mainForm.cs 410 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Diagnostics.Eventing.Reader;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Ports;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.InteropServices;
  12. using System.Runtime.InteropServices.ComTypes;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading;
  16. using System.Web;
  17. using System.Windows.Forms;
  18. using System.Xml.Linq;
  19. namespace Welling_Motor_Debug_Tool
  20. {
  21. public partial class mainForm : Form
  22. {
  23. #region 变量定义
  24. //版本号
  25. public static string Version = "2.2.0";
  26. //串口实例
  27. Serial_Process mySerialProcess = new Serial_Process();
  28. string PortNumSave = "";
  29. string PortBaudrateSave = "";
  30. //本地信息定义
  31. LocalInfo localInfo = new LocalInfo();
  32. //FTP实例
  33. ftp myFtp = new ftp();
  34. //MC运行信息超时计数
  35. bool MC_RunInfo_Refresh = false;
  36. ushort MC_RunInfo_Refresh_Cnt = 0;
  37. //MC调试信息超时计数
  38. bool MC_DebugInfo_Refresh = false;
  39. ushort MC_DebugInfo_Refresh_Cnt = 0;
  40. //MC故障码超时计数
  41. bool MC_ErrorCode_Refresh = false;
  42. ushort MC_ErrorCode_Refresh_Cnt = 0;
  43. //配置参数实例
  44. Params myParams = new Params();
  45. //记录文件名称
  46. string RunInfoSaveFilename = "";
  47. //BMS运行信息超时计数
  48. bool BMS_RunInfo_Refresh = false;
  49. ushort BMS_RunInfo_Refresh_Cnt = 0;
  50. //生产模式关机指令反馈状态
  51. bool PowerOffAckStatus = false;
  52. //登录窗口
  53. public static Login EnterForm1 = new Login();
  54. //生产配置文件信息
  55. ArrayList array_CfgInfo = new ArrayList();
  56. //写入参数返回标志和计数
  57. public bool WriteACK = false;
  58. public ushort WriteCnt = 0;
  59. public ushort ACK_WaitCnt = 0;
  60. //写入参数返回提示标志
  61. public bool ACK_DisFlag = true;
  62. //Boot版本信息
  63. public string BootInfo = "";
  64. //接收指令临时缓存,转string
  65. public string CmdRevStrTemp = "";
  66. //计时器,用于统计运行时间
  67. public Stopwatch stopwatch = new Stopwatch();
  68. //力矩传感器检验参数窗口
  69. public static TorqueParams TorqueParamsForm = new TorqueParams();
  70. //参数生成窗口
  71. public static GenerateParams GenerateParamsForm = new GenerateParams();
  72. //版本信息窗口
  73. public static Version VersionForm = new Version();
  74. //本机硬件信息
  75. public string Local_HdInformation = "";
  76. #endregion
  77. #region 故障日志结构体定义
  78. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  79. [StructLayout(LayoutKind.Sequential)]
  80. public struct MC_ErrorLogSaveInfo_Struct_t
  81. {
  82. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  83. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  84. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  85. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  86. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  87. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  88. //电机运行信息,占用空间32bytes
  89. [StructLayout(LayoutKind.Sequential)]
  90. public struct MC_RunInfo_Struct_t
  91. {
  92. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  93. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  94. public ushort Power; //电功率 1W,地址偏移4
  95. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  96. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  97. public byte Cadence; //踏频 1rpm,地址偏移10
  98. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  99. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  100. public byte GearSt; //助力档位,地址偏移13
  101. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  102. public byte SOC; //剩余电量 1%,地址偏移15
  103. public ushort RemainDistance; //续航里程 1km,地址偏移16
  104. public ushort Torque_AD; //力矩寄存器,地址偏移18
  105. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  106. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  107. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  108. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  109. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  110. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  111. public UInt32 RS; //预留 4bytes
  112. };
  113. [MarshalAs(UnmanagedType.Struct)]
  114. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  115. //控制变量
  116. public Int16 IqCurrent; //Pu, 地址偏移 48
  117. public Int16 IqVoltage; //Pu, 地址偏移 50
  118. public Int16 IdCurrent; //Pu, 地址偏移 52
  119. public Int16 IdVoltage; //Pu, 地址偏移 54
  120. //状态机
  121. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  122. //预留
  123. public UInt16 RS1;
  124. public UInt16 RS2;
  125. public UInt16 RS3;
  126. };
  127. #endregion
  128. #region 屏幕缩放比例获取
  129. public class PrimaryScreen
  130. {
  131. #region Win32 API
  132. [DllImport("user32.dll")]
  133. static extern IntPtr GetDC(IntPtr ptr);
  134. [DllImport("gdi32.dll")]
  135. static extern int GetDeviceCaps(
  136. IntPtr hdc, // handle to DC
  137. int nIndex // index of capability
  138. );
  139. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  140. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  141. #endregion
  142. #region DeviceCaps常量
  143. const int HORZRES = 8;
  144. const int VERTRES = 10;
  145. const int LOGPIXELSX = 88;
  146. const int LOGPIXELSY = 90;
  147. const int DESKTOPVERTRES = 117;
  148. const int DESKTOPHORZRES = 118;
  149. #endregion
  150. #region 属性
  151. /// <summary>
  152. /// 获取屏幕分辨率当前物理大小
  153. /// </summary>
  154. public static Size WorkingArea
  155. {
  156. get
  157. {
  158. IntPtr hdc = GetDC(IntPtr.Zero);
  159. Size size = new Size();
  160. size.Width = GetDeviceCaps(hdc, HORZRES);
  161. size.Height = GetDeviceCaps(hdc, VERTRES);
  162. ReleaseDC(IntPtr.Zero, hdc);
  163. return size;
  164. }
  165. }
  166. /// <summary>
  167. /// 当前系统DPI_X 大小 一般为96
  168. /// </summary>
  169. public static int DpiX
  170. {
  171. get
  172. {
  173. IntPtr hdc = GetDC(IntPtr.Zero);
  174. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  175. ReleaseDC(IntPtr.Zero, hdc);
  176. return DpiX;
  177. }
  178. }
  179. /// <summary>
  180. /// 当前系统DPI_Y 大小 一般为96
  181. /// </summary>
  182. public static int DpiY
  183. {
  184. get
  185. {
  186. IntPtr hdc = GetDC(IntPtr.Zero);
  187. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  188. ReleaseDC(IntPtr.Zero, hdc);
  189. return DpiX;
  190. }
  191. }
  192. /// <summary>
  193. /// 获取真实设置的桌面分辨率大小
  194. /// </summary>
  195. public static Size DESKTOP
  196. {
  197. get
  198. {
  199. IntPtr hdc = GetDC(IntPtr.Zero);
  200. Size size = new Size();
  201. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  202. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  203. ReleaseDC(IntPtr.Zero, hdc);
  204. return size;
  205. }
  206. }
  207. /// <summary>
  208. /// 获取宽度缩放百分比
  209. /// </summary>
  210. public static float ScaleX
  211. {
  212. get
  213. {
  214. IntPtr hdc = GetDC(IntPtr.Zero);
  215. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  216. int d = GetDeviceCaps(hdc, HORZRES);
  217. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  218. ReleaseDC(IntPtr.Zero, hdc);
  219. return ScaleX;
  220. }
  221. }
  222. /// <summary>
  223. /// 获取高度缩放百分比
  224. /// </summary>
  225. public static float ScaleY
  226. {
  227. get
  228. {
  229. IntPtr hdc = GetDC(IntPtr.Zero);
  230. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  231. ReleaseDC(IntPtr.Zero, hdc);
  232. return ScaleY;
  233. }
  234. }
  235. #endregion
  236. }
  237. #endregion
  238. public mainForm()
  239. {
  240. InitializeComponent();
  241. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  242. stopwatch.Start();
  243. //端口初始化
  244. mySerialProcess.Init();
  245. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  246. //检查备忘录文件
  247. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  248. {
  249. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  250. }
  251. //检验流水号记录文件
  252. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  253. {
  254. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  255. }
  256. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  257. {
  258. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  259. }
  260. //检查文件夹
  261. if (!Directory.Exists(localInfo.LocalPath))
  262. {
  263. Directory.CreateDirectory(localInfo.LocalPath);
  264. }
  265. if (!Directory.Exists(localInfo.LocalDataPath))
  266. {
  267. Directory.CreateDirectory(localInfo.LocalDataPath);
  268. }
  269. if (!Directory.Exists(localInfo.ToolsPath))
  270. {
  271. Directory.CreateDirectory(localInfo.ToolsPath);
  272. }
  273. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  274. {
  275. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  276. }
  277. //检查配置文件
  278. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  279. {
  280. //打开文件
  281. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  282. string sLine = "";
  283. ArrayList array_CfgInfo = new ArrayList();
  284. array_CfgInfo.Clear();
  285. while (sLine != null)
  286. {
  287. sLine = objReader.ReadLine();
  288. array_CfgInfo.Add(sLine);
  289. }
  290. objReader.Close();
  291. //解析配置文件
  292. try
  293. {
  294. //Port Set
  295. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  296. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  297. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  298. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  299. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  300. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  301. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  302. //Option
  303. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  304. 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
  305. 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
  306. if (array_CfgInfo[9].ToString().Split(':')[1] == "False")
  307. {
  308. checkBox_OffLineFacMode.Checked = false;
  309. checkBox_OffLineFacMode.Enabled = false;
  310. checkBox_OffLineCheckMode.Checked = false;
  311. checkBox_OffLineCheckMode.Enabled = false;
  312. }
  313. else
  314. {
  315. checkBox_OffLineFacMode.Checked = true;
  316. checkBox_OffLineFacMode.Enabled = true;
  317. checkBox_OffLineCheckMode.Checked = true;
  318. checkBox_OffLineCheckMode.Enabled = true;
  319. }
  320. //Server Set
  321. toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
  322. toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
  323. toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
  324. toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
  325. toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
  326. //MacInfo
  327. toolStripTextBox_MAC.Text = array_CfgInfo[19].ToString().Split(':')[1];
  328. toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
  329. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  330. toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
  331. //Log Address
  332. textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
  333. textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
  334. //电机类型
  335. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[29].ToString().Split(':')[1] == "True");
  336. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  337. //检测阈值
  338. toolStripTextBox_ThVol.Text = array_CfgInfo[33].ToString().Split(':')[1];
  339. toolStripTextBox_ThCur.Text = array_CfgInfo[34].ToString().Split(':')[1];
  340. toolStripTextBox_ThSpeed.Text = array_CfgInfo[35].ToString().Split(':')[1];
  341. toolStripTextBox_ThTor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  342. toolStripTextBox_ThCad.Text = array_CfgInfo[37].ToString().Split(':')[1];
  343. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[38].ToString().Split(':')[1];
  344. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[39].ToString().Split(':')[1];
  345. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[40].ToString().Split(':')[1];
  346. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[41].ToString().Split(':')[1];
  347. //MOS内阻校准系数
  348. toolStripTextBox_MosCalK.Text = array_CfgInfo[44].ToString().Split(':')[1];
  349. toolStripTextBox_MOS1.Text= array_CfgInfo[45].ToString().Split(':')[1];
  350. toolStripTextBox_MOS2.Text = array_CfgInfo[46].ToString().Split(':')[1];
  351. toolStripTextBox_MOS3.Text = array_CfgInfo[47].ToString().Split(':')[1];
  352. //通信协议类型
  353. cANToolStripMenuItem.Checked = (array_CfgInfo[50].ToString().Split(':')[1] == "True");
  354. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  355. }
  356. catch (System.Exception)
  357. {
  358. timer_1s.Enabled = false;
  359. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  360. timer_1s.Enabled = true;
  361. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  362. }
  363. }
  364. else //不存在配置文件,生成文件写入默认值
  365. {
  366. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  367. }
  368. //解析本地流水号记录
  369. do
  370. {
  371. //测试模式
  372. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  373. //检验模式
  374. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  375. } while (false);
  376. //获取本机信息,读取时间较长,优先从本地文件获取
  377. do
  378. {
  379. try
  380. {
  381. //本地文件为空,读取信息保存
  382. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  383. {
  384. Local_HdInformation = "";
  385. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  386. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  387. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  388. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  389. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  390. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  391. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  392. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  393. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  394. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  395. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  396. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  397. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  398. }
  399. //从本地读取,计算机名和IP地址重新读
  400. else
  401. {
  402. Local_HdInformation = "";
  403. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  404. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  405. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  406. for (int i = 0; i < fileInfo.Length; i++)
  407. Local_HdInformation += fileInfo[i] + "\r\n";
  408. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  409. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  410. }
  411. }
  412. catch(Exception)
  413. {
  414. }
  415. } while (false);
  416. //系统登录
  417. do
  418. {
  419. EnterForm1.ShowDialog();
  420. try
  421. {
  422. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  423. {
  424. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  425. {
  426. //隐藏设置项
  427. 其它配置项ToolStripMenuItem.Visible = false;
  428. 写入存储ToolStripMenuItem.Visible = false;
  429. 离线使用ToolStripMenuItem.Visible = false;
  430. 服务器配置ToolStripMenuItem.Visible = false;
  431. 判断阈值ToolStripMenuItem.Visible = false;
  432. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  433. mOS内阻范围ToolStripMenuItem.Visible = false;
  434. 力矩传感器检验ToolStripMenuItem.Visible = false;
  435. //显示生产信息
  436. 生产信息ToolStripMenuItem.Visible = true;
  437. //显示电机类型,但不可编辑
  438. 电机类型ToolStripMenuItem.Visible = true;
  439. 中置电机ToolStripMenuItem.Enabled = false;
  440. 轮毂电机ToolStripMenuItem.Enabled = false;
  441. if (uARTToolStripMenuItem.Checked)
  442. UART协议ToolStripMenuItem.Visible = true;
  443. //隐藏研发调试界面
  444. tabPage_MotorParam.Parent = null;
  445. tabPage_BikeParam.Parent = null;
  446. tabPage_BikeParam2.Parent = null;
  447. tabPage_ControlParam.Parent = null;
  448. tabPage_SensorParam.Parent = null;
  449. tabPage_AssistParam.Parent = null;
  450. tabPage_UsrRideParam.Parent = null;
  451. tabPage_DebugParam.Parent = null;
  452. tabPage_RecordInfo.Parent = null;
  453. tabPage_OtherInfo.Parent = null;
  454. tabPage_OBC.Parent = null;
  455. tabPage_RAMorFLASH.Parent = null;
  456. tabPage_FactoryMode.Parent = null;
  457. tabPage_DebugInfo.Parent = null;
  458. //显示运行信息
  459. tabPage_RunInfo.Parent = tabControl2;
  460. //根据电机类型修改生产信息和电机类型
  461. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  462. {
  463. 中置电机ToolStripMenuItem.Checked = true;
  464. 轮毂电机ToolStripMenuItem.Checked = false;
  465. toolStripTextBox_MACPD.Text = "MM_MC1";
  466. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  467. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  468. }
  469. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  470. {
  471. 中置电机ToolStripMenuItem.Checked = false;
  472. 轮毂电机ToolStripMenuItem.Checked = true;
  473. toolStripTextBox_MACPD.Text = "GF_250_1";
  474. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  475. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  476. }
  477. //显示对应生产测试界面
  478. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  479. {
  480. tabPage_ProductMode_Write.Parent = tabControl1;
  481. tabPage_ProductMode_Write.Select();
  482. tabPage_ProductMode_Read.Parent = null;
  483. }
  484. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  485. {
  486. tabPage_ProductMode_Read.Parent = tabControl1;
  487. tabPage_ProductMode_Read.Select();
  488. tabPage_ProductMode_Write.Parent = null;
  489. }
  490. //应答指令不提示
  491. ACK_DisFlag = false;
  492. //退出登录
  493. break;
  494. }
  495. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  496. {
  497. //隐藏工作台内容,新建窗口完成配置
  498. groupBox1.Visible = false;
  499. groupBox3.Visible = false;
  500. tabControl2.Visible = false;
  501. //隐藏提示信息
  502. label_StarInfo.Visible = false;
  503. //打开参数配置框
  504. GenerateParamsForm.ShowDialog();
  505. System.Environment.Exit(0);
  506. //退出登录
  507. break;
  508. }
  509. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  510. {
  511. //隐藏量产界面
  512. tabPage_ProductMode_Read.Parent = null;
  513. tabPage_ProductMode_Write.Parent = null;
  514. //隐藏配置项
  515. 其它配置项ToolStripMenuItem.Visible = false;
  516. 离线使用ToolStripMenuItem.Visible = false;
  517. 服务器配置ToolStripMenuItem.Visible = false;
  518. 判断阈值ToolStripMenuItem.Visible = false;
  519. 力矩传感器检验ToolStripMenuItem.Visible = false;
  520. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  521. mOS内阻范围ToolStripMenuItem.Visible = false;
  522. //显示生产信息
  523. 生产信息ToolStripMenuItem.Visible = true;
  524. //显示电机类型,但不可编辑
  525. 电机类型ToolStripMenuItem.Visible = true;
  526. 中置电机ToolStripMenuItem.Enabled = true;
  527. 轮毂电机ToolStripMenuItem.Enabled = true;
  528. if (uARTToolStripMenuItem.Checked)
  529. UART协议ToolStripMenuItem.Visible = true;
  530. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  531. {
  532. 中置电机ToolStripMenuItem.Checked = true;
  533. 轮毂电机ToolStripMenuItem.Checked = false;
  534. toolStripTextBox_MACPD.Text = "MM_MC1";
  535. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  536. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  537. }
  538. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  539. {
  540. 中置电机ToolStripMenuItem.Checked = false;
  541. 轮毂电机ToolStripMenuItem.Checked = true;
  542. toolStripTextBox_MACPD.Text = "GF_250_1";
  543. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  544. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  545. }
  546. //退出登录
  547. break;
  548. }
  549. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  550. {
  551. //隐藏设置项
  552. 其它配置项ToolStripMenuItem.Visible = false;
  553. 写入存储ToolStripMenuItem.Visible = false;
  554. 离线使用ToolStripMenuItem.Visible = false;
  555. 服务器配置ToolStripMenuItem.Visible = false;
  556. 判断阈值ToolStripMenuItem.Visible = false;
  557. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  558. mOS内阻范围ToolStripMenuItem.Visible = false;
  559. 力矩传感器检验ToolStripMenuItem.Visible = false;
  560. //显示生产信息
  561. 生产信息ToolStripMenuItem.Visible = true;
  562. //显示电机类型,但不可编辑
  563. 电机类型ToolStripMenuItem.Visible = false;
  564. 中置电机ToolStripMenuItem.Enabled = false;
  565. 轮毂电机ToolStripMenuItem.Enabled = false;
  566. if (uARTToolStripMenuItem.Checked)
  567. UART协议ToolStripMenuItem.Visible = true;
  568. //隐藏研发调试界面
  569. tabPage_MotorParam.Parent = null;
  570. tabPage_BikeParam.Parent = null;
  571. tabPage_BikeParam2.Parent = null;
  572. tabPage_ControlParam.Parent = null;
  573. tabPage_SensorParam.Parent = null;
  574. tabPage_AssistParam.Parent = null;
  575. tabPage_UsrRideParam.Parent = null;
  576. tabPage_DebugParam.Parent = null;
  577. tabPage_RecordInfo.Parent = null;
  578. tabPage_OtherInfo.Parent = null;
  579. tabPage_OBC.Parent = null;
  580. tabPage_RAMorFLASH.Parent = null;
  581. tabPage_FactoryMode.Parent = null;
  582. tabPage_DebugInfo.Parent = null;
  583. //显示运行信息
  584. tabPage_RunInfo.Parent = tabControl2;
  585. //目前仅轮毂使用
  586. 中置电机ToolStripMenuItem.Checked = false;
  587. 轮毂电机ToolStripMenuItem.Checked = true;
  588. toolStripTextBox_MACPD.Text = "GF_250_1";
  589. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  590. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  591. //显示量产测试界面
  592. tabPage_ProductMode_Write.Parent = tabControl1;
  593. tabPage_ProductMode_Write.Select();
  594. tabPage_ProductMode_Read.Parent = null;
  595. //允许离线使用
  596. 允许ToolStripMenuItem.Checked = false;
  597. 不允许ToolStripMenuItem.Checked = true;
  598. checkBox_OffLineFacMode.Checked = false;
  599. checkBox_OffLineFacMode.Enabled = true;
  600. checkBox_OffLineCheckMode.Checked = false;
  601. checkBox_OffLineCheckMode.Enabled = true;
  602. //应答指令不提示
  603. ACK_DisFlag = false;
  604. //退出登录
  605. break;
  606. }
  607. else if (EnterForm1.comboBox_User.Text == "研发调试")
  608. {
  609. //隐藏量产界面
  610. tabPage_ProductMode_Read.Parent = null;
  611. tabPage_ProductMode_Write.Parent = null;
  612. 服务器配置ToolStripMenuItem.Visible = false;
  613. if (uARTToolStripMenuItem.Checked)
  614. UART协议ToolStripMenuItem.Visible = true;
  615. //退出登录
  616. break;
  617. }
  618. else if (EnterForm1.comboBox_User.Text == "管理员")
  619. {
  620. //不隐藏任何界面
  621. //...
  622. //退出登录
  623. break;
  624. }
  625. else
  626. {
  627. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  628. //重新登录
  629. continue;
  630. }
  631. }
  632. else
  633. {
  634. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  635. //重新登录
  636. continue;
  637. }
  638. }
  639. catch (Exception)
  640. {
  641. System.Environment.Exit(0);
  642. }
  643. } while (true);
  644. //配置网络FTP服务器
  645. myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text, "admin", "ttium_admin");
  646. //创建线程,定时检测网络连接状态
  647. Thread th = new Thread(NetworkCheck);
  648. th.IsBackground = true;
  649. th.Start();
  650. }
  651. /// <summary>
  652. /// 检查网络状态线程
  653. /// </summary>
  654. private void NetworkCheck()
  655. {
  656. //允许离线使用,直接退出
  657. if (允许ToolStripMenuItem.Checked == true) //允许离线使用
  658. {
  659. timer_1s.Enabled = false;
  660. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  661. timer_1s.Enabled = true;
  662. return;
  663. }
  664. //不允许离线使用,实时监测网络状态
  665. else
  666. {
  667. //初始化第一次连接FTP服务器
  668. bool Result = myFtp.CheckFtp();
  669. if (Result == true)//服务器连接成功
  670. {
  671. myFtp.IsNetConnected = true;
  672. //上传登录日志
  673. do
  674. {
  675. //日志文件名
  676. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  677. string fileName = date;
  678. //日志内容
  679. string fileInfo = Local_HdInformation;
  680. //保存本地
  681. if (!Directory.Exists(localInfo.LocalLogPath))
  682. Directory.CreateDirectory(localInfo.LocalLogPath);
  683. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  684. //上传服务器
  685. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  686. } while (false);
  687. }
  688. else//服务器连接失败
  689. {
  690. myFtp.IsNetConnected = false;
  691. if (EnterForm1.comboBox_User.Text != "管理员")
  692. {
  693. timer_1s.Enabled = false;
  694. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  695. timer_1s.Enabled = true;
  696. this.Close();
  697. }
  698. }
  699. //创建定时器,定时10s检查网络
  700. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  701. timer_CheckNet.Enabled = true;
  702. timer_CheckNet.Interval = 30000;
  703. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  704. timer_CheckNet.Start();
  705. while (true)
  706. {
  707. Thread.Sleep(1);
  708. if (myFtp.IsNetConnected == false)
  709. {
  710. label_Server_ComStatus.Text = "网络已断开";
  711. label_ServerStatus.BackColor = Color.Red;
  712. }
  713. else
  714. {
  715. label_Server_ComStatus.Text = "网络已连接";
  716. label_ServerStatus.BackColor = Color.Green;
  717. }
  718. }
  719. }
  720. }
  721. /// <summary>
  722. /// 线程中定时任务,检查网络状态
  723. /// </summary>
  724. /// <param name="sender"></param>
  725. /// <param name="e"></param>
  726. private void timer_CheckNet_Tick(object sender, EventArgs e)
  727. {
  728. //连接FTP服务器
  729. bool Result = myFtp.CheckFtp();
  730. if (Result == true)//服务器连接成功
  731. {
  732. myFtp.IsNetConnected = true;
  733. //允许使用
  734. groupBox1.Enabled = true;
  735. groupBox3.Enabled = true;
  736. tabControl2.Enabled = true;
  737. }
  738. else//服务器连接失败
  739. {
  740. myFtp.IsNetConnected = false;
  741. if (EnterForm1.comboBox_User.Text != "管理员")
  742. {
  743. timer_1s.Enabled = false;
  744. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  745. timer_1s.Enabled = true;
  746. //禁止使用
  747. groupBox1.Enabled = false;
  748. groupBox3.Enabled = false;
  749. tabControl2.Enabled = false;
  750. }
  751. }
  752. }
  753. #region 非独占性延时函数
  754. public static void Delay_ms(int milliSecond)
  755. {
  756. int start = Environment.TickCount;
  757. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  758. {
  759. Application.DoEvents();
  760. }
  761. }
  762. #endregion
  763. private void MainForm_Load(object sender, System.EventArgs e)
  764. {
  765. //页面初始化
  766. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  767. label_Computername.Text = System.Environment.UserName;
  768. label_UserName.Text = EnterForm1.comboBox_User.Text;
  769. this.Text += Version;
  770. //检查版本,自动更新
  771. do
  772. {
  773. //检查网络状态
  774. if (myFtp.CheckFtp() == false)
  775. {
  776. break; ;
  777. }
  778. else
  779. {
  780. //检查本地文件删除
  781. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  782. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  783. //读取最新版本号
  784. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  785. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  786. string sLine = "";
  787. ArrayList arrText = new ArrayList();//创建一个动态数组
  788. while (sLine != null)
  789. {
  790. sLine = objReader.ReadLine();
  791. arrText.Add(sLine);
  792. }
  793. objReader.Close();
  794. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  795. //检查是否有最新版本
  796. string[] VerOld = mainForm.Version.Trim().Split('.');
  797. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  798. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  799. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  800. if (VerNew_int <= VerOld_int)
  801. {
  802. //版本已是最新,跳出
  803. break;
  804. }
  805. //确认下载最新版本
  806. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  807. {
  808. string SavePath = Directory.GetCurrentDirectory();
  809. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  810. foreach (string file in FileList)
  811. {
  812. if (file.Contains(".exe"))
  813. {
  814. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  815. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  816. System.Environment.Exit(0);
  817. }
  818. }
  819. }
  820. }
  821. } while (false);
  822. //下拉控件初始值设定
  823. comboBox_WorkMode.SelectedIndex = 0;
  824. comboBox_GearSt.SelectedIndex = 0;
  825. comboBox_LightSwitch.SelectedIndex = 1;
  826. comboBox_OBC_SetGearST.SelectedIndex = 0;
  827. comboBox_OBC_LightSw.SelectedIndex = 1;
  828. comboBox_AssistTorque.SelectedIndex = 0;
  829. comboBox_AssistCadence.SelectedIndex = 0;
  830. //combobox事件定义
  831. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  832. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  833. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  834. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  835. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  836. //端口自动连接
  837. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  838. {
  839. try
  840. {
  841. PortConnect();
  842. }
  843. catch (System.Exception)
  844. {
  845. timer_1s.Enabled = false;
  846. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  847. timer_1s.Enabled = true;
  848. }
  849. }
  850. //不识别联动装置盒自动打开界面
  851. #if true
  852. groupBox1.Visible = true;
  853. groupBox3.Visible = true;
  854. tabControl2.Visible = true;
  855. label_StarInfo.Visible = false;
  856. #endif
  857. //创建线程,定时解析数据
  858. Thread th = new Thread(Task_SerialProcess);
  859. th.IsBackground = true;
  860. th.Start();
  861. }
  862. #region 结构体与字节流相互转换
  863. public static class MyConverter
  864. {
  865. /// <summary>
  866. /// 由结构体转换为byte数组
  867. /// </summary>
  868. public static byte[] StructureToByte<T>(T structure)
  869. {
  870. int size = Marshal.SizeOf(typeof(T));
  871. byte[] buffer = new byte[size];
  872. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  873. try
  874. {
  875. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  876. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  877. }
  878. finally
  879. {
  880. Marshal.FreeHGlobal(bufferIntPtr);
  881. }
  882. return buffer;
  883. }
  884. /// <summary>
  885. /// 由byte数组转换为结构体
  886. /// </summary>
  887. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  888. {
  889. object structure = null;
  890. int size = Marshal.SizeOf(typeof(T));
  891. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  892. try
  893. {
  894. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  895. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  896. }
  897. finally
  898. {
  899. Marshal.FreeHGlobal(allocIntPtr);
  900. }
  901. return (T)structure;
  902. }
  903. }
  904. #endregion
  905. #region 故障日志解析显示
  906. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  907. {
  908. string SaveData = "";
  909. //Log1
  910. if (Log1.Error_Index != 0xFFFF)
  911. {
  912. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  913. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  914. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  915. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  916. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  917. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  918. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  919. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  920. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  921. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  922. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  923. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  924. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  925. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  926. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  927. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  928. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  929. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  930. {
  931. SaveData += "续航:" + "---km" + ", ";
  932. }
  933. else
  934. {
  935. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  936. }
  937. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  938. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  939. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  940. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  941. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  942. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  943. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  944. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  945. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  946. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  947. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  948. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  949. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  950. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  951. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  952. SaveData += "\r\n\r\n";
  953. richTextBox_Record.AppendText(SaveData);
  954. SaveData = "";
  955. }
  956. //Log2
  957. if (Log2.Error_Index != 0xFFFF)
  958. {
  959. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  960. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  961. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  962. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  963. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  964. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  965. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  966. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  967. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  968. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  969. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  970. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  971. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  972. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  973. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  974. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  975. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  976. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  977. {
  978. SaveData += "续航:" + "---km" + ", ";
  979. }
  980. else
  981. {
  982. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  983. }
  984. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  985. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  986. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  987. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  988. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  989. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  990. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  991. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  992. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  993. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  994. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  995. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  996. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  997. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  998. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  999. SaveData += "\r\n\r\n";
  1000. richTextBox_Record.AppendText(SaveData);
  1001. SaveData = "";
  1002. }
  1003. }
  1004. #endregion
  1005. #region 串口数据解析线程
  1006. /// <summary>
  1007. /// 串口数据解析线程
  1008. /// </summary>
  1009. private void Task_SerialProcess()
  1010. {
  1011. //创建定时器,定时读取串口数据
  1012. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1013. timer_ReadSerial.Enabled = true;
  1014. timer_ReadSerial.Interval = 20;
  1015. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1016. timer_ReadSerial.Start();
  1017. while (true)
  1018. {
  1019. Thread.Sleep(1);
  1020. };
  1021. }
  1022. /// <summary>
  1023. /// 串口解析定时器
  1024. /// </summary>
  1025. /// <param name="sender"></param>
  1026. /// <param name="e"></param>
  1027. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1028. {
  1029. //串口解析
  1030. Serial_process(mySerialProcess.buffer);
  1031. }
  1032. #endregion
  1033. #region 数据解析
  1034. public void Serial_process(List<byte> buffer)
  1035. {
  1036. byte DataNum = 0; //记录每条命令数据段的长度
  1037. ushort PackageID, Cmd;
  1038. byte[] Data = new byte[1024];
  1039. try
  1040. {
  1041. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1042. {
  1043. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1044. {
  1045. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1046. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1047. {
  1048. int CmdLen = buffer[5];
  1049. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1050. while (CmdLen > 0) //读取命令段
  1051. {
  1052. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1053. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1054. if (DataNum <= (CmdLen - 2))
  1055. {
  1056. for (int i = 0; i < DataNum; i++)
  1057. {
  1058. Data[i] = buffer[i + 8];
  1059. }
  1060. buffer.RemoveRange(0, CmdLen + 11);
  1061. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1062. DataRevToString(Cmd, Data);//指令数据转为字符串
  1063. }
  1064. }
  1065. }
  1066. else
  1067. {
  1068. buffer.RemoveAt(0);//ID不对
  1069. }
  1070. }
  1071. else
  1072. {
  1073. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1074. }
  1075. }
  1076. }
  1077. catch (Exception)
  1078. {
  1079. }
  1080. }
  1081. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1082. {
  1083. int DataTemp;
  1084. ushort uData16;
  1085. unchecked
  1086. {
  1087. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1088. }
  1089. #region 解析发送给CDL的指令
  1090. if (ID == 0x7FF)
  1091. {
  1092. switch (CmdTemp)
  1093. {
  1094. case 0x1100://
  1095. {
  1096. unchecked
  1097. {
  1098. this.Invoke((EventHandler)(delegate
  1099. {
  1100. //CDL连接成功
  1101. mySerialProcess.CDL_Online_Flag = true;
  1102. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1103. groupBox1.Visible = true;
  1104. groupBox3.Visible = true;
  1105. tabControl2.Visible = true;
  1106. label_StarInfo.Visible = false;
  1107. }));
  1108. }
  1109. break;
  1110. }
  1111. default: break;
  1112. }
  1113. }
  1114. #endregion
  1115. #region 解析电机的命令
  1116. else if ((ID == 0x715) || (ID == 0x710))
  1117. {
  1118. switch (CmdTemp)
  1119. {
  1120. case 0x1020://电机运行信息
  1121. {
  1122. unchecked
  1123. {
  1124. this.Invoke((EventHandler)(delegate
  1125. {
  1126. MC_RunInfo_Refresh = true;
  1127. //车速
  1128. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1129. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1130. //输出转速
  1131. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1132. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1133. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1134. Class_MotorSpeed.Data = DataTemp;
  1135. //电功率
  1136. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1137. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1138. //母线电压
  1139. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1140. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1141. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1142. //母线电流
  1143. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1144. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1145. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1146. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1147. Class_CurrentData.Data = DataTemp;
  1148. //踏频
  1149. DataTemp = (ushort)(Data[10]);
  1150. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1151. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1152. Class_CadenceData.Data = DataTemp;
  1153. //踩踏力矩
  1154. DataTemp = (ushort)(Data[11]);
  1155. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1156. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1157. Class_TorqueData.Data = DataTemp;
  1158. //踩踏方向
  1159. DataTemp = (ushort)(Data[12]);
  1160. if (DataTemp == 0)
  1161. {
  1162. textBox_RunInfo_Dir.Text = "正向";
  1163. }
  1164. else if (DataTemp == 1)
  1165. {
  1166. textBox_RunInfo_Dir.Text = "反向";
  1167. }
  1168. else if (DataTemp == 2)
  1169. {
  1170. textBox_RunInfo_Dir.Text = "停止";
  1171. }
  1172. //助力档位
  1173. DataTemp = (ushort)(Data[13]);
  1174. if (DataTemp == 0x33)
  1175. {
  1176. textBox_RunInfo_GearSt.Text = "SMART";
  1177. //comboBox_GearSt.SelectedIndex = 5;
  1178. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1179. }
  1180. else if (DataTemp == 0x22)
  1181. {
  1182. textBox_RunInfo_GearSt.Text = "WALK";
  1183. //comboBox_GearSt.SelectedIndex = 6;
  1184. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1185. }
  1186. else
  1187. {
  1188. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1189. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1190. //comboBox_GearSt.SelectedIndex = DataTemp;
  1191. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1192. }
  1193. //大灯状态
  1194. DataTemp = (ushort)(Data[14]);
  1195. if (DataTemp == 0xF0)
  1196. {
  1197. textBox_RunInfo_LightSwitch.Text = "OFF";
  1198. //comboBox_LightSwitch.SelectedIndex = 1;
  1199. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1200. }
  1201. else if (DataTemp == 0xF1)
  1202. {
  1203. textBox_RunInfo_LightSwitch.Text = "ON";
  1204. //comboBox_LightSwitch.SelectedIndex = 0;
  1205. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1206. }
  1207. //剩余电量
  1208. DataTemp = (ushort)(Data[15]);
  1209. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1210. //剩余续航里程
  1211. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1212. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1213. {
  1214. textBox_RunInfo_Range.Text = "---";
  1215. }
  1216. else
  1217. {
  1218. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1219. }
  1220. //预留(显示力矩Reg),空2bytes
  1221. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1222. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1223. //平均功耗
  1224. DataTemp = (ushort)(Data[20]);
  1225. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1226. //PCB温度
  1227. DataTemp = (ushort)(Data[21]);
  1228. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1229. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1230. Class_MotorTemp.Data = DataTemp - 40;
  1231. //绕组温度
  1232. DataTemp = (ushort)(Data[22]);
  1233. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1234. //MCU温度
  1235. DataTemp = (ushort)(Data[23]);
  1236. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1237. //单次里程
  1238. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1239. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1240. //单次时间
  1241. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1242. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1243. //数据保存
  1244. RunInfoAutoSave();
  1245. }));
  1246. }
  1247. break;
  1248. }
  1249. case 0x1104://故障码
  1250. {
  1251. unchecked
  1252. {
  1253. this.Invoke((EventHandler)(delegate
  1254. {
  1255. MC_ErrorCode_Refresh = true;
  1256. textBox_ErrorCode.Text =
  1257. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1258. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1259. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1260. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1261. "H";
  1262. }));
  1263. }
  1264. break;
  1265. }
  1266. case 0xA903://反馈指令
  1267. {
  1268. unchecked
  1269. {
  1270. this.Invoke((EventHandler)(delegate
  1271. {
  1272. if (ACK_DisFlag == true)
  1273. {
  1274. timer_1s.Enabled = false;
  1275. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1276. timer_1s.Enabled = true;
  1277. //关机反馈
  1278. PowerOffAckStatus = true;
  1279. }
  1280. //应答标志置位
  1281. WriteACK = true;
  1282. WriteCnt++;
  1283. }));
  1284. }
  1285. break;
  1286. }
  1287. case 0xB226://马达参数
  1288. {
  1289. unchecked
  1290. {
  1291. this.Invoke((EventHandler)(delegate
  1292. {
  1293. richTextBox_MotorParam.Clear();
  1294. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1295. {
  1296. if (i == 6)
  1297. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1298. else
  1299. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1300. }
  1301. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1302. }));
  1303. }
  1304. break;
  1305. }
  1306. case 0xB31A://整车信息
  1307. {
  1308. unchecked
  1309. {
  1310. this.Invoke((EventHandler)(delegate
  1311. {
  1312. richTextBox_BikeParam.Clear();
  1313. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1314. {
  1315. if (i == 9)
  1316. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1317. else
  1318. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1319. //更新前后灯参数
  1320. if (i == 8)
  1321. {
  1322. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1323. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1324. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1325. }
  1326. //更新开关机参数
  1327. else if (i == 11)
  1328. {
  1329. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1330. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1331. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1332. }
  1333. }
  1334. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1335. }));
  1336. }
  1337. break;
  1338. }
  1339. case 0xB420://控制器参数
  1340. {
  1341. unchecked
  1342. {
  1343. this.Invoke((EventHandler)(delegate
  1344. {
  1345. richTextBox_ControlParam.Clear();
  1346. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1347. {
  1348. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1349. }
  1350. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1351. }));
  1352. }
  1353. break;
  1354. }
  1355. case 0xB528://传感器参数
  1356. {
  1357. unchecked
  1358. {
  1359. this.Invoke((EventHandler)(delegate
  1360. {
  1361. richTextBox_SensorParam.Clear();
  1362. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1363. {
  1364. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1365. }
  1366. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1367. //更新生产模式页面传感器零点和标定值
  1368. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1369. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1370. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1371. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1372. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1373. }));
  1374. }
  1375. break;
  1376. }
  1377. case 0xB64C://助力参数
  1378. {
  1379. unchecked
  1380. {
  1381. this.Invoke((EventHandler)(delegate
  1382. {
  1383. richTextBox_AssistParam.Clear();
  1384. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1385. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1386. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1387. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1388. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1389. {
  1390. if (i < index_1) //数据占用2bytes
  1391. {
  1392. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1393. }
  1394. else if (i <= index_2) //数据占用4bytes
  1395. {
  1396. 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])) + ", ");
  1397. }
  1398. else if (i < index_3) //数据占用2bytes,无符号
  1399. {
  1400. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1401. }
  1402. else if (i <= index_4) //数据占用2bytes,有符号
  1403. {
  1404. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1405. }
  1406. else //数据占用2bytes,无符号
  1407. {
  1408. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1409. }
  1410. }
  1411. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1412. }));
  1413. }
  1414. break;
  1415. }
  1416. case 0xB74C://历史记录
  1417. {
  1418. unchecked
  1419. {
  1420. this.Invoke((EventHandler)(delegate
  1421. {
  1422. richTextBox_Record.Clear();
  1423. for (int i = 0; i < myParams.Record.Count; i++)
  1424. {
  1425. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1426. }
  1427. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1428. }));
  1429. }
  1430. break;
  1431. }
  1432. case 0xB83A://调试参数
  1433. {
  1434. unchecked
  1435. {
  1436. this.Invoke((EventHandler)(delegate
  1437. {
  1438. richTextBox_DebugParam.Clear();
  1439. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1440. {
  1441. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1442. }
  1443. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1444. }));
  1445. }
  1446. break;
  1447. }
  1448. case 0xB904://存储标志
  1449. {
  1450. unchecked
  1451. {
  1452. this.Invoke((EventHandler)(delegate
  1453. {
  1454. ushort Flag = 0;
  1455. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1456. if (Flag == 0)
  1457. {
  1458. radioButton_EE_SaveNo.Checked = true;
  1459. radioButton_EE_SaveYes.Checked = false;
  1460. }
  1461. else
  1462. {
  1463. radioButton_EE_SaveNo.Checked = false;
  1464. radioButton_EE_SaveYes.Checked = true;
  1465. }
  1466. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1467. if (Flag == 0)
  1468. {
  1469. radioButton_SIP_SaveNo.Checked = true;
  1470. radioButton_SIP_SaveYes.Checked = false;
  1471. }
  1472. else
  1473. {
  1474. radioButton_SIP_SaveNo.Checked = false;
  1475. radioButton_SIP_SaveYes.Checked = true;
  1476. }
  1477. }));
  1478. }
  1479. break;
  1480. }
  1481. case 0x1240://电机版本信息
  1482. {
  1483. unchecked
  1484. {
  1485. this.Invoke((EventHandler)(delegate
  1486. {
  1487. //电机型号
  1488. textBox_Model.Text = "";
  1489. textBox_OBC_ReadModel.Text = "";
  1490. textBox_FacModeName.Text = "";
  1491. for (ushort i = 0; i < 16; i++)
  1492. {
  1493. if (Data[i] == 0x2E)
  1494. {
  1495. break;
  1496. }
  1497. textBox_Model.Text += ((char)Data[i]).ToString();
  1498. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1499. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1500. }
  1501. Class_Motor_Ver.Mode = textBox_Model.Text;
  1502. //电机SN
  1503. textBox_SN.Text = "";
  1504. textBox_OBC_ReadSN.Text = "";
  1505. textBox_FacModeNum.Text = "";
  1506. for (ushort i = 0; i < 16; i++)
  1507. {
  1508. if (Data[16 + i] == 0x2E)
  1509. {
  1510. break;
  1511. }
  1512. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1513. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1514. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1515. }
  1516. Class_Motor_Ver.SN = textBox_SN.Text;
  1517. //电机HW
  1518. textBox_HW.Text = "";
  1519. textBox_OBC_ReadHW.Text = "";
  1520. textBox_FacModeHW.Text = "";
  1521. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1522. {
  1523. if (Data[32 + i] == 0x2E)
  1524. {
  1525. break;
  1526. }
  1527. else if (Data[32 + i] == 'r')
  1528. {
  1529. Data[32 + i] = (byte)'.';
  1530. break;
  1531. }
  1532. string strTemp = "";
  1533. strTemp = ((char)Data[32 + i]).ToString();
  1534. textBox_HW.Text += strTemp;
  1535. textBox_OBC_ReadHW.Text += strTemp;
  1536. textBox_FacModeHW.Text += strTemp;
  1537. }
  1538. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1539. {
  1540. if (Data[40 + i] == 0x2E)
  1541. {
  1542. break;
  1543. }
  1544. else if (Data[40 + i] == 'r')
  1545. {
  1546. Data[40 + i] = (byte)'.';
  1547. break;
  1548. }
  1549. string strTemp = "";
  1550. strTemp = ((char)Data[40 + i]).ToString();
  1551. textBox_HW.Text += strTemp;
  1552. textBox_OBC_ReadHW.Text += strTemp;
  1553. textBox_FacModeHW.Text += strTemp;
  1554. }
  1555. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1556. {
  1557. string strTemp = "";
  1558. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1559. textBox_HW.Text += strTemp;
  1560. textBox_OBC_ReadHW.Text += strTemp;
  1561. textBox_FacModeHW.Text += strTemp;
  1562. }
  1563. Class_Motor_Ver.HW = textBox_HW.Text;
  1564. //电机FW
  1565. textBox_FW.Text = "";
  1566. textBox_OBC_ReadFW.Text = "";
  1567. textBox_FacModeFW.Text = "";
  1568. for (ushort i = 0; i < 16; i++)
  1569. {
  1570. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1571. {
  1572. break;
  1573. }
  1574. if (Data[48 + i] == 'r')
  1575. {
  1576. Data[48 + i] = (byte)'.';
  1577. }
  1578. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1579. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1580. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1581. }
  1582. Class_Motor_Ver.FW = textBox_FW.Text;
  1583. }));
  1584. }
  1585. break;
  1586. }
  1587. case 0xA610://自定义1
  1588. {
  1589. unchecked
  1590. {
  1591. this.Invoke((EventHandler)(delegate
  1592. {
  1593. textBox_User1.Text = "";
  1594. for (ushort i = 0; i < 16; i++)
  1595. {
  1596. if (Data[i] == 0x2E)
  1597. {
  1598. break;
  1599. }
  1600. textBox_User1.Text += ((char)Data[i]).ToString();
  1601. }
  1602. }));
  1603. }
  1604. break;
  1605. }
  1606. case 0xA710://自定义2
  1607. {
  1608. unchecked
  1609. {
  1610. this.Invoke((EventHandler)(delegate
  1611. {
  1612. textBox_User2.Text = "";
  1613. for (ushort i = 0; i < 16; i++)
  1614. {
  1615. if (Data[i] == 0x2E)
  1616. {
  1617. break;
  1618. }
  1619. textBox_User2.Text += ((char)Data[i]).ToString();
  1620. }
  1621. }));
  1622. }
  1623. break;
  1624. }
  1625. case 0xA810://自定义1
  1626. {
  1627. unchecked
  1628. {
  1629. this.Invoke((EventHandler)(delegate
  1630. {
  1631. textBox_User3.Text = "";
  1632. for (ushort i = 0; i < 16; i++)
  1633. {
  1634. if (Data[i] == 0x2E)
  1635. {
  1636. break;
  1637. }
  1638. textBox_User3.Text += ((char)Data[i]).ToString();
  1639. }
  1640. }));
  1641. }
  1642. break;
  1643. }
  1644. case 0xA520://生产信息
  1645. {
  1646. unchecked
  1647. {
  1648. this.Invoke((EventHandler)(delegate
  1649. {
  1650. //生产商
  1651. textBox_MAC.Text = "";
  1652. for (ushort i = 0; i < 8; i++)
  1653. {
  1654. if (Data[i] == 0x2E)
  1655. {
  1656. break;
  1657. }
  1658. textBox_MAC.Text += ((char)Data[i]).ToString();
  1659. }
  1660. //生产地
  1661. textBox_MACAdd.Text = "";
  1662. for (ushort i = 0; i < 8; i++)
  1663. {
  1664. if (Data[8 + i] == 0x2E)
  1665. {
  1666. break;
  1667. }
  1668. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1669. }
  1670. //生产日期
  1671. textBox_MACDate.Text = "";
  1672. for (ushort i = 0; i < 8; i++)
  1673. {
  1674. if (Data[16 + i] == 0x2E)
  1675. {
  1676. break;
  1677. }
  1678. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1679. }
  1680. //品牌信息
  1681. textBox_PP.Text = "";
  1682. for (ushort i = 0; i < 8; i++)
  1683. {
  1684. if (Data[24 + i] == 0x2E)
  1685. {
  1686. break;
  1687. }
  1688. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1689. }
  1690. }));
  1691. }
  1692. break;
  1693. }
  1694. case 0xA408://密钥
  1695. {
  1696. unchecked
  1697. {
  1698. this.Invoke((EventHandler)(delegate
  1699. {
  1700. textBox_Key.Text = "";
  1701. for (ushort i = 0; i < 8; i++)
  1702. {
  1703. textBox_Key.Text += ((char)Data[i]).ToString();
  1704. }
  1705. }));
  1706. }
  1707. break;
  1708. }
  1709. case 0xAB09://存储器数据
  1710. case 0xAB0A:
  1711. case 0xAB0B:
  1712. case 0xAB0C:
  1713. {
  1714. unchecked
  1715. {
  1716. this.Invoke((EventHandler)(delegate
  1717. {
  1718. long ByteNum = 0;
  1719. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1720. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1721. {
  1722. for (int i = 0; i < ByteNum; i++)
  1723. {
  1724. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1725. }
  1726. }
  1727. else //根据设置自动转换10进制显示
  1728. {
  1729. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1730. {
  1731. switch (ByteNum)
  1732. {
  1733. case 1:
  1734. {
  1735. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1736. break;
  1737. }
  1738. case 2:
  1739. {
  1740. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1741. break;
  1742. }
  1743. case 3:
  1744. {
  1745. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1746. break;
  1747. }
  1748. case 4:
  1749. {
  1750. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1751. break;
  1752. }
  1753. default:
  1754. {
  1755. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1756. break;
  1757. }
  1758. }
  1759. }
  1760. else //16进制显示
  1761. {
  1762. switch (ByteNum)
  1763. {
  1764. case 1:
  1765. {
  1766. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1767. break;
  1768. }
  1769. case 2:
  1770. {
  1771. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1772. break;
  1773. }
  1774. case 3:
  1775. {
  1776. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1777. break;
  1778. }
  1779. case 4:
  1780. {
  1781. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1782. break;
  1783. }
  1784. default:
  1785. {
  1786. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1787. break;
  1788. }
  1789. }
  1790. }
  1791. }
  1792. }));
  1793. }
  1794. break;
  1795. }
  1796. case 0xAB88://故障日志
  1797. {
  1798. unchecked
  1799. {
  1800. this.Invoke((EventHandler)(delegate
  1801. {
  1802. //电机存储的故障日志,一包128字节包含2条故障日志
  1803. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1804. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1805. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1806. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1807. //数据显示
  1808. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1809. }));
  1810. }
  1811. break;
  1812. }
  1813. case 0x1401://在线检测结果
  1814. {
  1815. unchecked
  1816. {
  1817. this.Invoke((EventHandler)(delegate
  1818. {
  1819. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1820. }));
  1821. }
  1822. break;
  1823. }
  1824. case 0x1510://骑行历史信息
  1825. {
  1826. unchecked
  1827. {
  1828. this.Invoke((EventHandler)(delegate
  1829. {
  1830. long DataTemp32;
  1831. //ODO里程
  1832. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1833. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1834. textBox_ODO_KM.Text = DataTemp32.ToString();
  1835. //ODO时间
  1836. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1837. if (DataTemp32 >= 60 * 100000)
  1838. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1839. else
  1840. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1841. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1842. //TRIP里程
  1843. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1844. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1845. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1846. //TRIP时间
  1847. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1848. if (DataTemp32 >= 60 * 100000)
  1849. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1850. else
  1851. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1852. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1853. }));
  1854. }
  1855. break;
  1856. }
  1857. case 0x1720://客户信息
  1858. {
  1859. unchecked
  1860. {
  1861. this.Invoke((EventHandler)(delegate
  1862. {
  1863. //软件标识
  1864. textBox_SP.Text = "";
  1865. textBox_OBC_ReadSP.Text = "";
  1866. textBox_FacModeSP.Text = "";
  1867. for (ushort i = 0; i < 23; i++)
  1868. {
  1869. if (Data[i] == 'r')
  1870. {
  1871. Data[i] = (byte)'.';
  1872. }
  1873. textBox_SP.Text += ((char)Data[i]).ToString();
  1874. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1875. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1876. }
  1877. //Git提交版本信息
  1878. textBox_FacModeGit.Text = "";
  1879. for (ushort i = 0; i < 9; i++)
  1880. {
  1881. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  1882. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  1883. }
  1884. Class_Motor_Ver.Special = textBox_SP.Text;
  1885. }));
  1886. }
  1887. break;
  1888. }
  1889. case 0xBA20: //调试信息
  1890. {
  1891. unchecked
  1892. {
  1893. this.Invoke((EventHandler)(delegate
  1894. {
  1895. MC_DebugInfo_Refresh = true;
  1896. //系统状态机
  1897. DataTemp = (short)(Data[0]);
  1898. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  1899. //二层状态机
  1900. DataTemp = (short)(Data[1]);
  1901. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  1902. //电机状态机
  1903. DataTemp = (short)(Data[2]);
  1904. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  1905. //助力状态机
  1906. DataTemp = (short)(Data[3]);
  1907. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  1908. //IdRef
  1909. DataTemp = (short)(Data[5] * 256 + Data[4]);
  1910. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  1911. //IqRef
  1912. DataTemp = (short)(Data[7] * 256 + Data[6]);
  1913. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  1914. //UdRef
  1915. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1916. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  1917. //UqRef
  1918. DataTemp = (short)(Data[11] * 256 + Data[10]);
  1919. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  1920. //瞬时力矩
  1921. DataTemp = (short)(Data[13] * 256 + Data[12]);
  1922. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  1923. //时间滤波力矩
  1924. DataTemp = (short)(Data[15] * 256 + Data[14]);
  1925. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  1926. //踏频滤波力矩
  1927. DataTemp = (short)(Data[17] * 256 + Data[16]);
  1928. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  1929. //IdFdb
  1930. DataTemp = (short)(Data[19] * 256 + Data[18]);
  1931. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  1932. //IqFdb
  1933. DataTemp = (short)(Data[21] * 256 + Data[20]);
  1934. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  1935. //助力输出
  1936. DataTemp = (short)(Data[23] * 256 + Data[22]);
  1937. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  1938. //数据保存
  1939. RunInfoAutoSave();
  1940. }));
  1941. }
  1942. break;
  1943. }
  1944. case 0xBB20: //产品标签信息
  1945. {
  1946. unchecked
  1947. {
  1948. this.Invoke((EventHandler)(delegate
  1949. {
  1950. //产品标签
  1951. textBox_TagInfo.Text = "";
  1952. for (ushort i = 0; i < 32; i++)
  1953. {
  1954. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  1955. }
  1956. }));
  1957. }
  1958. break;
  1959. }
  1960. case 0xBC20: //内阻校正信息
  1961. {
  1962. unchecked
  1963. {
  1964. this.Invoke((EventHandler)(delegate
  1965. {
  1966. //内阻1
  1967. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1968. textBox_MOS_R1.Text = Convert.ToString(uData16);
  1969. //内阻2
  1970. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  1971. textBox_MOS_R2.Text = Convert.ToString(uData16);
  1972. //内阻3
  1973. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  1974. textBox_MOS_R3.Text = Convert.ToString(uData16);
  1975. //K1
  1976. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  1977. textBox_MOS_K1.Text = Convert.ToString(uData16);
  1978. //K2
  1979. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  1980. textBox_MOS_K2.Text = Convert.ToString(uData16);
  1981. //K3
  1982. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  1983. textBox_MOS_K3.Text = Convert.ToString(uData16);
  1984. //K4
  1985. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  1986. textBox_MOS_K4.Text = Convert.ToString(uData16);
  1987. //K5
  1988. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  1989. textBox_MOS_K5.Text = Convert.ToString(uData16);
  1990. }));
  1991. }
  1992. break;
  1993. }
  1994. case 0xBD20: //整车信息2
  1995. {
  1996. unchecked
  1997. {
  1998. this.Invoke((EventHandler)(delegate
  1999. {
  2000. richTextBox_BikeParam2.Clear();
  2001. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2002. {
  2003. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2004. }
  2005. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2006. }));
  2007. }
  2008. break;
  2009. }
  2010. case 0xBE20: //用户骑行参数
  2011. {
  2012. unchecked
  2013. {
  2014. this.Invoke((EventHandler)(delegate
  2015. {
  2016. richTextBox_UsrRidesParam.Clear();
  2017. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2018. {
  2019. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2020. }
  2021. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2022. }));
  2023. }
  2024. break;
  2025. }
  2026. case 0xC109: //Boot版本信息
  2027. {
  2028. BootInfo = "";
  2029. for (ushort i = 0; i < 9; i++)
  2030. {
  2031. BootInfo += ((char)Data[i]).ToString();
  2032. }
  2033. break;
  2034. }
  2035. default:
  2036. {
  2037. break;
  2038. }
  2039. }
  2040. }
  2041. #endregion
  2042. #region 解析BMS广播的命令
  2043. else if (ID == 0x720)
  2044. {
  2045. switch (CmdTemp)
  2046. {
  2047. case 0x1010://BMS运行信息
  2048. {
  2049. unchecked
  2050. {
  2051. this.Invoke((EventHandler)(delegate
  2052. {
  2053. BMS_RunInfo_Refresh = true;
  2054. richTextBox_OBC_BMS_RunInfo.Clear();
  2055. //电压
  2056. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2057. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2058. //电流
  2059. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2060. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2061. //剩余容量
  2062. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2063. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2064. //满充容量
  2065. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2066. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2067. //电芯温度
  2068. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2069. //剩余电量
  2070. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2071. //电池状态
  2072. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2073. //SOH
  2074. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2075. //循环次数
  2076. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2077. }));
  2078. }
  2079. break;
  2080. }
  2081. default: break;
  2082. }
  2083. }
  2084. #endregion
  2085. #region 解析电机发送OBC的命令
  2086. else if (ID == 0x713)
  2087. {
  2088. switch (CmdTemp)
  2089. {
  2090. case 0x5408://电机用户参数
  2091. {
  2092. unchecked
  2093. {
  2094. this.Invoke((EventHandler)(delegate
  2095. {
  2096. richTextBox_OBC_ReadUserInfo.Clear();
  2097. //默认周长
  2098. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2099. //启动模式
  2100. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2101. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2102. //限速
  2103. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2104. //周长微调
  2105. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2106. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2107. //助力方案
  2108. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2109. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2110. //关机时间
  2111. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2112. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2113. //限速微调
  2114. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2115. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2116. }));
  2117. }
  2118. break;
  2119. }
  2120. case 0x5303://电机应答反馈
  2121. {
  2122. unchecked
  2123. {
  2124. this.Invoke((EventHandler)(delegate
  2125. {
  2126. timer_1s.Enabled = false;
  2127. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2128. timer_1s.Enabled = true;
  2129. }));
  2130. }
  2131. break;
  2132. }
  2133. case 0x5620: //用户骑行参数
  2134. {
  2135. unchecked
  2136. {
  2137. this.Invoke((EventHandler)(delegate
  2138. {
  2139. richTextBox_UsrRidesParam.Clear();
  2140. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2141. {
  2142. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2143. }
  2144. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2145. }));
  2146. }
  2147. break;
  2148. }
  2149. default: break;
  2150. }
  2151. }
  2152. #endregion
  2153. }
  2154. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2155. {
  2156. CmdRevStrTemp = "";
  2157. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2158. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2159. ushort len = (ushort)(CmdTemp & 0x00FF);
  2160. for (int i = 0; i < len ; i++)
  2161. {
  2162. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2163. }
  2164. }
  2165. #endregion
  2166. /// <summary>
  2167. /// 端口连接或断开
  2168. /// </summary>
  2169. private void PortConnect()
  2170. {
  2171. bool result = false;
  2172. if (连接ToolStripMenuItem.Text == "连接")
  2173. {
  2174. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2175. if (result)
  2176. {
  2177. toolStripComboBox_ComNum.Enabled = false;
  2178. toolStripComboBox_Baudrate.Enabled = false;
  2179. 刷新ToolStripMenuItem.Enabled = false;
  2180. 连接ToolStripMenuItem.Text = "断开";
  2181. 连接ToolStripMenuItem.Checked = true;
  2182. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2183. label_PortStatus.BackColor = Color.Green;
  2184. }
  2185. }
  2186. else if (连接ToolStripMenuItem.Text == "断开")
  2187. {
  2188. checkBox_OBC_StartSetGearSt.Checked = false;
  2189. checkBox_OBC_StartReadBMS.Checked = false;
  2190. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2191. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2192. toolStripComboBox_ComNum.Enabled = true;
  2193. toolStripComboBox_Baudrate.Enabled = true;
  2194. 刷新ToolStripMenuItem.Enabled = true;
  2195. 连接ToolStripMenuItem.Text = "连接";
  2196. 连接ToolStripMenuItem.Checked = false;
  2197. label_COM_Sta.Text = "连接状态:未连接";
  2198. label_PortStatus.BackColor = Color.Red;
  2199. }
  2200. }
  2201. /// <summary>
  2202. /// 端口连接事件
  2203. /// </summary>
  2204. /// <param name="sender"></param>
  2205. /// <param name="e"></param>
  2206. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2207. {
  2208. PortConnect();
  2209. }
  2210. /// <summary>
  2211. /// 端口号刷新事件
  2212. /// </summary>
  2213. /// <param name="sender"></param>
  2214. /// <param name="e"></param>
  2215. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2216. {
  2217. toolStripComboBox_ComNum.Items.Clear();
  2218. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2219. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2220. }
  2221. /// <summary>
  2222. /// 转速调节事件
  2223. /// </summary>
  2224. /// <param name="sender"></param>
  2225. /// <param name="e"></param>
  2226. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  2227. {
  2228. //生产模式转速设置值更新
  2229. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  2230. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  2231. //设置转速百分比
  2232. var Data = new byte[1];
  2233. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  2234. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  2235. }
  2236. /// <summary>
  2237. /// 存储标志修改事件
  2238. /// </summary>
  2239. /// <param name="sender"></param>
  2240. /// <param name="e"></param>
  2241. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2242. {
  2243. if (写入存储ToolStripMenuItem.Checked)
  2244. {
  2245. EnterForm1.ShowDialog();
  2246. try
  2247. {
  2248. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2249. {
  2250. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2251. {
  2252. 写入存储ToolStripMenuItem.Checked = false;
  2253. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2254. }
  2255. else
  2256. {
  2257. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2258. }
  2259. }
  2260. else
  2261. {
  2262. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2263. }
  2264. }
  2265. catch (Exception)
  2266. {
  2267. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2268. }
  2269. }
  2270. else
  2271. {
  2272. 写入存储ToolStripMenuItem.Checked = true;
  2273. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2274. }
  2275. }
  2276. /// <summary>
  2277. /// 1s定时器
  2278. /// </summary>
  2279. /// <param name="sender"></param>
  2280. /// <param name="e"></param>
  2281. private void timer_1s_Tick(object sender, EventArgs e)
  2282. {
  2283. //时间更新
  2284. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2285. //MC_Runinfo超时清除
  2286. if (MC_RunInfo_Refresh == false)
  2287. {
  2288. MC_RunInfo_Refresh_Cnt++;
  2289. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2290. {
  2291. MC_RunInfo_Clear();
  2292. MC_RunInfo_Refresh_Cnt = 0;
  2293. }
  2294. }
  2295. else
  2296. {
  2297. MC_RunInfo_Refresh_Cnt = 0;
  2298. }
  2299. MC_RunInfo_Refresh = false;
  2300. //MC_Debuginfo超时清除
  2301. if (MC_DebugInfo_Refresh == false)
  2302. {
  2303. MC_DebugInfo_Refresh_Cnt++;
  2304. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2305. {
  2306. MC_DebugInfo_Clear();
  2307. MC_DebugInfo_Refresh_Cnt = 0;
  2308. }
  2309. }
  2310. else
  2311. {
  2312. MC_DebugInfo_Refresh_Cnt = 0;
  2313. }
  2314. MC_DebugInfo_Refresh = false;
  2315. //BMS_RunInfo超时清除
  2316. if (BMS_RunInfo_Refresh == false)
  2317. {
  2318. BMS_RunInfo_Refresh_Cnt++;
  2319. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2320. {
  2321. richTextBox_OBC_BMS_RunInfo.Clear();
  2322. BMS_RunInfo_Refresh_Cnt = 0;
  2323. }
  2324. }
  2325. else
  2326. {
  2327. BMS_RunInfo_Refresh_Cnt = 0;
  2328. }
  2329. BMS_RunInfo_Refresh = false;
  2330. //故障码超时清除
  2331. if (MC_ErrorCode_Refresh == false)
  2332. {
  2333. MC_ErrorCode_Refresh_Cnt++;
  2334. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2335. {
  2336. textBox_ErrorCode.Text = "---";
  2337. MC_ErrorCode_Refresh_Cnt = 0;
  2338. }
  2339. }
  2340. else
  2341. {
  2342. MC_ErrorCode_Refresh_Cnt = 0;
  2343. }
  2344. MC_ErrorCode_Refresh = false;
  2345. //CDL连接超时
  2346. if (识别通讯盒ToolStripMenuItem.Checked)
  2347. {
  2348. if (mySerialProcess.CDL_Online_Flag == false)
  2349. {
  2350. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2351. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2352. {
  2353. timer_1s.Enabled = false;
  2354. MessageBox.Show("连接失败!", "提示");
  2355. timer_1s.Enabled = true;
  2356. //关闭串口
  2357. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2358. toolStripComboBox_ComNum.Enabled = true;
  2359. toolStripComboBox_Baudrate.Enabled = true;
  2360. 刷新ToolStripMenuItem.Enabled = true;
  2361. 连接ToolStripMenuItem.Text = "连接";
  2362. 连接ToolStripMenuItem.Checked = false;
  2363. label_COM_Sta.Text = "连接状态:未连接";
  2364. label_PortStatus.BackColor = Color.Red;
  2365. }
  2366. }
  2367. }
  2368. //OBC定时发送设置档位
  2369. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2370. {
  2371. var CtrlCode = new byte[2];
  2372. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2373. CtrlCode[0] = 0x33;
  2374. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2375. CtrlCode[0] = 0x22;
  2376. else
  2377. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2378. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2379. CtrlCode[1] = 0xF1;
  2380. else
  2381. CtrlCode[1] = 0xF0;
  2382. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2383. {
  2384. checkBox_OBC_StartSetGearSt.Checked = false;
  2385. }
  2386. }
  2387. //OBC定时发送查询电池
  2388. if (checkBox_OBC_StartReadBMS.Checked == true)
  2389. {
  2390. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2391. {
  2392. checkBox_OBC_StartReadBMS.Checked = false;
  2393. }
  2394. }
  2395. //定时读取存储器
  2396. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2397. {
  2398. var Address = new byte[4];
  2399. UInt32 Address_Begin;
  2400. UInt32 Addres_End;
  2401. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2402. richTextBox_RamFlasgData.Clear();
  2403. do
  2404. {
  2405. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2406. {
  2407. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2408. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2409. continue;
  2410. }
  2411. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2412. {
  2413. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2414. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2415. continue;
  2416. }
  2417. else
  2418. {
  2419. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2420. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2421. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2422. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2423. if (Addres_End < Address_Begin)
  2424. {
  2425. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2426. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2427. continue;
  2428. }
  2429. else
  2430. {
  2431. var SendByte = new byte[8];
  2432. SendByte[0] = (byte)(Address_Begin >> 24);
  2433. SendByte[1] = (byte)(Address_Begin >> 16);
  2434. SendByte[2] = (byte)(Address_Begin >> 8);
  2435. SendByte[3] = (byte)(Address_Begin);
  2436. SendByte[4] = (byte)(Addres_End >> 24);
  2437. SendByte[5] = (byte)(Addres_End >> 16);
  2438. SendByte[6] = (byte)(Addres_End >> 8);
  2439. SendByte[7] = (byte)(Addres_End);
  2440. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2441. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2442. }
  2443. }
  2444. } while (false);
  2445. }
  2446. //写入参数等待计时
  2447. ACK_WaitCnt++;
  2448. }
  2449. /// <summary>
  2450. /// 运行信息清除
  2451. /// </summary>
  2452. private void MC_RunInfo_Clear()
  2453. {
  2454. foreach (Control c in tabPage_RunInfo.Controls)
  2455. {
  2456. if ((c is TextBox))
  2457. {
  2458. if (c.Name != textBox_ErrorCode.ToString())
  2459. c.Text = "---";
  2460. }
  2461. }
  2462. }
  2463. /// <summary>
  2464. /// 调试信息清除
  2465. /// </summary>
  2466. private void MC_DebugInfo_Clear()
  2467. {
  2468. foreach (Control c in tabPage_DebugInfo.Controls)
  2469. {
  2470. if ((c is TextBox))
  2471. {
  2472. if (c.Name != textBox_ErrorCode.ToString())
  2473. c.Text = "---";
  2474. }
  2475. }
  2476. }
  2477. /// <summary>
  2478. /// 读取马达参数
  2479. /// </summary>
  2480. /// <param name="sender"></param>
  2481. /// <param name="e"></param>
  2482. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2483. {
  2484. richTextBox_MotorParam.Clear();
  2485. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2486. }
  2487. /// <summary>
  2488. /// 写入马达参数
  2489. /// </summary>
  2490. /// <param name="sender"></param>
  2491. /// <param name="e"></param>
  2492. private void button_Write_Click(object sender, EventArgs e)
  2493. {
  2494. var ConfigParam = new byte[40];
  2495. for (int i = 0; i < 40; i++)
  2496. ConfigParam[i] = 0;
  2497. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2498. short wDataTemp = 0;
  2499. ushort DataTemp = 0;
  2500. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2501. try
  2502. {
  2503. for (int i = 0; i < strDataTemp.Length; i++)
  2504. {
  2505. if (i == 6)
  2506. {
  2507. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2508. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2509. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2510. }
  2511. else
  2512. {
  2513. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2514. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2515. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2516. }
  2517. }
  2518. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2519. }
  2520. catch (Exception)
  2521. {
  2522. timer_1s.Enabled = false;
  2523. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2524. timer_1s.Enabled = true;
  2525. }
  2526. }
  2527. /// <summary>
  2528. /// 读取整车信息
  2529. /// </summary>
  2530. /// <param name="sender"></param>
  2531. /// <param name="e"></param>
  2532. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2533. {
  2534. richTextBox_BikeParam.Clear();
  2535. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2536. }
  2537. /// <summary>
  2538. /// 写入整车信息
  2539. /// </summary>
  2540. /// <param name="sender"></param>
  2541. /// <param name="e"></param>
  2542. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2543. {
  2544. var ConfigParam = new byte[28];
  2545. for (int i = 0; i < 28; i++)
  2546. ConfigParam[i] = 0;
  2547. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2548. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2549. try
  2550. {
  2551. for (int i = 0; i < strDataTemp.Length; i++)
  2552. {
  2553. short wDataTemp = 0;
  2554. //前后灯参数修改
  2555. if (i == 8)
  2556. {
  2557. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2558. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2559. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2560. }
  2561. //开关机参数
  2562. else if (i == 11)
  2563. {
  2564. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2565. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2566. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2567. }
  2568. else
  2569. {
  2570. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2571. }
  2572. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2573. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2574. }
  2575. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2576. }
  2577. catch (Exception)
  2578. {
  2579. timer_1s.Enabled = false;
  2580. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2581. timer_1s.Enabled = true;
  2582. }
  2583. }
  2584. /// <summary>
  2585. /// 读取控制器参数
  2586. /// </summary>
  2587. /// <param name="sender"></param>
  2588. /// <param name="e"></param>
  2589. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2590. {
  2591. richTextBox_ControlParam.Clear();
  2592. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2593. }
  2594. /// <summary>
  2595. /// 写入控制器参数
  2596. /// </summary>
  2597. /// <param name="sender"></param>
  2598. /// <param name="e"></param>
  2599. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2600. {
  2601. var ConfigParam = new byte[34];
  2602. for (int i = 0; i < 34; i++)
  2603. ConfigParam[i] = 0;
  2604. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2605. ushort uwDataTemp = 0;
  2606. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2607. try
  2608. {
  2609. for (int i = 0; i < strDataTemp.Length; i++)
  2610. {
  2611. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2612. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2613. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2614. }
  2615. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2616. }
  2617. catch (Exception)
  2618. {
  2619. timer_1s.Enabled = false;
  2620. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2621. timer_1s.Enabled = true;
  2622. }
  2623. }
  2624. /// <summary>
  2625. /// 读取助力参数
  2626. /// </summary>
  2627. /// <param name="sender"></param>
  2628. /// <param name="e"></param>
  2629. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2630. {
  2631. var ConfigParam = new byte[4];
  2632. int AssistNum = 0;
  2633. try
  2634. {
  2635. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2636. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2637. ConfigParam[1] = (byte)(AssistNum >> 8);
  2638. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2639. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2640. ConfigParam[3] = (byte)(AssistNum >> 8);
  2641. richTextBox_AssistParam.Clear();
  2642. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2643. }
  2644. catch (Exception)
  2645. {
  2646. timer_1s.Enabled = false;
  2647. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2648. timer_1s.Enabled = true;
  2649. }
  2650. }
  2651. /// <summary>
  2652. /// 写入助力参数
  2653. /// </summary>
  2654. /// <param name="sender"></param>
  2655. /// <param name="e"></param>
  2656. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2657. {
  2658. var ConfigParam = new byte[80];
  2659. for (int i = 0; i < 80; i++)
  2660. ConfigParam[i] = 0;
  2661. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2662. long lDataTemp = 0;
  2663. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2664. int index_1 = 0, index_2 = 0;
  2665. try
  2666. {
  2667. for (int i = 0; i < strDataTemp.Length; i++)
  2668. {
  2669. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2670. {
  2671. index_1 = i;
  2672. break;
  2673. }
  2674. }
  2675. for (int i = 0; i < strDataTemp.Length; i++)
  2676. {
  2677. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2678. {
  2679. index_2 = i;
  2680. break;
  2681. }
  2682. }
  2683. for (int i = 0; i < strDataTemp.Length; i++)
  2684. {
  2685. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2686. if (i < index_1)
  2687. {
  2688. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2689. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2690. }
  2691. else if (i <= index_2)
  2692. {
  2693. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2694. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2695. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2696. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2697. }
  2698. else
  2699. {
  2700. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2701. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2702. }
  2703. }
  2704. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2705. }
  2706. catch (Exception)
  2707. {
  2708. timer_1s.Enabled = false;
  2709. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2710. timer_1s.Enabled = true;
  2711. }
  2712. }
  2713. /// <summary>
  2714. /// 读取调试参数
  2715. /// </summary>
  2716. /// <param name="sender"></param>
  2717. /// <param name="e"></param>
  2718. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2719. {
  2720. richTextBox_DebugParam.Clear();
  2721. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2722. }
  2723. /// <summary>
  2724. /// 写入调试参数
  2725. /// </summary>
  2726. /// <param name="sender"></param>
  2727. /// <param name="e"></param>
  2728. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2729. {
  2730. var ConfigParam = new byte[60];
  2731. for (int i = 0; i < 60; i++)
  2732. ConfigParam[i] = 0;
  2733. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2734. ushort uwDataTemp = 0;
  2735. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2736. try
  2737. {
  2738. for (int i = 0; i < strDataTemp.Length; i++)
  2739. {
  2740. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2741. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2742. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2743. }
  2744. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2745. }
  2746. catch (Exception)
  2747. {
  2748. timer_1s.Enabled = false;
  2749. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2750. timer_1s.Enabled = true;
  2751. }
  2752. }
  2753. /// <summary>
  2754. /// 读取历史
  2755. /// </summary>
  2756. /// <param name="sender"></param>
  2757. /// <param name="e"></param>
  2758. private void button_ReadRecord_Click(object sender, EventArgs e)
  2759. {
  2760. richTextBox_Record.Clear();
  2761. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2762. }
  2763. /// <summary>
  2764. /// 读取传感器参数
  2765. /// </summary>
  2766. /// <param name="sender"></param>
  2767. /// <param name="e"></param>
  2768. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2769. {
  2770. richTextBox_SensorParam.Clear();
  2771. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2772. }
  2773. /// <summary>
  2774. /// 写入力矩传感器标定值
  2775. /// </summary>
  2776. /// <param name="sender"></param>
  2777. /// <param name="e"></param>
  2778. private void button_Write_Cal_Click(object sender, EventArgs e)
  2779. {
  2780. var ConfigParam = new byte[4];
  2781. for (int i = 0; i < 4; i++)
  2782. ConfigParam[i] = 0;
  2783. ushort uwDataTemp = 0;
  2784. try
  2785. {
  2786. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2787. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2788. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2789. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2790. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2791. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2792. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2793. }
  2794. catch (Exception)
  2795. {
  2796. timer_1s.Enabled = false;
  2797. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2798. timer_1s.Enabled = true;
  2799. }
  2800. }
  2801. /// <summary>
  2802. /// 写入传感器参数
  2803. /// </summary>
  2804. /// <param name="sender"></param>
  2805. /// <param name="e"></param>
  2806. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2807. {
  2808. var ConfigParam = new byte[14];
  2809. for (int i = 0; i < 14; i++)
  2810. ConfigParam[i] = 0;
  2811. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2812. ushort uwDataTemp = 0;
  2813. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2814. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2815. int index = 0;
  2816. try
  2817. {
  2818. for (int i = 0; i < strDataTemp.Length; i++)
  2819. {
  2820. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2821. {
  2822. index = i;
  2823. break;
  2824. }
  2825. }
  2826. for (int i = 0; i < (strDataTemp.Length - index); i++)
  2827. {
  2828. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  2829. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2830. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2831. }
  2832. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  2833. }
  2834. catch (Exception)
  2835. {
  2836. timer_1s.Enabled = false;
  2837. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2838. timer_1s.Enabled = true;
  2839. }
  2840. }
  2841. /// <summary>
  2842. /// 写入型号
  2843. /// </summary>
  2844. /// <param name="sender"></param>
  2845. /// <param name="e"></param>
  2846. private void button_WriteModel_Click(object sender, EventArgs e)
  2847. {
  2848. string Mode = textBox_Model.Text;
  2849. var ModeArray = new byte[16];
  2850. for (ushort i = 0; i < Mode.Length; i++)
  2851. {
  2852. ModeArray[i] = (byte)Mode[i];
  2853. }
  2854. if (Mode.Length < 16)
  2855. {
  2856. ModeArray[Mode.Length] = (byte)'.';
  2857. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2858. {
  2859. ModeArray[Mode.Length + 1 + i] = 0x20;
  2860. }
  2861. }
  2862. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2863. }
  2864. /// <summary>
  2865. /// 写入SN
  2866. /// </summary>
  2867. /// <param name="sender"></param>
  2868. /// <param name="e"></param>
  2869. private void button_WriteSN_Click(object sender, EventArgs e)
  2870. {
  2871. string SN = textBox_SN.Text;
  2872. var SNArray = new byte[16];
  2873. for (ushort i = 0; i < SN.Length; i++)
  2874. {
  2875. SNArray[i] = (byte)SN[i];
  2876. }
  2877. if (SN.Length < 16)
  2878. {
  2879. SNArray[SN.Length] = (byte)'.';
  2880. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2881. {
  2882. SNArray[SN.Length + 1 + i] = 0x20;
  2883. }
  2884. }
  2885. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2886. }
  2887. /// <summary>
  2888. /// 查询版本信息
  2889. /// </summary>
  2890. /// <param name="sender"></param>
  2891. /// <param name="e"></param>
  2892. private void button_ReadVersion_Click(object sender, EventArgs e)
  2893. {
  2894. textBox_Model.Text = "---";
  2895. textBox_SN.Text = "---";
  2896. textBox_HW.Text = "---";
  2897. textBox_FW.Text = "---";
  2898. textBox_SP.Text = "---";
  2899. textBox_OBC_ReadModel.Text = "---";
  2900. textBox_OBC_ReadSN.Text = "---";
  2901. textBox_OBC_ReadHW.Text = "---";
  2902. textBox_OBC_ReadFW.Text = "---";
  2903. textBox_OBC_ReadSP.Text = "---";
  2904. textBox_FacModeName.Text = "---";
  2905. textBox_FacModeNum.Text = "---";
  2906. textBox_FacModeHW.Text = "---";
  2907. textBox_FacModeFW.Text = "---";
  2908. textBox_FacModeSP.Text = "---";
  2909. Class_Motor_Ver.Mode = "---";
  2910. Class_Motor_Ver.SN = "---";
  2911. Class_Motor_Ver.HW = "---";
  2912. Class_Motor_Ver.FW = "---";
  2913. Class_Motor_Ver.Special = "---";
  2914. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2915. }
  2916. /// <summary>
  2917. /// 查询自定义1
  2918. /// </summary>
  2919. /// <param name="sender"></param>
  2920. /// <param name="e"></param>
  2921. private void button_ReadUser1_Click(object sender, EventArgs e)
  2922. {
  2923. textBox_User1.Text = "---";
  2924. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  2925. }
  2926. /// <summary>
  2927. /// 查询自定义2
  2928. /// </summary>
  2929. /// <param name="sender"></param>
  2930. /// <param name="e"></param>
  2931. private void button_ReadUser2_Click(object sender, EventArgs e)
  2932. {
  2933. textBox_User2.Text = "---";
  2934. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  2935. }
  2936. /// <summary>
  2937. /// 查询自定义3
  2938. /// </summary>
  2939. /// <param name="sender"></param>
  2940. /// <param name="e"></param>
  2941. private void button_ReadUser3_Click(object sender, EventArgs e)
  2942. {
  2943. textBox_User3.Text = "---";
  2944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  2945. }
  2946. /// <summary>
  2947. /// 写入自定义字符串1
  2948. /// </summary>
  2949. /// <param name="sender"></param>
  2950. /// <param name="e"></param>
  2951. private void button_WriteUser1_Click(object sender, EventArgs e)
  2952. {
  2953. string User = textBox_User1.Text;
  2954. var UserArray = new byte[16];
  2955. for (ushort i = 0; i < User.Length; i++)
  2956. {
  2957. UserArray[i] = (byte)User[i];
  2958. }
  2959. if (User.Length < 16)
  2960. {
  2961. UserArray[User.Length] = (byte)'.';
  2962. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2963. {
  2964. UserArray[User.Length + 1 + i] = 0x20;
  2965. }
  2966. }
  2967. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  2968. }
  2969. /// <summary>
  2970. /// 写入自定义字符串2
  2971. /// </summary>
  2972. /// <param name="sender"></param>
  2973. /// <param name="e"></param>
  2974. private void button_WriteUser2_Click(object sender, EventArgs e)
  2975. {
  2976. string User = textBox_User2.Text;
  2977. var UserArray = new byte[16];
  2978. for (ushort i = 0; i < User.Length; i++)
  2979. {
  2980. UserArray[i] = (byte)User[i];
  2981. }
  2982. if (User.Length < 16)
  2983. {
  2984. UserArray[User.Length] = (byte)'.';
  2985. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2986. {
  2987. UserArray[User.Length + 1 + i] = 0x20;
  2988. }
  2989. }
  2990. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  2991. }
  2992. /// <summary>
  2993. /// 写入自定义字符串3
  2994. /// </summary>
  2995. /// <param name="sender"></param>
  2996. /// <param name="e"></param>
  2997. private void button_WriteUser3_Click(object sender, EventArgs e)
  2998. {
  2999. string User = textBox_User3.Text;
  3000. var UserArray = new byte[16];
  3001. for (ushort i = 0; i < User.Length; i++)
  3002. {
  3003. UserArray[i] = (byte)User[i];
  3004. }
  3005. if (User.Length < 16)
  3006. {
  3007. UserArray[User.Length] = (byte)'.';
  3008. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3009. {
  3010. UserArray[User.Length + 1 + i] = 0x20;
  3011. }
  3012. }
  3013. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3014. }
  3015. /// <summary>
  3016. /// 查询生产信息
  3017. /// </summary>
  3018. /// <param name="sender"></param>
  3019. /// <param name="e"></param>
  3020. private void button_ReadMAC_Click(object sender, EventArgs e)
  3021. {
  3022. textBox_MAC.Text = "---";
  3023. textBox_MACAdd.Text = "---";
  3024. textBox_MACDate.Text = "---";
  3025. textBox_PP.Text = "---";
  3026. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3027. }
  3028. /// <summary>
  3029. /// 写入生产信息
  3030. /// </summary>
  3031. /// <param name="sender"></param>
  3032. /// <param name="e"></param>
  3033. private void button_WriteMac_Click(object sender, EventArgs e)
  3034. {
  3035. var MACArray = new byte[32];
  3036. //填入生产商
  3037. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3038. {
  3039. MACArray[i] = (byte)textBox_MAC.Text[i];
  3040. }
  3041. if (textBox_MAC.Text.Length < 8)
  3042. {
  3043. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3044. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3045. {
  3046. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3047. }
  3048. }
  3049. //填入生产地
  3050. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3051. {
  3052. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3053. }
  3054. if (textBox_MACAdd.Text.Length < 8)
  3055. {
  3056. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3057. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3058. {
  3059. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3060. }
  3061. }
  3062. //填入生产日期
  3063. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3064. {
  3065. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3066. }
  3067. if (textBox_MACDate.Text.Length < 8)
  3068. {
  3069. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3070. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3071. {
  3072. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3073. }
  3074. }
  3075. //填入品牌
  3076. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3077. {
  3078. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3079. }
  3080. if (textBox_PP.Text.Length < 8)
  3081. {
  3082. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3083. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3084. {
  3085. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3086. }
  3087. }
  3088. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3089. }
  3090. /// <summary>
  3091. /// 查询密钥
  3092. /// </summary>
  3093. /// <param name="sender"></param>
  3094. /// <param name="e"></param>
  3095. private void button_ReadKey_Click(object sender, EventArgs e)
  3096. {
  3097. textBox_Key.Text = "---";
  3098. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3099. }
  3100. /// <summary>
  3101. /// 写入校验密钥
  3102. /// </summary>
  3103. /// <param name="sender"></param>
  3104. /// <param name="e"></param>
  3105. private void button_WriteKey_Click(object sender, EventArgs e)
  3106. {
  3107. string Key = textBox_Key.Text;
  3108. var KeyArray = new byte[8];
  3109. if (Key.Length != 8)
  3110. {
  3111. timer_1s.Enabled = false;
  3112. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3113. timer_1s.Enabled = true;
  3114. return;
  3115. }
  3116. for (ushort i = 0; i < Key.Length; i++)
  3117. {
  3118. KeyArray[i] = (byte)Key[i];
  3119. }
  3120. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3121. }
  3122. /// <summary>
  3123. /// 查询在线检测结果
  3124. /// </summary>
  3125. /// <param name="sender"></param>
  3126. /// <param name="e"></param>
  3127. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3128. {
  3129. textBox_Online.Text = "---";
  3130. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3131. }
  3132. /// <summary>
  3133. /// 系统清除
  3134. /// </summary>
  3135. /// <param name="sender"></param>
  3136. /// <param name="e"></param>
  3137. private void button_SystemClear_Click(object sender, EventArgs e)
  3138. {
  3139. var Code = new byte[5];
  3140. Code[0] = (byte)'C';
  3141. Code[1] = (byte)'L';
  3142. Code[2] = (byte)'E';
  3143. Code[3] = (byte)'A';
  3144. Code[4] = (byte)'R';
  3145. timer_1s.Enabled = false;
  3146. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3147. {
  3148. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3149. {
  3150. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3151. {
  3152. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3153. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3154. }
  3155. }
  3156. }
  3157. timer_1s.Enabled = true;
  3158. }
  3159. /// <summary>
  3160. /// 参数还原
  3161. /// </summary>
  3162. /// <param name="sender"></param>
  3163. /// <param name="e"></param>
  3164. private void button_Recovery_Click(object sender, EventArgs e)
  3165. {
  3166. var Code = new byte[8];
  3167. Code[0] = (byte)'R';
  3168. Code[1] = (byte)'E';
  3169. Code[2] = (byte)'C';
  3170. Code[3] = (byte)'O';
  3171. Code[4] = (byte)'V';
  3172. Code[5] = (byte)'E';
  3173. Code[6] = (byte)'R';
  3174. Code[7] = (byte)'Y';
  3175. timer_1s.Enabled = false;
  3176. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3177. {
  3178. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3179. {
  3180. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3181. {
  3182. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3183. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3184. }
  3185. }
  3186. }
  3187. timer_1s.Enabled = true;
  3188. }
  3189. /// <summary>
  3190. /// 系统复位
  3191. /// </summary>
  3192. /// <param name="sender"></param>
  3193. /// <param name="e"></param>
  3194. private void button_Reset_Click(object sender, EventArgs e)
  3195. {
  3196. var Code_Off = new byte[5];
  3197. var Code_Reset = new byte[5];
  3198. Code_Off[0] = (byte)'O';
  3199. Code_Off[1] = (byte)'F';
  3200. Code_Off[2] = (byte)'F';
  3201. Code_Off[3] = (byte)'.';
  3202. Code_Off[4] = (byte)'.';
  3203. Code_Reset[0] = (byte)'R';
  3204. Code_Reset[1] = (byte)'E';
  3205. Code_Reset[2] = (byte)'S';
  3206. Code_Reset[3] = (byte)'E';
  3207. Code_Reset[4] = (byte)'T';
  3208. timer_1s.Enabled = false;
  3209. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3210. {
  3211. timer_1s.Enabled = true;
  3212. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3213. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3214. PowerOffAckStatus = false;
  3215. Delay_ms(250);
  3216. int TryCnt = 3;
  3217. while ((TryCnt--) >= 0)
  3218. {
  3219. if (!PowerOffAckStatus)
  3220. {
  3221. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3222. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3223. PowerOffAckStatus = false;
  3224. Delay_ms(250);
  3225. }
  3226. else break;
  3227. }
  3228. if (PowerOffAckStatus)
  3229. {
  3230. timer_1s.Enabled = false;
  3231. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3232. timer_1s.Enabled = true;
  3233. }
  3234. else
  3235. {
  3236. timer_1s.Enabled = false;
  3237. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3238. timer_1s.Enabled = true;
  3239. }
  3240. }
  3241. timer_1s.Enabled = true;
  3242. }
  3243. /// <summary>
  3244. /// 记录清除
  3245. /// </summary>
  3246. /// <param name="sender"></param>
  3247. /// <param name="e"></param>
  3248. private void button_ClearLog_Click(object sender, EventArgs e)
  3249. {
  3250. var Code = new byte[9];
  3251. Code[0] = (byte)'L';
  3252. Code[1] = (byte)'O';
  3253. Code[2] = (byte)'G';
  3254. Code[3] = (byte)' ';
  3255. Code[4] = (byte)'C';
  3256. Code[5] = (byte)'L';
  3257. Code[6] = (byte)'E';
  3258. Code[7] = (byte)'A';
  3259. Code[8] = (byte)'R';
  3260. timer_1s.Enabled = false;
  3261. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3262. {
  3263. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3264. {
  3265. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3266. {
  3267. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3268. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3269. }
  3270. }
  3271. }
  3272. timer_1s.Enabled = true;
  3273. }
  3274. /// <summary>
  3275. /// 打开系统计算器
  3276. /// </summary>
  3277. /// <param name="sender"></param>
  3278. /// <param name="e"></param>
  3279. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3280. {
  3281. System.Diagnostics.Process.Start("calc.exe");
  3282. }
  3283. /// <summary>
  3284. ///故障转换和显示
  3285. /// </summary>
  3286. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3287. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3288. "",""};
  3289. private string ErrorInfoDisplay(UInt32 Code)
  3290. {
  3291. string Result = "";
  3292. if (Code == 0)
  3293. {
  3294. Result = "无故障";
  3295. }
  3296. else
  3297. {
  3298. for (int i = 0; i < 32; i++)
  3299. {
  3300. if ((Code & 0x01) == 0x01)
  3301. {
  3302. Result += ErrorInfo[i] + " ";
  3303. }
  3304. Code >>= 1;
  3305. }
  3306. }
  3307. return Result;
  3308. }
  3309. /// <summary>
  3310. /// 鼠标滑过故障码显示具体内容
  3311. /// </summary>
  3312. /// <param name="sender"></param>
  3313. /// <param name="e"></param>
  3314. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3315. {
  3316. // 创建the ToolTip
  3317. ToolTip toolTip1 = new ToolTip();
  3318. // 设置显示样式
  3319. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  3320. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3321. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3322. toolTip1.ShowAlways = true;//是否显示提示框
  3323. // 设置伴随的对象.
  3324. string ErrorCode = this.textBox_ErrorCode.Text;
  3325. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3326. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3327. }
  3328. /// <summary>
  3329. /// 数据记录
  3330. /// </summary>
  3331. private void RunInfoAutoSave()
  3332. {
  3333. if (运行信息记录ToolStripMenuItem.Checked == true)
  3334. {
  3335. if (RunInfoSaveFilename == string.Empty)
  3336. {
  3337. return;
  3338. }
  3339. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3340. foreach (Control c in tabPage_RunInfo.Controls)
  3341. {
  3342. if (c is TextBox)
  3343. {
  3344. SaveData += c.Text + " , ";
  3345. }
  3346. }
  3347. foreach (Control c in tabPage_DebugInfo.Controls)
  3348. {
  3349. if (c is TextBox)
  3350. {
  3351. SaveData += c.Text + " , ";
  3352. }
  3353. }
  3354. SaveData += "\r\n";
  3355. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3356. }
  3357. }
  3358. /// <summary>
  3359. /// 打开或关闭数据记录
  3360. /// </summary>
  3361. /// <param name="sender"></param>
  3362. /// <param name="e"></param>
  3363. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3364. {
  3365. if (运行信息记录ToolStripMenuItem.Checked == false)
  3366. {
  3367. if (mySerialProcess.mySerial.IsOpen == true)
  3368. {
  3369. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3370. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3371. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3372. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3373. timer_1s.Enabled = false;
  3374. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3375. timer_1s.Enabled = true;
  3376. 运行信息记录ToolStripMenuItem.Checked = true;
  3377. }
  3378. else
  3379. {
  3380. timer_1s.Enabled = false;
  3381. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3382. timer_1s.Enabled = true;
  3383. }
  3384. }
  3385. else
  3386. {
  3387. 运行信息记录ToolStripMenuItem.Checked = false;
  3388. timer_1s.Enabled = false;
  3389. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3390. timer_1s.Enabled = true;
  3391. }
  3392. }
  3393. /// <summary>
  3394. /// 仪表启动控制档位开关事件
  3395. /// </summary>
  3396. /// <param name="sender"></param>
  3397. /// <param name="e"></param>
  3398. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3399. {
  3400. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3401. {
  3402. //检查串口是否打开
  3403. if (!mySerialProcess.mySerial.IsOpen)
  3404. {
  3405. timer_1s.Enabled = false;
  3406. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3407. timer_1s.Enabled = true;
  3408. checkBox_OBC_StartSetGearSt.Checked = false;
  3409. return;
  3410. }
  3411. //检查是否选择档位和打开车灯
  3412. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3413. {
  3414. timer_1s.Enabled = false;
  3415. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3416. timer_1s.Enabled = true;
  3417. checkBox_OBC_StartSetGearSt.Checked = false;
  3418. return;
  3419. }
  3420. }
  3421. }
  3422. /// <summary>
  3423. /// OBC查询电机用户参数
  3424. /// </summary>
  3425. /// <param name="sender"></param>
  3426. /// <param name="e"></param>
  3427. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3428. {
  3429. richTextBox_OBC_ReadUserInfo.Clear();
  3430. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3431. }
  3432. /// <summary>
  3433. /// OBC设置电机用户参数
  3434. /// </summary>
  3435. /// <param name="sender"></param>
  3436. /// <param name="e"></param>
  3437. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3438. {
  3439. var UserInfoCode = new byte[8];
  3440. for (int i = 0; i < UserInfoCode.Length; i++)
  3441. UserInfoCode[i] = 0;
  3442. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3443. {
  3444. timer_1s.Enabled = false;
  3445. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3446. timer_1s.Enabled = true;
  3447. return;
  3448. }
  3449. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3450. {
  3451. timer_1s.Enabled = false;
  3452. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3453. timer_1s.Enabled = true;
  3454. return;
  3455. }
  3456. //周长微调
  3457. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3458. //启动模式
  3459. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3460. //助力方案
  3461. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3462. //自动关机时间
  3463. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3464. //限速微调
  3465. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3466. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3467. }
  3468. /// <summary>
  3469. /// OBC查询电机版本信息
  3470. /// </summary>
  3471. /// <param name="sender"></param>
  3472. /// <param name="e"></param>
  3473. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3474. {
  3475. textBox_Model.Text = "---";
  3476. textBox_SN.Text = "---";
  3477. textBox_HW.Text = "---";
  3478. textBox_FW.Text = "---";
  3479. textBox_SP.Text = "---";
  3480. textBox_OBC_ReadModel.Text = "---";
  3481. textBox_OBC_ReadSN.Text = "---";
  3482. textBox_OBC_ReadHW.Text = "---";
  3483. textBox_OBC_ReadFW.Text = "---";
  3484. textBox_OBC_ReadSP.Text = "---";
  3485. textBox_FacModeName.Text = "---";
  3486. textBox_FacModeNum.Text = "---";
  3487. textBox_FacModeHW.Text = "---";
  3488. textBox_FacModeFW.Text = "---";
  3489. textBox_FacModeSP.Text = "---";
  3490. Class_Motor_Ver.Mode = "---";
  3491. Class_Motor_Ver.SN = "---";
  3492. Class_Motor_Ver.HW = "---";
  3493. Class_Motor_Ver.FW = "---";
  3494. Class_Motor_Ver.Special = "---";
  3495. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3496. }
  3497. /// <summary>
  3498. /// OBC读取骑行历史
  3499. /// </summary>
  3500. /// <param name="sender"></param>
  3501. /// <param name="e"></param>
  3502. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3503. {
  3504. textBox_OBC_TRIP_KM.Text = "";
  3505. textBox_OBC_TRIP_TIME.Text = "";
  3506. textBox_OBC_ODO_KM.Text = "";
  3507. textBox_OBC_ODO_TIME.Text = "";
  3508. textBox_ODO_KM.Text = "---";
  3509. textBox_ODO_TIME.Text = "---";
  3510. textBox_TRIP_KM.Text = "---";
  3511. textBox_TRIP_TIME.Text = "---";
  3512. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3513. }
  3514. /// <summary>
  3515. /// OBC清除TRIP里程
  3516. /// </summary>
  3517. /// <param name="sender"></param>
  3518. /// <param name="e"></param>
  3519. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3520. {
  3521. var Code = new byte[5];
  3522. Code[0] = (byte)'C';
  3523. Code[1] = (byte)'L';
  3524. Code[2] = (byte)'E';
  3525. Code[3] = (byte)'A';
  3526. Code[4] = (byte)'R';
  3527. timer_1s.Enabled = false;
  3528. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3529. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3530. timer_1s.Enabled = true;
  3531. }
  3532. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3533. {
  3534. if (checkBox_OBC_StartReadBMS.Checked == true)
  3535. {
  3536. //检查串口是否打开
  3537. if (!mySerialProcess.mySerial.IsOpen)
  3538. {
  3539. timer_1s.Enabled = false;
  3540. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3541. timer_1s.Enabled = true;
  3542. checkBox_OBC_StartReadBMS.Checked = false;
  3543. return;
  3544. }
  3545. }
  3546. }
  3547. /// <summary>
  3548. /// 写入力矩传感器参数
  3549. /// </summary>
  3550. /// <param name="sender"></param>
  3551. /// <param name="e"></param>
  3552. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3553. {
  3554. var ConfigParam = new byte[46];
  3555. for (int i = 0; i < 14; i++)
  3556. ConfigParam[i] = 0;
  3557. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3558. ushort uwDataTemp = 0;
  3559. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3560. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3561. int index = 0;
  3562. try
  3563. {
  3564. for (int i = 0; i < strDataTemp.Length; i++)
  3565. {
  3566. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3567. {
  3568. index = i;
  3569. break;
  3570. }
  3571. }
  3572. for (int i = 0; i < (index + 1); i++)
  3573. {
  3574. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3575. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3576. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3577. }
  3578. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3579. }
  3580. catch (Exception)
  3581. {
  3582. timer_1s.Enabled = false;
  3583. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3584. timer_1s.Enabled = true;
  3585. }
  3586. }
  3587. /// <summary>
  3588. /// 查询存储标志
  3589. /// </summary>
  3590. /// <param name="sender"></param>
  3591. /// <param name="e"></param>
  3592. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3593. {
  3594. radioButton_EE_SaveYes.Checked = false;
  3595. radioButton_EE_SaveNo.Checked = false;
  3596. radioButton_SIP_SaveYes.Checked = false;
  3597. radioButton_SIP_SaveNo.Checked = false;
  3598. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3599. }
  3600. /// <summary>
  3601. /// 写入存储标志
  3602. /// </summary>
  3603. /// <param name="sender"></param>
  3604. /// <param name="e"></param>
  3605. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3606. {
  3607. var SaveFlag = new byte[6];
  3608. for (int i = 0; i < 6; i++)
  3609. SaveFlag[i] = 0;
  3610. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3611. {
  3612. timer_1s.Enabled = false;
  3613. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3614. timer_1s.Enabled = true;
  3615. return;
  3616. }
  3617. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3618. {
  3619. timer_1s.Enabled = false;
  3620. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3621. timer_1s.Enabled = true;
  3622. return;
  3623. }
  3624. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3625. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3626. SaveFlag[3] = 0;
  3627. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3628. SaveFlag[5] = 0;
  3629. timer_1s.Enabled = false;
  3630. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3631. {
  3632. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3633. }
  3634. timer_1s.Enabled = true;
  3635. }
  3636. /// <summary>
  3637. /// 读取指定地址数据
  3638. /// </summary>
  3639. /// <param name="sender"></param>
  3640. /// <param name="e"></param>
  3641. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3642. {
  3643. var Address = new byte[4];
  3644. UInt32 Address_Begin;
  3645. UInt32 Addres_End;
  3646. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3647. richTextBox_RamFlasgData.Clear();
  3648. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3649. {
  3650. timer_1s.Enabled = false;
  3651. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3652. timer_1s.Enabled = true;
  3653. return;
  3654. }
  3655. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3656. {
  3657. timer_1s.Enabled = false;
  3658. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3659. timer_1s.Enabled = true;
  3660. return;
  3661. }
  3662. else
  3663. {
  3664. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3665. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3666. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3667. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3668. if (Addres_End < Address_Begin)
  3669. {
  3670. timer_1s.Enabled = false;
  3671. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3672. timer_1s.Enabled = true;
  3673. return;
  3674. }
  3675. else
  3676. {
  3677. var SendByte = new byte[8];
  3678. SendByte[0] = (byte)(Address_Begin >> 24);
  3679. SendByte[1] = (byte)(Address_Begin >> 16);
  3680. SendByte[2] = (byte)(Address_Begin >> 8);
  3681. SendByte[3] = (byte)(Address_Begin);
  3682. SendByte[4] = (byte)(Addres_End >> 24);
  3683. SendByte[5] = (byte)(Addres_End >> 16);
  3684. SendByte[6] = (byte)(Addres_End >> 8);
  3685. SendByte[7] = (byte)(Addres_End);
  3686. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3687. }
  3688. }
  3689. }
  3690. /// <summary>
  3691. /// 工作模式选择
  3692. /// </summary>
  3693. /// <param name="sender"></param>
  3694. /// <param name="e"></param>
  3695. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3696. {
  3697. var RunMode = new byte[1];
  3698. if (comboBox_WorkMode.Text == "配置模式")
  3699. RunMode[0] = 0x01;
  3700. else if (comboBox_WorkMode.Text == "调试模式")
  3701. RunMode[0] = 0x02;
  3702. else
  3703. RunMode[0] = 0x00;
  3704. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3705. }
  3706. /// <summary>
  3707. /// 助力档位选择
  3708. /// </summary>
  3709. /// <param name="sender"></param>
  3710. /// <param name="e"></param>
  3711. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3712. {
  3713. var CtrlCode = new byte[2];
  3714. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3715. CtrlCode[0] = 0x33;
  3716. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3717. CtrlCode[0] = 0x22;
  3718. else
  3719. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3720. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3721. CtrlCode[1] = 0xF1;
  3722. else
  3723. CtrlCode[1] = 0xF0;
  3724. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3725. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3726. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3727. }
  3728. /// <summary>
  3729. /// 仪表档位选择
  3730. /// </summary>
  3731. /// <param name="sender"></param>
  3732. /// <param name="e"></param>
  3733. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3734. {
  3735. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3736. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3737. }
  3738. /// <summary>
  3739. /// 生产模式初始化
  3740. /// </summary>
  3741. /// <param name="sender"></param>
  3742. /// <param name="e"></param>
  3743. private void button_FacModeInit_Click(object sender, EventArgs e)
  3744. {
  3745. var Code = new byte[5];
  3746. Code[0] = (byte)'C';
  3747. Code[1] = (byte)'L';
  3748. Code[2] = (byte)'E';
  3749. Code[3] = (byte)'A';
  3750. Code[4] = (byte)'R';
  3751. timer_1s.Enabled = false;
  3752. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3753. {
  3754. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3755. {
  3756. timer_1s.Enabled = true;
  3757. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3758. PowerOffAckStatus = false;
  3759. Delay_ms(250);
  3760. int TryCnt = 3;
  3761. while ((TryCnt--) >= 0)
  3762. {
  3763. if (!PowerOffAckStatus)
  3764. {
  3765. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3766. PowerOffAckStatus = false;
  3767. Delay_ms(250);
  3768. }
  3769. else break;
  3770. }
  3771. if (PowerOffAckStatus)
  3772. {
  3773. timer_1s.Enabled = false;
  3774. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3775. timer_1s.Enabled = true;
  3776. }
  3777. else
  3778. {
  3779. timer_1s.Enabled = false;
  3780. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3781. timer_1s.Enabled = true;
  3782. }
  3783. timer_1s.Enabled = true;
  3784. }
  3785. }
  3786. timer_1s.Enabled = true;
  3787. //清除历史测试记录
  3788. textBox_FacModeSensorADC0.Text = "";
  3789. textBox_FacModeSensorADC1.Text = "";
  3790. textBox_FacModeSensorADC2.Text = "";
  3791. textBox_FacModeSensorADC3.Text = "";
  3792. textBox_FacModeSensorADC4.Text = "";
  3793. LightSwitchStatus = false;
  3794. MotorRunStatus = false;
  3795. trackBar_FacModeMotorSpeedAdj.Value = 5;
  3796. textBox_FacModeName.Text = "";
  3797. textBox_FacModeNum.Text = "";
  3798. textBox_FacModeHW.Text = "";
  3799. textBox_FacModeFW.Text = "";
  3800. }
  3801. /// <summary>
  3802. /// 生产模式读取传感器参数
  3803. /// </summary>
  3804. /// <param name="sender"></param>
  3805. /// <param name="e"></param>
  3806. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3807. {
  3808. richTextBox_SensorParam.Clear();
  3809. textBox_FacModeSensorADC0.Text = "";
  3810. textBox_FacModeSensorADC1.Text = "";
  3811. textBox_FacModeSensorADC2.Text = "";
  3812. textBox_FacModeSensorADC3.Text = "";
  3813. textBox_FacModeSensorADC4.Text = "";
  3814. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3815. }
  3816. /// <summary>
  3817. /// 生产模式传感器标定1
  3818. /// </summary>
  3819. /// <param name="sender"></param>
  3820. /// <param name="e"></param>
  3821. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  3822. {
  3823. var ConfigParam = new byte[4];
  3824. for (int i = 0; i < 4; i++)
  3825. ConfigParam[i] = 0;
  3826. ushort uwDataTemp = 0;
  3827. try
  3828. {
  3829. uwDataTemp = 1;//负载序号
  3830. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3831. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3832. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  3833. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3834. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3835. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3836. Delay_ms(200);
  3837. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3838. }
  3839. catch (Exception)
  3840. {
  3841. timer_1s.Enabled = false;
  3842. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3843. timer_1s.Enabled = true;
  3844. }
  3845. }
  3846. /// <summary>
  3847. /// 生产模式传感器标定2
  3848. /// </summary>
  3849. /// <param name="sender"></param>
  3850. /// <param name="e"></param>
  3851. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  3852. {
  3853. var ConfigParam = new byte[4];
  3854. for (int i = 0; i < 4; i++)
  3855. ConfigParam[i] = 0;
  3856. ushort uwDataTemp = 0;
  3857. try
  3858. {
  3859. uwDataTemp = 2;//负载序号
  3860. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3861. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3862. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  3863. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3864. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3865. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3866. Delay_ms(200);
  3867. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3868. }
  3869. catch (Exception)
  3870. {
  3871. timer_1s.Enabled = false;
  3872. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3873. timer_1s.Enabled = true;
  3874. }
  3875. }
  3876. /// <summary>
  3877. /// 生产模式传感器标定3
  3878. /// </summary>
  3879. /// <param name="sender"></param>
  3880. /// <param name="e"></param>
  3881. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  3882. {
  3883. var ConfigParam = new byte[4];
  3884. for (int i = 0; i < 4; i++)
  3885. ConfigParam[i] = 0;
  3886. ushort uwDataTemp = 0;
  3887. try
  3888. {
  3889. uwDataTemp = 3;//负载序号
  3890. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3891. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3892. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  3893. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3894. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3895. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3896. Delay_ms(200);
  3897. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3898. }
  3899. catch (Exception)
  3900. {
  3901. timer_1s.Enabled = false;
  3902. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3903. timer_1s.Enabled = true;
  3904. }
  3905. }
  3906. /// <summary>
  3907. /// 生产模式传感器标定3
  3908. /// </summary>
  3909. /// <param name="sender"></param>
  3910. /// <param name="e"></param>
  3911. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  3912. {
  3913. var ConfigParam = new byte[4];
  3914. for (int i = 0; i < 4; i++)
  3915. ConfigParam[i] = 0;
  3916. ushort uwDataTemp = 0;
  3917. try
  3918. {
  3919. uwDataTemp = 4;//负载序号
  3920. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3921. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3922. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  3923. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3924. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3925. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3926. Delay_ms(200);
  3927. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3928. }
  3929. catch (Exception)
  3930. {
  3931. timer_1s.Enabled = false;
  3932. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3933. timer_1s.Enabled = true;
  3934. }
  3935. }
  3936. /// <summary>
  3937. /// 生产模式开关灯
  3938. /// </summary>
  3939. /// <param name="sender"></param>
  3940. /// <param name="e"></param>
  3941. bool LightSwitchStatus = false;
  3942. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  3943. {
  3944. var CtrlCode = new byte[2];
  3945. CtrlCode[0] = 0x00;
  3946. if (LightSwitchStatus)
  3947. {
  3948. CtrlCode[1] = 0xF0;
  3949. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  3950. }
  3951. else
  3952. {
  3953. CtrlCode[1] = 0xF1;
  3954. button_FacModeLightSW.BackColor = Color.Yellow;
  3955. }
  3956. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  3957. {
  3958. LightSwitchStatus = !LightSwitchStatus;
  3959. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3960. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3961. }
  3962. }
  3963. /// <summary>
  3964. /// 生产模式电机控制
  3965. /// </summary>
  3966. /// <param name="sender"></param>
  3967. /// <param name="e"></param>
  3968. bool MotorRunStatus = false;
  3969. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  3970. {
  3971. string DebugDefaultInfo = "";
  3972. //获取调试信息
  3973. if (richTextBox_DebugParam.Text == string.Empty)
  3974. {
  3975. richTextBox_DebugParam.Clear();
  3976. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  3977. }
  3978. Delay_ms(200);
  3979. DebugDefaultInfo = richTextBox_DebugParam.Text;
  3980. //获取参数
  3981. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  3982. if (strDataTemp.Length != 29)
  3983. {
  3984. timer_1s.Enabled = false;
  3985. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3986. timer_1s.Enabled = true;
  3987. return;
  3988. }
  3989. //设置参数
  3990. var ConfigParam = new byte[60];
  3991. for (int i = 0; i < 60; i++)
  3992. ConfigParam[i] = 0;
  3993. ConfigParam[0] = 0x00;
  3994. ushort uwDataTemp = 0;
  3995. if (!MotorRunStatus) //停止状态
  3996. {
  3997. //设置速度环
  3998. strDataTemp[0] = "整体运行模式=3";
  3999. //发送数据
  4000. try
  4001. {
  4002. for (int i = 0; i < strDataTemp.Length; i++)
  4003. {
  4004. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4005. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4006. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4007. }
  4008. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4009. return;
  4010. }
  4011. catch (Exception)
  4012. {
  4013. timer_1s.Enabled = false;
  4014. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4015. timer_1s.Enabled = true;
  4016. }
  4017. Delay_ms(200);
  4018. //设置转速百分比100%
  4019. trackBar_FacModeMotorSpeedAdj.Value = 100;
  4020. MotorRunStatus = !MotorRunStatus;
  4021. button_FacModeMotorRun.BackColor = Color.Yellow;
  4022. Delay_ms(200);
  4023. //电机进入配置模式
  4024. var RunMode = new byte[1];
  4025. RunMode[0] = 0x01;
  4026. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4027. }
  4028. else //运转状态
  4029. {
  4030. //设置转速百分比0%
  4031. trackBar_FacModeMotorSpeedAdj.Value = 0;
  4032. MotorRunStatus = !MotorRunStatus;
  4033. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4034. Delay_ms(200);
  4035. //还原为原始值
  4036. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4037. try
  4038. {
  4039. for (int i = 0; i < strDataTemp.Length; i++)
  4040. {
  4041. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4042. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4043. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4044. }
  4045. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4046. return;
  4047. }
  4048. catch (Exception)
  4049. {
  4050. timer_1s.Enabled = false;
  4051. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4052. timer_1s.Enabled = true;
  4053. }
  4054. Delay_ms(200);
  4055. //电机退出配置模式
  4056. var RunMode = new byte[1];
  4057. RunMode[0] = 0x00;
  4058. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4059. }
  4060. }
  4061. /// <summary>
  4062. /// 生产模式转速调节
  4063. /// </summary>
  4064. /// <param name="sender"></param>
  4065. /// <param name="e"></param>
  4066. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  4067. {
  4068. //转速百分比更新
  4069. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  4070. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  4071. }
  4072. /// <summary>
  4073. /// 生产模式写入型号
  4074. /// </summary>
  4075. /// <param name="sender"></param>
  4076. /// <param name="e"></param>
  4077. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4078. {
  4079. string Mode = textBox_FacModeName.Text;
  4080. var ModeArray = new byte[16];
  4081. for (ushort i = 0; i < Mode.Length; i++)
  4082. {
  4083. ModeArray[i] = (byte)Mode[i];
  4084. }
  4085. if (Mode.Length < 16)
  4086. {
  4087. ModeArray[Mode.Length] = (byte)'.';
  4088. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4089. {
  4090. ModeArray[Mode.Length + 1 + i] = 0x20;
  4091. }
  4092. }
  4093. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4094. }
  4095. /// <summary>
  4096. /// 生产模式写入SN
  4097. /// </summary>
  4098. /// <param name="sender"></param>
  4099. /// <param name="e"></param>
  4100. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4101. {
  4102. string SN = textBox_FacModeNum.Text;
  4103. var SNArray = new byte[16];
  4104. for (ushort i = 0; i < SN.Length; i++)
  4105. {
  4106. SNArray[i] = (byte)SN[i];
  4107. }
  4108. if (SN.Length < 16)
  4109. {
  4110. SNArray[SN.Length] = (byte)'.';
  4111. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4112. {
  4113. SNArray[SN.Length + 1 + i] = 0x20;
  4114. }
  4115. }
  4116. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4117. }
  4118. /// <summary>
  4119. /// 生产模式读取版本信息
  4120. /// </summary>
  4121. /// <param name="sender"></param>
  4122. /// <param name="e"></param>
  4123. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4124. {
  4125. textBox_Model.Text = "---";
  4126. textBox_SN.Text = "---";
  4127. textBox_HW.Text = "---";
  4128. textBox_FW.Text = "---";
  4129. textBox_SP.Text = "---";
  4130. textBox_OBC_ReadModel.Text = "---";
  4131. textBox_OBC_ReadSN.Text = "---";
  4132. textBox_OBC_ReadHW.Text = "---";
  4133. textBox_OBC_ReadFW.Text = "---";
  4134. textBox_OBC_ReadSP.Text = "---";
  4135. textBox_FacModeName.Text = "---";
  4136. textBox_FacModeNum.Text = "---";
  4137. textBox_FacModeHW.Text = "---";
  4138. textBox_FacModeFW.Text = "---";
  4139. textBox_FacModeSP.Text = "---";
  4140. textBox_FacModeGit.Text = "---";
  4141. Class_Motor_Ver.Mode = "---";
  4142. Class_Motor_Ver.SN = "---";
  4143. Class_Motor_Ver.HW = "---";
  4144. Class_Motor_Ver.FW = "---";
  4145. Class_Motor_Ver.Special = "---";
  4146. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4147. }
  4148. /// <summary>
  4149. /// 生产模式写入生产信息
  4150. /// </summary>
  4151. /// <param name="sender"></param>
  4152. /// <param name="e"></param>
  4153. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4154. {
  4155. var MACArray = new byte[32];
  4156. string MacDefaultInfo = "";
  4157. string MacAddDefaultInfo = "";
  4158. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4159. string MacPPDefaultInfo = "";
  4160. do
  4161. {
  4162. //填入生产商
  4163. if (toolStripTextBox_MAC.Text == string.Empty)
  4164. {
  4165. break;
  4166. }
  4167. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4168. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4169. {
  4170. MACArray[i] = (byte)MacDefaultInfo[i];
  4171. }
  4172. if (MacDefaultInfo.Length < 8)
  4173. {
  4174. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4175. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4176. {
  4177. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4178. }
  4179. }
  4180. //填入生产地
  4181. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4182. {
  4183. break;
  4184. }
  4185. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4186. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4187. {
  4188. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4189. }
  4190. if (MacAddDefaultInfo.Length < 8)
  4191. {
  4192. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4193. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4194. {
  4195. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4196. }
  4197. }
  4198. //填入生产日期
  4199. if (toolStripTextBox_MACDate.Text == string.Empty)
  4200. {
  4201. break;
  4202. }
  4203. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4204. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4205. {
  4206. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4207. }
  4208. if (MacDateDefaultInfo.Length < 8)
  4209. {
  4210. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4211. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4212. {
  4213. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4214. }
  4215. }
  4216. //填入产品标识
  4217. if (toolStripTextBox_MACPD.Text == string.Empty)
  4218. {
  4219. break;
  4220. }
  4221. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4222. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4223. {
  4224. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4225. }
  4226. if (MacPPDefaultInfo.Length < 8)
  4227. {
  4228. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4229. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4230. {
  4231. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4232. }
  4233. }
  4234. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4235. return;
  4236. } while (false);
  4237. timer_1s.Enabled = false;
  4238. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4239. timer_1s.Enabled = true;
  4240. }
  4241. /// <summary>
  4242. /// 生产模式保存测试页面
  4243. /// </summary>
  4244. /// <param name="sender"></param>
  4245. /// <param name="e"></param>
  4246. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4247. {
  4248. Button_FacModeSaveResult.Text = "存储中…";
  4249. string[] AssistParams = new string[15];
  4250. do
  4251. {
  4252. //读取一次马达参数
  4253. richTextBox_MotorParam.Clear();
  4254. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4255. Delay_ms(100);
  4256. //读取一次整车参数
  4257. richTextBox_BikeParam.Clear();
  4258. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4259. Delay_ms(100);
  4260. //读取一次控制参数
  4261. richTextBox_ControlParam.Clear();
  4262. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4263. Delay_ms(100);
  4264. //查询传感器
  4265. richTextBox_SensorParam.Clear();
  4266. textBox_FacModeSensorADC0.Text = "";
  4267. textBox_FacModeSensorADC1.Text = "";
  4268. textBox_FacModeSensorADC2.Text = "";
  4269. textBox_FacModeSensorADC3.Text = "";
  4270. textBox_FacModeSensorADC4.Text = "";
  4271. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4272. Delay_ms(100);
  4273. //读取15次助力参数
  4274. for (int i = 1; i <= 15; i++)
  4275. {
  4276. var ConfigParam = new byte[4];
  4277. richTextBox_AssistParam.Clear();
  4278. ConfigParam[0] = (byte)(i & 0xFF);
  4279. ConfigParam[1] = (byte)(i >> 8);
  4280. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4281. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4282. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4283. Delay_ms(200);
  4284. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4285. }
  4286. //读取一次调试信息
  4287. richTextBox_DebugParam.Clear();
  4288. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4289. Delay_ms(100);
  4290. //读取一次历史信息
  4291. richTextBox_Record.Clear();
  4292. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4293. Delay_ms(100);
  4294. //读取一次电机运行信息
  4295. var CtrlCode = new byte[2];
  4296. CtrlCode[0] = 0x00;
  4297. CtrlCode[1] = 0xF0;
  4298. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4299. Delay_ms(100);
  4300. //读取一次版本信息
  4301. textBox_Model.Text = "---";
  4302. textBox_SN.Text = "---";
  4303. textBox_HW.Text = "---";
  4304. textBox_FW.Text = "---";
  4305. textBox_OBC_ReadModel.Text = "---";
  4306. textBox_OBC_ReadSN.Text = "---";
  4307. textBox_OBC_ReadHW.Text = "---";
  4308. textBox_OBC_ReadFW.Text = "---";
  4309. textBox_FacModeName.Text = "---";
  4310. textBox_FacModeNum.Text = "---";
  4311. textBox_FacModeHW.Text = "---";
  4312. textBox_FacModeFW.Text = "---";
  4313. Class_Motor_Ver.Mode = "---";
  4314. Class_Motor_Ver.SN = "---";
  4315. Class_Motor_Ver.HW = "---";
  4316. Class_Motor_Ver.FW = "---";
  4317. Class_Motor_Ver.Special = "---";
  4318. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4319. Delay_ms(100);
  4320. //读取一次生产信息
  4321. textBox_MAC.Text = "";
  4322. textBox_MACAdd.Text = "";
  4323. textBox_MACDate.Text = "";
  4324. textBox_PP.Text = "";
  4325. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4326. Delay_ms(100);
  4327. //读取一次自定义信息
  4328. textBox_User1.Text = "---";
  4329. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4330. Delay_ms(100);
  4331. textBox_User2.Text = "---";
  4332. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4333. Delay_ms(100);
  4334. textBox_User3.Text = "---";
  4335. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4336. Delay_ms(100);
  4337. //读取一次密钥
  4338. textBox_Key.Text = "---";
  4339. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4340. Delay_ms(100);
  4341. //读取一次存储标志
  4342. radioButton_EE_SaveYes.Checked = false;
  4343. radioButton_EE_SaveNo.Checked = false;
  4344. radioButton_SIP_SaveYes.Checked = false;
  4345. radioButton_SIP_SaveNo.Checked = false;
  4346. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4347. Delay_ms(100);
  4348. //读取一次MOS内阻校准参数
  4349. foreach (Control c in groupBox21.Controls)
  4350. {
  4351. if (c is TextBox)
  4352. c.Text = "";
  4353. }
  4354. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4355. Delay_ms(100);
  4356. //提示检查
  4357. #if false
  4358. timer_1s.Enabled = false;
  4359. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4360. {
  4361. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4362. timer_1s.Enabled = true;
  4363. return;
  4364. }
  4365. timer_1s.Enabled = true;
  4366. Delay_ms(200);
  4367. #endif
  4368. //判断数据是否有效
  4369. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4370. {
  4371. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4372. break;
  4373. }
  4374. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4375. {
  4376. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4377. break;
  4378. }
  4379. //设置文件存储路径
  4380. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4381. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4382. Save_Path += PD_PathName;
  4383. if (!Directory.Exists(Save_Path))
  4384. Directory.CreateDirectory(Save_Path);
  4385. //保存页面
  4386. string PIC_SaveFileName = "";
  4387. Double scaleX = PrimaryScreen.ScaleX;
  4388. Double scaleY = PrimaryScreen.ScaleY;
  4389. //保存页面
  4390. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4391. Graphics g = Graphics.FromImage(bit);
  4392. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4393. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4394. bit.Save(PIC_SaveFileName);
  4395. //保存数据
  4396. string DataFileName = "";
  4397. string FileInfo = "";
  4398. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4399. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4400. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4401. FileInfo += "\r\n";
  4402. FileInfo += "[电机信息]\r\n";
  4403. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4404. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4405. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4406. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4407. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4408. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4409. FileInfo += "\r\n";
  4410. FileInfo += "[马达参数]\r\n";
  4411. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4412. FileInfo += "\r\n";
  4413. FileInfo += "[整车参数]\r\n";
  4414. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4415. FileInfo += "\r\n";
  4416. FileInfo += "[控制参数]\r\n";
  4417. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4418. FileInfo += "\r\n";
  4419. FileInfo += "[传感器参数]\r\n";
  4420. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4421. FileInfo += "\r\n";
  4422. FileInfo += "[助力参数]\r\n";
  4423. for(int i=0;i<15;i++)
  4424. {
  4425. FileInfo += AssistParams[i] + "\r\n";
  4426. }
  4427. FileInfo += "[调试参数]\r\n";
  4428. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4429. FileInfo += "\r\n";
  4430. FileInfo += "[历史信息]\r\n";
  4431. FileInfo += richTextBox_Record.Text + "\r\n";
  4432. FileInfo += "\r\n";
  4433. FileInfo += "[MOS内阻校准参数]\r\n";
  4434. FileInfo += textBox_MOS_K1.Text + ", ";
  4435. FileInfo += textBox_MOS_K2.Text + ", ";
  4436. FileInfo += textBox_MOS_K3.Text + ", ";
  4437. FileInfo += textBox_MOS_K4.Text + ", ";
  4438. FileInfo += textBox_MOS_K5.Text + ", ";
  4439. FileInfo += textBox_MOS_R1.Text + ", ";
  4440. FileInfo += textBox_MOS_R2.Text + ", ";
  4441. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4442. FileInfo += "\r\n";
  4443. FileInfo += "[生产信息]\r\n";
  4444. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4445. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4446. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4447. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4448. FileInfo += "\r\n";
  4449. FileInfo += "[自定义信息]\r\n";
  4450. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4451. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4452. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4453. FileInfo += "\r\n";
  4454. FileInfo += "[校验密钥]\r\n";
  4455. FileInfo += textBox_Key.Text + "\r\n";
  4456. FileInfo += "\r\n";
  4457. FileInfo += "[存储标志]\r\n";
  4458. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4459. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4460. FileInfo += "\r\n";
  4461. FileInfo += Local_HdInformation;
  4462. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4463. Delay_ms(1000);
  4464. timer_1s.Enabled = false;
  4465. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4466. timer_1s.Enabled = true;
  4467. //数据上传
  4468. if (myFtp.IsNetConnected == true)
  4469. {
  4470. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4471. //检查路径
  4472. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4473. {
  4474. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4475. }
  4476. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4477. {
  4478. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4479. }
  4480. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4481. {
  4482. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4483. }
  4484. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4485. {
  4486. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4487. }
  4488. //上传文件
  4489. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4490. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4491. if ((result1 & result2) == true)
  4492. {
  4493. timer_1s.Enabled = false;
  4494. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4495. timer_1s.Enabled = true;
  4496. }
  4497. else
  4498. {
  4499. timer_1s.Enabled = false;
  4500. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4501. timer_1s.Enabled = true;
  4502. }
  4503. }
  4504. else
  4505. {
  4506. timer_1s.Enabled = false;
  4507. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4508. timer_1s.Enabled = true;
  4509. }
  4510. Button_FacModeSaveResult.Text = "保存数据";
  4511. return;
  4512. } while (false);
  4513. timer_1s.Enabled = false;
  4514. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4515. timer_1s.Enabled = true;
  4516. Button_FacModeSaveResult.Text = "保存数据";
  4517. }
  4518. /// <summary>
  4519. /// 工具箱页面保存
  4520. /// </summary>
  4521. /// <param name="sender"></param>
  4522. /// <param name="e"></param>
  4523. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4524. {
  4525. Double scaleX = PrimaryScreen.ScaleX;
  4526. Double scaleY = PrimaryScreen.ScaleY;
  4527. //保存页面
  4528. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4529. Graphics g = Graphics.FromImage(bit);
  4530. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4531. SaveFileDialog sf = new SaveFileDialog();
  4532. sf.Title = "页面保存";
  4533. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4534. sf.Filter = "图片|*.png";
  4535. timer_1s.Enabled = false;
  4536. if (sf.ShowDialog() == DialogResult.OK)
  4537. {
  4538. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4539. }
  4540. timer_1s.Enabled = true;
  4541. }
  4542. /// <summary>
  4543. /// 生产模式关机
  4544. /// </summary>
  4545. /// <param name="sender"></param>
  4546. /// <param name="e"></param>
  4547. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4548. {
  4549. var Code_Off = new byte[5];
  4550. var Code_Reset = new byte[5];
  4551. Code_Off[0] = (byte)'O';
  4552. Code_Off[1] = (byte)'F';
  4553. Code_Off[2] = (byte)'F';
  4554. Code_Off[3] = (byte)'.';
  4555. Code_Off[4] = (byte)'.';
  4556. Code_Reset[0] = (byte)'R';
  4557. Code_Reset[1] = (byte)'E';
  4558. Code_Reset[2] = (byte)'S';
  4559. Code_Reset[3] = (byte)'E';
  4560. Code_Reset[4] = (byte)'T';
  4561. timer_1s.Enabled = false;
  4562. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4563. {
  4564. timer_1s.Enabled = true;
  4565. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4566. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4567. PowerOffAckStatus = false;
  4568. Delay_ms(250);
  4569. int TryCnt = 3;
  4570. while ((TryCnt--) >= 0)
  4571. {
  4572. if (!PowerOffAckStatus)
  4573. {
  4574. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4575. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4576. PowerOffAckStatus = false;
  4577. Delay_ms(250);
  4578. }
  4579. else break;
  4580. }
  4581. if (PowerOffAckStatus)
  4582. {
  4583. timer_1s.Enabled = false;
  4584. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4585. timer_1s.Enabled = true;
  4586. }
  4587. else
  4588. {
  4589. timer_1s.Enabled = false;
  4590. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4591. timer_1s.Enabled = true;
  4592. }
  4593. }
  4594. timer_1s.Enabled = true;
  4595. }
  4596. //仪表电源键按下
  4597. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4598. {
  4599. var Code = new byte[2];
  4600. Code[0] = 0;
  4601. Code[1] = 0b00100000;
  4602. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4603. }
  4604. /// <summary>
  4605. /// 仪表加键按下
  4606. /// </summary>
  4607. /// <param name="sender"></param>
  4608. /// <param name="e"></param>
  4609. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4610. {
  4611. var Code = new byte[2];
  4612. Code[0] = 0;
  4613. Code[1] = 0b00010000;
  4614. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4615. }
  4616. /// <summary>
  4617. /// 仪表减键按下
  4618. /// </summary>
  4619. /// <param name="sender"></param>
  4620. /// <param name="e"></param>
  4621. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4622. {
  4623. var Code = new byte[2];
  4624. Code[0] = 0;
  4625. Code[1] = 0b00001000;
  4626. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4627. }
  4628. /// <summary>
  4629. /// 仪表Walk键按下
  4630. /// </summary>
  4631. /// <param name="sender"></param>
  4632. /// <param name="e"></param>
  4633. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4634. {
  4635. var Code = new byte[2];
  4636. Code[0] = 0;
  4637. Code[1] = 0b00000100;
  4638. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4639. }
  4640. /// <summary>
  4641. /// 仪表Light键按下
  4642. /// </summary>
  4643. /// <param name="sender"></param>
  4644. /// <param name="e"></param>
  4645. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4646. {
  4647. var Code = new byte[2];
  4648. Code[0] = 0;
  4649. Code[1] = 0b00000010;
  4650. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4651. }
  4652. /// <summary>
  4653. /// 仪表Set键按下
  4654. /// </summary>
  4655. /// <param name="sender"></param>
  4656. /// <param name="e"></param>
  4657. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4658. {
  4659. var Code = new byte[2];
  4660. Code[0] = 0;
  4661. Code[1] = 0b00000001;
  4662. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4663. }
  4664. /// <summary>
  4665. /// 导出电机故障日志
  4666. /// </summary>
  4667. /// <param name="sender"></param>
  4668. /// <param name="e"></param>
  4669. private void button_ExportLog_Click(object sender, EventArgs e)
  4670. {
  4671. var Address = new byte[4];
  4672. UInt32 Address_Begin;
  4673. UInt32 Addres_End;
  4674. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4675. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4676. richTextBox_Record.Clear();
  4677. textBox_LogAddrBegin.ReadOnly = true;
  4678. textBox_LogAddrEnd.ReadOnly = true;
  4679. if (!mySerialProcess.mySerial.IsOpen)
  4680. {
  4681. timer_1s.Enabled = false;
  4682. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4683. timer_1s.Enabled = true;
  4684. return;
  4685. }
  4686. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4687. {
  4688. timer_1s.Enabled = false;
  4689. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4690. timer_1s.Enabled = true;
  4691. return;
  4692. }
  4693. else
  4694. {
  4695. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4696. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4697. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4698. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4699. if (Addres_End <= Address_Begin)
  4700. {
  4701. timer_1s.Enabled = false;
  4702. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4703. timer_1s.Enabled = true;
  4704. return;
  4705. }
  4706. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4707. {
  4708. timer_1s.Enabled = false;
  4709. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4710. timer_1s.Enabled = true;
  4711. return;
  4712. }
  4713. else
  4714. {
  4715. UInt32 ReadCount = 0;
  4716. button_ExportLog.Text = "导出中...";
  4717. button_ExportLog.Enabled = false;
  4718. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4719. for (ushort i = 0; i < ReadCount; i++)
  4720. {
  4721. var SendByte = new byte[8];
  4722. UInt32 Address_Temp_Begin;
  4723. UInt32 Address_Temp_End;
  4724. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4725. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4726. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4727. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4728. SendByte[3] = (byte)(Address_Temp_Begin);
  4729. Address_Temp_End = Address_Temp_Begin + 127;
  4730. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4731. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4732. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4733. SendByte[7] = (byte)(Address_Temp_End);
  4734. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4735. Delay_ms(200);//Thread.Sleep(200);
  4736. }
  4737. button_ExportLog.Text = "导出日志";
  4738. button_ExportLog.Enabled = true;
  4739. }
  4740. }
  4741. }
  4742. /// <summary>
  4743. /// 保存日志信息
  4744. /// </summary>
  4745. /// <param name="sender"></param>
  4746. /// <param name="e"></param>
  4747. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4748. {
  4749. string SaveInfo = "";
  4750. if (richTextBox_Record.Text == string.Empty)
  4751. {
  4752. timer_1s.Enabled = false;
  4753. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4754. timer_1s.Enabled = true;
  4755. return;
  4756. }
  4757. //获取保存信息
  4758. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4759. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4760. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4761. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4762. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4763. SaveInfo += "\r\n";
  4764. SaveInfo += richTextBox_Record.Text;
  4765. //设置保存路径和文件名
  4766. SaveFileDialog sf = new SaveFileDialog();
  4767. sf.Title = "数据保存";
  4768. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4769. sf.FileName.Replace(" ", "");
  4770. sf.Filter = "日志|*.ttlog";
  4771. if (sf.ShowDialog() == DialogResult.OK)
  4772. {
  4773. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4774. }
  4775. }
  4776. /// <summary>
  4777. /// 双击修改日志起始地址
  4778. /// </summary>
  4779. /// <param name="sender"></param>
  4780. /// <param name="e"></param>
  4781. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4782. {
  4783. textBox_LogAddrBegin.ReadOnly = false;
  4784. }
  4785. /// <summary>
  4786. /// 双击修改日志结束地址
  4787. /// </summary>
  4788. /// <param name="sender"></param>
  4789. /// <param name="e"></param>
  4790. private void label88_DoubleClick(object sender, EventArgs e)
  4791. {
  4792. textBox_LogAddrEnd.ReadOnly = false;
  4793. }
  4794. /// <summary>
  4795. /// 存储器自动读取选择
  4796. /// </summary>
  4797. /// <param name="sender"></param>
  4798. /// <param name="e"></param>
  4799. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4800. {
  4801. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4802. {
  4803. //检查串口是否打开
  4804. if (!mySerialProcess.mySerial.IsOpen)
  4805. {
  4806. timer_1s.Enabled = false;
  4807. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4808. timer_1s.Enabled = true;
  4809. checkBox_ReadRanFlash_AutoSW.Checked = false;
  4810. return;
  4811. }
  4812. }
  4813. }
  4814. /// <summary>
  4815. /// 系统开机按钮
  4816. /// </summary>
  4817. /// <param name="sender"></param>
  4818. /// <param name="e"></param>
  4819. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4820. {
  4821. byte[] Data = new byte[1];
  4822. Data[0] = 0xF1;
  4823. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4824. }
  4825. /// <summary>
  4826. /// 系统关机按钮
  4827. /// </summary>
  4828. /// <param name="sender"></param>
  4829. /// <param name="e"></param>
  4830. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4831. {
  4832. byte[] Data = new byte[1];
  4833. Data[0] = 0xF0;
  4834. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4835. }
  4836. /// <summary>
  4837. /// 连接开机选择
  4838. /// </summary>
  4839. /// <param name="sender"></param>
  4840. /// <param name="e"></param>
  4841. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4842. {
  4843. //输入用户名
  4844. EnterForm1.ShowDialog();
  4845. try
  4846. {
  4847. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4848. {
  4849. if (EnterForm1.comboBox_User.Text == "管理员")
  4850. {
  4851. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  4852. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4853. }
  4854. else
  4855. {
  4856. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4857. }
  4858. }
  4859. else
  4860. {
  4861. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4862. }
  4863. }
  4864. catch (Exception)
  4865. {
  4866. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4867. }
  4868. }
  4869. /// <summary>
  4870. /// 断开关机选择
  4871. /// </summary>
  4872. /// <param name="sender"></param>
  4873. /// <param name="e"></param>
  4874. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4875. {
  4876. //输入用户名
  4877. EnterForm1.ShowDialog();
  4878. try
  4879. {
  4880. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4881. {
  4882. if (EnterForm1.comboBox_User.Text == "管理员")
  4883. {
  4884. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  4885. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4886. }
  4887. else
  4888. {
  4889. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4890. }
  4891. }
  4892. else
  4893. {
  4894. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4895. }
  4896. }
  4897. catch (Exception)
  4898. {
  4899. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4900. }
  4901. }
  4902. /// <summary>
  4903. /// 识别通讯盒选择
  4904. /// </summary>
  4905. /// <param name="sender"></param>
  4906. /// <param name="e"></param>
  4907. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  4908. {
  4909. //输入用户名
  4910. EnterForm1.ShowDialog();
  4911. try
  4912. {
  4913. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4914. {
  4915. if (EnterForm1.comboBox_User.Text == "管理员")
  4916. {
  4917. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  4918. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4919. }
  4920. else
  4921. {
  4922. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4923. }
  4924. }
  4925. else
  4926. {
  4927. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4928. }
  4929. }
  4930. catch (Exception)
  4931. {
  4932. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4933. }
  4934. }
  4935. /// <summary>
  4936. /// 将配置信息导出为cfg文件
  4937. /// </summary>
  4938. private void ConfigFileSave(bool DeleteFlag, string FileName)
  4939. {
  4940. if (DeleteFlag)
  4941. {
  4942. if (File.Exists(FileName))
  4943. File.Delete(FileName);
  4944. }
  4945. string CfgFileInfo = "";
  4946. CfgFileInfo += "[PortSet]" + "\r\n";
  4947. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  4948. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  4949. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4950. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4951. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  4952. CfgFileInfo += "\r\n";
  4953. CfgFileInfo += "[Option]" + "\r\n";
  4954. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  4955. CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
  4956. CfgFileInfo += "\r\n";
  4957. CfgFileInfo += "[ServerSet]" + "\r\n";
  4958. CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
  4959. CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
  4960. CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
  4961. CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
  4962. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  4963. CfgFileInfo += "\r\n";
  4964. CfgFileInfo += "[MacInfo]" + "\r\n";
  4965. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  4966. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  4967. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  4968. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  4969. CfgFileInfo += "\r\n";
  4970. CfgFileInfo += "[LogAddress]" + "\r\n";
  4971. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  4972. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  4973. CfgFileInfo += "\r\n";
  4974. CfgFileInfo += "[MotorType]" + "\r\n";
  4975. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4976. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4977. CfgFileInfo += "\r\n";
  4978. CfgFileInfo += "[CheckValue]" + "\r\n";
  4979. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  4980. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  4981. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  4982. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  4983. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  4984. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  4985. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  4986. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  4987. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  4988. CfgFileInfo += "\r\n";
  4989. CfgFileInfo += "[MosCalK]" + "\r\n";
  4990. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  4991. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  4992. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  4993. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  4994. CfgFileInfo += "\r\n";
  4995. CfgFileInfo += "[ProtocolType]" + "\r\n";
  4996. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  4997. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  4998. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  4999. }
  5000. /// <summary>
  5001. /// 配置状态更新,点击时保存
  5002. /// </summary>
  5003. private void ConfigFileSave_Click(object sender, EventArgs e)
  5004. {
  5005. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5006. }
  5007. /// <summary>
  5008. /// 文本框修改结束,回车保存
  5009. /// </summary>
  5010. /// <param name="sender"></param>
  5011. /// <param name="e"></param>
  5012. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5013. {
  5014. if (e.KeyCode == Keys.Enter)
  5015. {
  5016. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5017. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5018. }
  5019. }
  5020. /// <summary>
  5021. /// 允许离线使用
  5022. /// </summary>
  5023. /// <param name="sender"></param>
  5024. /// <param name="e"></param>
  5025. private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
  5026. {
  5027. //输入用户名
  5028. EnterForm1.ShowDialog();
  5029. try
  5030. {
  5031. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5032. {
  5033. if (EnterForm1.comboBox_User.Text == "管理员")
  5034. {
  5035. 允许ToolStripMenuItem.Checked = true;
  5036. 不允许ToolStripMenuItem.Checked = false;
  5037. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5038. }
  5039. else
  5040. {
  5041. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5042. 允许ToolStripMenuItem.Checked = false;
  5043. 不允许ToolStripMenuItem.Checked = true;
  5044. }
  5045. }
  5046. else
  5047. {
  5048. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5049. 允许ToolStripMenuItem.Checked = false;
  5050. 不允许ToolStripMenuItem.Checked = true;
  5051. }
  5052. }
  5053. catch (Exception)
  5054. {
  5055. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5056. 允许ToolStripMenuItem.Checked = false;
  5057. 不允许ToolStripMenuItem.Checked = true;
  5058. }
  5059. }
  5060. /// <summary>
  5061. /// 不允许离线使用
  5062. /// </summary>
  5063. /// <param name="sender"></param>
  5064. /// <param name="e"></param>
  5065. private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
  5066. {
  5067. 允许ToolStripMenuItem.Checked = false;
  5068. 不允许ToolStripMenuItem.Checked = true;
  5069. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5070. }
  5071. /// <summary>
  5072. /// 弹出扫码按钮
  5073. /// </summary>
  5074. /// <param name="sender"></param>
  5075. /// <param name="e"></param>
  5076. private void button_ScanCode_Click(object sender, EventArgs e)
  5077. {
  5078. Scan scan_form = new Scan();
  5079. scan_form.ShowDialog();
  5080. do
  5081. {
  5082. if (scan_form.textBox_Scan.Text == string.Empty)
  5083. {
  5084. timer_1s.Enabled = false;
  5085. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5086. timer_1s.Enabled = true;
  5087. break;
  5088. }
  5089. string ScanInfo = scan_form.textBox_Scan.Text;
  5090. string regexInfo = "";
  5091. string[] InfoList = { "" };
  5092. try
  5093. {
  5094. if (中置电机ToolStripMenuItem.Checked == true)
  5095. {
  5096. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5097. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5098. }
  5099. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5100. {
  5101. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5102. string Model = InfoList[0];
  5103. string Spec = InfoList[1];
  5104. string Sn = InfoList[2];
  5105. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5106. InfoList[1] = Sn;
  5107. }
  5108. }
  5109. catch (Exception)
  5110. {
  5111. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5112. return;
  5113. }
  5114. if (InfoList.Length >= 2)
  5115. {
  5116. //写入型号
  5117. textBox_FacModeName.Text = InfoList[0];
  5118. string Mode = textBox_FacModeName.Text;
  5119. var ModeArray = new byte[16];
  5120. for (ushort i = 0; i < Mode.Length; i++)
  5121. {
  5122. ModeArray[i] = (byte)Mode[i];
  5123. }
  5124. if (Mode.Length < 16)
  5125. {
  5126. ModeArray[Mode.Length] = (byte)'.';
  5127. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5128. {
  5129. ModeArray[Mode.Length + 1 + i] = 0x20;
  5130. }
  5131. }
  5132. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5133. //写入SN
  5134. textBox_FacModeNum.Text = InfoList[1];
  5135. string SN = textBox_FacModeNum.Text;
  5136. var SNArray = new byte[16];
  5137. for (ushort i = 0; i < SN.Length; i++)
  5138. {
  5139. SNArray[i] = (byte)SN[i];
  5140. }
  5141. if (SN.Length < 16)
  5142. {
  5143. SNArray[SN.Length] = (byte)'.';
  5144. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5145. {
  5146. SNArray[SN.Length + 1 + i] = 0x20;
  5147. }
  5148. }
  5149. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5150. }
  5151. else
  5152. {
  5153. timer_1s.Enabled = false;
  5154. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5155. timer_1s.Enabled = true;
  5156. break;
  5157. }
  5158. } while (false);
  5159. scan_form.Dispose();
  5160. }
  5161. private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
  5162. {
  5163. //输入用户名
  5164. EnterForm1.ShowDialog();
  5165. try
  5166. {
  5167. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5168. {
  5169. if (EnterForm1.comboBox_User.Text == "管理员")
  5170. {
  5171. IP地址ToolStripMenuItem.Visible = true;
  5172. 端口ToolStripMenuItem.Visible = true;
  5173. 用户名ToolStripMenuItem.Visible = true;
  5174. 密码ToolStripMenuItem.Visible = true;
  5175. 存储路径ToolStripMenuItem.Visible = true;
  5176. }
  5177. else
  5178. {
  5179. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5180. IP地址ToolStripMenuItem.Visible = false;
  5181. 端口ToolStripMenuItem.Visible = false;
  5182. 用户名ToolStripMenuItem.Visible = false;
  5183. 密码ToolStripMenuItem.Visible = false;
  5184. 存储路径ToolStripMenuItem.Visible = false;
  5185. }
  5186. }
  5187. else
  5188. {
  5189. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5190. IP地址ToolStripMenuItem.Visible = false;
  5191. 端口ToolStripMenuItem.Visible = false;
  5192. 用户名ToolStripMenuItem.Visible = false;
  5193. 密码ToolStripMenuItem.Visible = false;
  5194. 存储路径ToolStripMenuItem.Visible = false;
  5195. }
  5196. }
  5197. catch (Exception)
  5198. {
  5199. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5200. IP地址ToolStripMenuItem.Visible = false;
  5201. 端口ToolStripMenuItem.Visible = false;
  5202. 用户名ToolStripMenuItem.Visible = false;
  5203. 密码ToolStripMenuItem.Visible = false;
  5204. 存储路径ToolStripMenuItem.Visible = false;
  5205. }
  5206. }
  5207. private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
  5208. {
  5209. //输入用户名
  5210. EnterForm1.ShowDialog();
  5211. try
  5212. {
  5213. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5214. {
  5215. if (EnterForm1.comboBox_User.Text == "管理员")
  5216. {
  5217. 生产商ToolStripMenuItem.Visible = true;
  5218. 生产地ToolStripMenuItem.Visible = true;
  5219. 生产日期ToolStripMenuItem.Visible = true;
  5220. 产品标识ToolStripMenuItem.Visible = true;
  5221. }
  5222. else
  5223. {
  5224. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5225. 生产商ToolStripMenuItem.Visible = false;
  5226. 生产地ToolStripMenuItem.Visible = false;
  5227. 生产日期ToolStripMenuItem.Visible = false;
  5228. 产品标识ToolStripMenuItem.Visible = false;
  5229. }
  5230. }
  5231. else
  5232. {
  5233. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5234. 生产商ToolStripMenuItem.Visible = false;
  5235. 生产地ToolStripMenuItem.Visible = false;
  5236. 生产日期ToolStripMenuItem.Visible = false;
  5237. 产品标识ToolStripMenuItem.Visible = false;
  5238. }
  5239. }
  5240. catch (Exception)
  5241. {
  5242. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5243. 生产商ToolStripMenuItem.Visible = false;
  5244. 生产地ToolStripMenuItem.Visible = false;
  5245. 生产日期ToolStripMenuItem.Visible = false;
  5246. 产品标识ToolStripMenuItem.Visible = false;
  5247. }
  5248. }
  5249. /// <summary>
  5250. /// 切换电机类型
  5251. /// </summary>
  5252. /// <param name="sender"></param>
  5253. /// <param name="e"></param>
  5254. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5255. {
  5256. 中置电机ToolStripMenuItem.Checked = true;
  5257. 轮毂电机ToolStripMenuItem.Checked = false;
  5258. toolStripTextBox_MACPD.Text = "MM_MC1";
  5259. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5260. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5261. }
  5262. /// <summary>
  5263. /// 切换电机类型
  5264. /// </summary>
  5265. /// <param name="sender"></param>
  5266. /// <param name="e"></param>
  5267. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5268. {
  5269. 中置电机ToolStripMenuItem.Checked = false;
  5270. 轮毂电机ToolStripMenuItem.Checked = true;
  5271. toolStripTextBox_MACPD.Text = "GF_250_1";
  5272. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5273. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5274. }
  5275. /// <summary>
  5276. /// 获取配置文件日期
  5277. /// </summary>
  5278. /// <param name="DisAll"></param>
  5279. private void GetDateList(bool DisAll)
  5280. {
  5281. string[] DateList = { "" };
  5282. //从服务器更新日期列表
  5283. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5284. {
  5285. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5286. }
  5287. //从本地更新日期列表
  5288. else
  5289. {
  5290. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5291. }
  5292. comboBox_FacModeCfgDate.Items.Clear();
  5293. comboBox_CheckModeCfgDate.Items.Clear();
  5294. //日期列表加载
  5295. if (DisAll == true)
  5296. {
  5297. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5298. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5299. comboBox_FacModeCfgDate.Items.Add("---");
  5300. comboBox_CheckModeCfgDate.Items.Add("---");
  5301. foreach (var file in DateList)
  5302. {
  5303. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5304. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5305. }
  5306. }
  5307. else
  5308. {
  5309. if (DateList.Length > 10)
  5310. {
  5311. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5312. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5313. comboBox_FacModeCfgDate.Items.Add("---");
  5314. comboBox_CheckModeCfgDate.Items.Add("---");
  5315. }
  5316. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5317. {
  5318. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5319. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5320. }
  5321. }
  5322. }
  5323. /// <summary>
  5324. /// 获取配置文件列表
  5325. /// </summary>
  5326. /// <param name="date"></param>
  5327. private void GetFileListFrom(string date)
  5328. {
  5329. string[] FileList = { "" };
  5330. //从服务器更新文件列表
  5331. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5332. {
  5333. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5334. }
  5335. else
  5336. {
  5337. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5338. }
  5339. comboBox_CheckModeCfgFile.Items.Clear();
  5340. comboBox_FacModeCfgFile.Items.Clear();
  5341. foreach (var file in FileList)
  5342. {
  5343. if (file.Contains(".ttcfg"))
  5344. {
  5345. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5346. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5347. }
  5348. }
  5349. }
  5350. /// <summary>
  5351. /// 检验模式选择文件日期
  5352. /// </summary>
  5353. /// <param name="sender"></param>
  5354. /// <param name="e"></param>
  5355. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5356. {
  5357. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5358. {
  5359. GetDateList(true);
  5360. }
  5361. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5362. {
  5363. GetDateList(false);
  5364. }
  5365. else
  5366. {
  5367. comboBox_CheckModeCfgFile.Text = "";
  5368. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5369. }
  5370. }
  5371. /// <summary>
  5372. /// 配置模式选择文件日期
  5373. /// </summary>
  5374. /// <param name="sender"></param>
  5375. /// <param name="e"></param>
  5376. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5377. {
  5378. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5379. {
  5380. GetDateList(true);
  5381. }
  5382. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5383. {
  5384. GetDateList(false);
  5385. }
  5386. else
  5387. {
  5388. comboBox_FacModeCfgFile.Text = "";
  5389. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5390. }
  5391. }
  5392. /// <summary>
  5393. /// 选中量产模式
  5394. /// </summary>
  5395. /// <param name="sender"></param>
  5396. /// <param name="e"></param>
  5397. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5398. {
  5399. //更新生产配置文件目录
  5400. GetDateList(false);
  5401. }
  5402. /// <summary>
  5403. /// 量产测试结束
  5404. /// </summary>
  5405. /// <param name=""></param>
  5406. private void FacMode_Stop(bool OK_Flag)
  5407. {
  5408. //打开开始按钮
  5409. button__FacMode_Start.Enabled = true;
  5410. //系统关机
  5411. var Code = new byte[32];//发送的指令数据
  5412. Code[0] = 0xF0;
  5413. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5414. //关闭串口
  5415. //mySerialProcess.SerialClose(false);
  5416. //路径设置
  5417. string LocalSavePath = "";
  5418. string ServerSavePath = "";
  5419. if (OK_Flag)
  5420. {
  5421. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5422. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5423. }
  5424. else
  5425. {
  5426. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5427. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5428. }
  5429. if (Directory.Exists(LocalSavePath) == false)
  5430. {
  5431. Directory.CreateDirectory(LocalSavePath);
  5432. }
  5433. //保存和上传
  5434. string LogSavePath = "";
  5435. string LogSaveFileName = "";
  5436. string ProductInfo = textBox_FacModeScan.Text;
  5437. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5438. if (Directory.Exists(LogSavePath) == false)
  5439. {
  5440. Directory.CreateDirectory(LogSavePath);
  5441. }
  5442. //测试页面
  5443. Double scaleX = PrimaryScreen.ScaleX;
  5444. Double scaleY = PrimaryScreen.ScaleY;
  5445. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5446. Graphics g = Graphics.FromImage(bit);
  5447. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5448. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5449. bit.Save(LogSaveFileName);
  5450. //上传测试页面到服务器
  5451. if (myFtp.IsNetConnected == true)
  5452. {
  5453. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5454. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5455. {
  5456. myFtp.MakeDir(ServerSavePath + DateNow);
  5457. }
  5458. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5459. {
  5460. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5461. }
  5462. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5463. if (result == true)
  5464. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5465. }
  5466. else
  5467. {
  5468. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5469. }
  5470. //测试记录
  5471. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5472. string file_str = "";
  5473. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5474. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5475. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5476. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5477. file_str += Local_HdInformation;
  5478. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5479. //上传测试记录到服务器
  5480. if (myFtp.IsNetConnected == true)
  5481. {
  5482. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5483. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5484. {
  5485. myFtp.MakeDir(ServerSavePath + DateNow);
  5486. }
  5487. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5488. {
  5489. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5490. }
  5491. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5492. if (result == true)
  5493. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5494. }
  5495. else
  5496. {
  5497. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5498. }
  5499. //扫码框清空
  5500. textBox_FacModeScan.Text = "";
  5501. }
  5502. /// <summary>
  5503. /// 量产测试开始
  5504. /// </summary>
  5505. /// <param name="sender"></param>
  5506. /// <param name="e"></param>
  5507. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5508. {
  5509. //关闭测试项目编辑
  5510. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5511. foreach (Control c in groupBox2.Controls)
  5512. {
  5513. if (c is CheckBox)
  5514. c.Enabled = false;
  5515. }
  5516. WriteLockStatus = true;
  5517. //检查配置文件
  5518. if (comboBox_FacModeCfgFile.Text == "")
  5519. {
  5520. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5521. return;
  5522. }
  5523. //开始测试
  5524. TestStart();
  5525. }
  5526. /// <summary>
  5527. /// 测试子函数
  5528. /// </summary>
  5529. private void TestStart()
  5530. {
  5531. //初始化标签
  5532. FacModelLabelInit();
  5533. richTextBox_FacModeLog.Clear();
  5534. //按钮禁止操作
  5535. button__FacMode_Start.Enabled = false;
  5536. //记录配置文件
  5537. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5538. //检查打标信息格式
  5539. label_FacModeStatus.Text = "检查扫码信息";
  5540. Delay_ms(500);
  5541. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5542. if (textBox_FacModeScan.Text == string.Empty)
  5543. {
  5544. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5545. button__FacMode_Start.Enabled = true;
  5546. return;
  5547. }
  5548. try
  5549. {
  5550. if (中置电机ToolStripMenuItem.Checked == true)
  5551. {
  5552. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5553. {
  5554. label_FacModeStatus.Text = "存在故障!";
  5555. label_FacModeResult.BackColor = Color.Red;
  5556. label_FacModeResult.Text = "标签格式错误";
  5557. button__FacMode_Start.Enabled = true;
  5558. return;
  5559. }
  5560. }
  5561. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5562. {
  5563. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5564. {
  5565. label_FacModeStatus.Text = "存在故障!";
  5566. label_FacModeResult.BackColor = Color.Red;
  5567. label_FacModeResult.Text = "标签格式错误";
  5568. button__FacMode_Start.Enabled = true;
  5569. return;
  5570. }
  5571. }
  5572. }
  5573. catch (System.Exception)
  5574. {
  5575. label_FacModeStatus.Text = "存在故障!";
  5576. label_FacModeResult.BackColor = Color.Red;
  5577. label_FacModeResult.Text = "标签格式错误";
  5578. button__FacMode_Start.Enabled = true;
  5579. return;
  5580. }
  5581. //打开串口
  5582. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5583. if (!mySerialProcess.mySerial.IsOpen)
  5584. {
  5585. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5586. //按钮禁止操作
  5587. button__FacMode_Start.Enabled = true;
  5588. return;
  5589. }
  5590. //流水号计数
  5591. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5592. serial += 1;
  5593. label_FacModeSerial.Text = serial.ToString();
  5594. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5595. //创建线程,执行测试任务
  5596. Thread th = new Thread(FacModeTest_Task);
  5597. th.Start();
  5598. }
  5599. /// <summary>
  5600. /// 执行一次测试任务
  5601. /// </summary>
  5602. private void FacModeTest_Task()
  5603. {
  5604. //开始测试
  5605. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5606. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5607. //变量定义
  5608. var Code = new byte[255];//发送的指令数据
  5609. label_FacModeStatus.Text = "开始测试";
  5610. Delay_ms(500);
  5611. label_FacModeStatus.Text = "系统开机";
  5612. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5613. if (uARTToolStripMenuItem.Checked)
  5614. {
  5615. Code[0] = (byte)'R';
  5616. Code[1] = (byte)'E';
  5617. Code[2] = (byte)'S';
  5618. Code[3] = (byte)'E';
  5619. Code[4] = (byte)'T';
  5620. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5621. Delay_ms(500);
  5622. }
  5623. //发送开机指令
  5624. BootInfo = "";
  5625. //确保测试前先关机,发送关机指令再发送开机指令
  5626. Code[0] = 0xF0;
  5627. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5628. Delay_ms(1500);
  5629. Code[0] = 0xF1;
  5630. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5631. ACK_WaitCnt = 0;
  5632. while (ACK_WaitCnt <= 10) ; //5s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5633. //检查BOOT版本
  5634. if (BootInfo != string.Empty)
  5635. {
  5636. label_FacModeBootVer.BackColor = Color.Green;
  5637. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5638. Delay_ms(500);
  5639. }
  5640. else
  5641. {
  5642. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5643. label_FacModeStatus.Text = "存在故障!";
  5644. label_FacModeResult.BackColor = Color.Red;
  5645. label_FacModeResult.Text = "测试异常";
  5646. Delay_ms(500);
  5647. //存储异常并上传
  5648. FacMode_Stop(false);
  5649. return;
  5650. }
  5651. //系统清除
  5652. if (checkBox_FacModeSysClear.Checked)
  5653. {
  5654. do
  5655. {
  5656. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5657. {
  5658. Code[0] = 0x00;//5S协议
  5659. Code[1] = 0x00;
  5660. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5661. Delay_ms(500);
  5662. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5663. Delay_ms(500);
  5664. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5665. }
  5666. //发送系统清除指令
  5667. label_FacModeStatus.Text = "系统清除";
  5668. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5669. Code[0] = (byte)'C';
  5670. Code[1] = (byte)'L';
  5671. Code[2] = (byte)'E';
  5672. Code[3] = (byte)'A';
  5673. Code[4] = (byte)'R';
  5674. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5675. WriteACK = false;
  5676. WriteCnt = 0;
  5677. ACK_WaitCnt = 0;
  5678. while (ACK_WaitCnt <= 6); //3s
  5679. //等待系统清除完成指令
  5680. if (WriteACK == true)
  5681. {
  5682. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5683. label_FacModeSysClear.BackColor = Color.Green;
  5684. }
  5685. else
  5686. {
  5687. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5688. label_FacModeStatus.Text = "存在故障!";
  5689. label_FacModeResult.BackColor = Color.Red;
  5690. label_FacModeResult.Text = "测试异常";
  5691. Delay_ms(500);
  5692. //存储异常并上传
  5693. FacMode_Stop(false);
  5694. return;
  5695. }
  5696. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5697. if (uARTToolStripMenuItem.Checked)
  5698. {
  5699. Code[0] = (byte)'R';
  5700. Code[1] = (byte)'E';
  5701. Code[2] = (byte)'S';
  5702. Code[3] = (byte)'E';
  5703. Code[4] = (byte)'T';
  5704. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5705. Delay_ms(500);
  5706. }
  5707. //系统重新开机
  5708. label_FacModeStatus.Text = "重新开机";
  5709. BootInfo = "";
  5710. //确保测试前先关机,发送关机指令再发送开机指令
  5711. BootInfo = "";
  5712. Code[0] = 0xF0;
  5713. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5714. Delay_ms(1500);
  5715. Code[0] = 0xF1;
  5716. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5717. ACK_WaitCnt = 0;
  5718. while (ACK_WaitCnt <= 10); //5s
  5719. //获取Boot版本信息
  5720. if (BootInfo != string.Empty)
  5721. {
  5722. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5723. }
  5724. else
  5725. {
  5726. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5727. label_FacModeStatus.Text = "存在故障!";
  5728. label_FacModeResult.BackColor = Color.Red;
  5729. label_FacModeResult.Text = "测试异常";
  5730. Delay_ms(500);
  5731. //存储异常并上传
  5732. FacMode_Stop(false);
  5733. return;
  5734. }
  5735. } while (false);
  5736. }
  5737. else
  5738. {
  5739. label_FacModeSysClear.BackColor = Color.Yellow;
  5740. label_FacModeStatus.Text = "跳过系统清除!";
  5741. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5742. Delay_ms(500);
  5743. }
  5744. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5745. {
  5746. Code[0] = 0x00;//5S协议
  5747. Code[1] = 0x00;
  5748. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5749. Delay_ms(500);
  5750. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5751. Delay_ms(500);
  5752. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5753. }
  5754. //检查是否有故障
  5755. if (textBox_ErrorCode.Text.Contains("H"))
  5756. {
  5757. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5758. label_FacModeStatus.Text = "电机存在故障!";
  5759. label_FacModeResult.BackColor = Color.Red;
  5760. label_FacModeResult.Text = "测试异常";
  5761. Delay_ms(500);
  5762. //存储异常并上传
  5763. FacMode_Stop(false);
  5764. return;
  5765. }
  5766. //参数写入
  5767. if (checkBox_FacModeCfgWrite.Checked)
  5768. {
  5769. label_FacModeStatus.Text = "参数写入";
  5770. //写入产品型号和SN
  5771. do
  5772. {
  5773. //根据扫码信息获取型号和SN
  5774. string ScanInfo = textBox_FacModeScan.Text;
  5775. string regexInfo = "";
  5776. string[] InfoList = { "" };
  5777. try
  5778. {
  5779. if (中置电机ToolStripMenuItem.Checked == true)
  5780. {
  5781. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5782. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  5783. }
  5784. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5785. {
  5786. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5787. string Model = InfoList[0];
  5788. string Spec = InfoList[1];
  5789. string Sn = InfoList[2];
  5790. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5791. InfoList[1] = Sn;
  5792. }
  5793. }
  5794. catch
  5795. {
  5796. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  5797. label_FacModeStatus.Text = "存在故障!";
  5798. label_FacModeResult.BackColor = Color.Red;
  5799. label_FacModeResult.Text = "标签格式错误";
  5800. Delay_ms(500);
  5801. //存储异常并上传
  5802. FacMode_Stop(false);
  5803. return;
  5804. }
  5805. if (InfoList.Length >= 2)
  5806. {
  5807. //检查配置文件是否与打标信息一致
  5808. //...
  5809. //写入型号
  5810. label_FacModeStatus.Text = "写入型号";
  5811. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  5812. textBox_FacModeName.Text = InfoList[0];
  5813. string Mode = textBox_FacModeName.Text;
  5814. var ModeArray = new byte[16];
  5815. for (ushort i = 0; i < Mode.Length; i++)
  5816. {
  5817. ModeArray[i] = (byte)Mode[i];
  5818. }
  5819. if (Mode.Length < 16)
  5820. {
  5821. ModeArray[Mode.Length] = (byte)'.';
  5822. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5823. {
  5824. ModeArray[Mode.Length + 1 + i] = 0x20;
  5825. }
  5826. }
  5827. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5828. WriteACK = false;
  5829. WriteCnt = 0;
  5830. ACK_WaitCnt = 0;
  5831. while (ACK_WaitCnt <= 2); //1s
  5832. if (WriteACK == true)
  5833. {
  5834. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  5835. }
  5836. else
  5837. {
  5838. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  5839. label_FacModeStatus.Text = "存在故障!";
  5840. label_FacModeResult.BackColor = Color.Red;
  5841. label_FacModeResult.Text = "测试异常";
  5842. Delay_ms(500);
  5843. //存储异常并上传
  5844. FacMode_Stop(false);
  5845. return;
  5846. }
  5847. //写入SN
  5848. label_FacModeStatus.Text = "写入SN";
  5849. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  5850. textBox_FacModeNum.Text = InfoList[1];
  5851. string SN = textBox_FacModeNum.Text;
  5852. var SNArray = new byte[16];
  5853. for (ushort i = 0; i < SN.Length; i++)
  5854. {
  5855. SNArray[i] = (byte)SN[i];
  5856. }
  5857. if (SN.Length < 16)
  5858. {
  5859. SNArray[SN.Length] = (byte)'.';
  5860. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5861. {
  5862. SNArray[SN.Length + 1 + i] = 0x20;
  5863. }
  5864. }
  5865. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5866. WriteACK = false;
  5867. WriteCnt = 0;
  5868. ACK_WaitCnt = 0;
  5869. while (ACK_WaitCnt <= 2); //1s
  5870. if (WriteACK == true)
  5871. {
  5872. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  5873. }
  5874. else
  5875. {
  5876. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  5877. label_FacModeStatus.Text = "存在故障!";
  5878. label_FacModeResult.BackColor = Color.Red;
  5879. label_FacModeResult.Text = "测试异常";
  5880. Delay_ms(500);
  5881. //存储异常并上传
  5882. FacMode_Stop(false);
  5883. return;
  5884. }
  5885. }
  5886. else
  5887. {
  5888. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5889. return;
  5890. }
  5891. } while (false);
  5892. //写入配置文件
  5893. do
  5894. {
  5895. label_FacModeStatus.Text = "写入配置文件";
  5896. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  5897. //配置文件
  5898. List<byte[]> CmdList = new List<byte[]>();
  5899. //从服务器下载文件
  5900. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5901. {
  5902. string SelectFile = "";
  5903. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  5904. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  5905. {
  5906. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  5907. }
  5908. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  5909. //打开文件
  5910. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  5911. CmdList.Clear();
  5912. while (streamReader.Peek() != -1)
  5913. {
  5914. string fileLineInfo = streamReader.ReadLine();
  5915. if (fileLineInfo.IndexOf("[") != -1)
  5916. {
  5917. continue;
  5918. }
  5919. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  5920. }
  5921. streamReader.Close();
  5922. }
  5923. //加载本地文件
  5924. else
  5925. {
  5926. string SelectFile = "";
  5927. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  5928. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  5929. CmdList.Clear();
  5930. while (streamReader.Peek() != -1)
  5931. {
  5932. string fileLineInfo = streamReader.ReadLine();
  5933. if (fileLineInfo.IndexOf("[") != -1)
  5934. {
  5935. continue;
  5936. }
  5937. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  5938. }
  5939. streamReader.Close();
  5940. }
  5941. int CmdNum = CmdList.Count(); //指令个数
  5942. Delay_ms(500);
  5943. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  5944. Delay_ms(500);
  5945. //开始写入
  5946. WriteCnt = 0;
  5947. for (int i = 0; i < CmdList.Count; i++)
  5948. {
  5949. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  5950. Thread.Sleep(200);
  5951. }
  5952. //判断写入是否完整
  5953. if (CmdNum == WriteCnt)
  5954. {
  5955. label_FacMode_CfgWrite.BackColor = Color.Green;
  5956. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  5957. Delay_ms(500);
  5958. }
  5959. else
  5960. {
  5961. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败" + "\r\n");
  5962. label_FacModeStatus.Text = "存在故障!";
  5963. label_FacModeResult.BackColor = Color.Red;
  5964. label_FacModeResult.Text = "测试异常";
  5965. Delay_ms(500);
  5966. //存储异常并上传
  5967. FacMode_Stop(false);
  5968. return;
  5969. }
  5970. } while (false);
  5971. }
  5972. else
  5973. {
  5974. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  5975. label_FacModeStatus.Text = "跳过参数写入!";
  5976. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  5977. Delay_ms(500);
  5978. }
  5979. //BMS通讯
  5980. if (checkBox_FacModeBMS.Checked)
  5981. {
  5982. if (label_FacModeBMS.BackColor == Color.Red)
  5983. {
  5984. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  5985. label_FacModeStatus.Text = "存在故障!";
  5986. label_FacModeResult.BackColor = Color.Red;
  5987. label_FacModeResult.Text = "测试异常";
  5988. Delay_ms(500);
  5989. //存储异常并上传
  5990. FacMode_Stop(false);
  5991. return;
  5992. }
  5993. }
  5994. else
  5995. {
  5996. label_FacModeBMS.BackColor = Color.Yellow;
  5997. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  5998. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  5999. Delay_ms(500);
  6000. }
  6001. //MOS内阻校准
  6002. if (checkBox_FacMode_MosCal.Checked)
  6003. {
  6004. label_FacModeStatus.Text = "MOS内阻校准";
  6005. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6006. Delay_ms(500);
  6007. //提示进行负载切换
  6008. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6009. {
  6010. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6011. label_FacModeStatus.Text = "存在故障!";
  6012. label_FacModeResult.BackColor = Color.Red;
  6013. label_FacModeResult.Text = "测试异常";
  6014. Delay_ms(500);
  6015. //存储异常并上传
  6016. FacMode_Stop(false);
  6017. return;
  6018. }
  6019. //确认后发送校准指令
  6020. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6021. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6022. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6023. ushort uwDataTemp = 0;
  6024. uwDataTemp = Convert.ToUInt16(K[0]);
  6025. Code[2] = (byte)(uwDataTemp & 0xFF);
  6026. Code[3] = (byte)(uwDataTemp >> 8);
  6027. uwDataTemp = Convert.ToUInt16(K[1]);
  6028. Code[4] = (byte)(uwDataTemp & 0xFF);
  6029. Code[5] = (byte)(uwDataTemp >> 8);
  6030. uwDataTemp = Convert.ToUInt16(K[2]);
  6031. Code[6] = (byte)(uwDataTemp & 0xFF);
  6032. Code[7] = (byte)(uwDataTemp >> 8);
  6033. uwDataTemp = Convert.ToUInt16(K[3]);
  6034. Code[8] = (byte)(uwDataTemp & 0xFF);
  6035. Code[9] = (byte)(uwDataTemp >> 8);
  6036. uwDataTemp = Convert.ToUInt16(K[4]);
  6037. Code[10] = (byte)(uwDataTemp & 0xFF);
  6038. Code[11] = (byte)(uwDataTemp >> 8);
  6039. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6040. WriteACK = false;
  6041. WriteCnt = 0;
  6042. ACK_WaitCnt = 0;
  6043. while (ACK_WaitCnt <= 6) ; //3s
  6044. if (WriteACK == true)
  6045. {
  6046. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6047. }
  6048. else
  6049. {
  6050. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6051. label_FacModeStatus.Text = "存在故障!";
  6052. label_FacModeResult.BackColor = Color.Red;
  6053. label_FacModeResult.Text = "测试异常";
  6054. Delay_ms(500);
  6055. //存储异常并上传
  6056. FacMode_Stop(false);
  6057. return;
  6058. }
  6059. //因控制器复位需发送指令重新进入5S协议
  6060. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6061. {
  6062. Code[0] = 0x00;//5S协议
  6063. Code[1] = 0x00;
  6064. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6065. Delay_ms(500);
  6066. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6067. Delay_ms(500);
  6068. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6069. }
  6070. //读取显示校准返回数据
  6071. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  6072. foreach (Control c in groupBox21.Controls)
  6073. {
  6074. if (c is TextBox)
  6075. c.Text = "";
  6076. }
  6077. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6078. ACK_WaitCnt = 0;
  6079. while (ACK_WaitCnt <= 2) ; //1s
  6080. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6081. {
  6082. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6083. label_FacModeStatus.Text = "存在故障!";
  6084. label_FacModeResult.BackColor = Color.Red;
  6085. label_FacModeResult.Text = "测试异常";
  6086. Delay_ms(500);
  6087. //存储异常并上传
  6088. FacMode_Stop(false);
  6089. return;
  6090. }
  6091. else
  6092. {
  6093. 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");
  6094. }
  6095. //与校准返回数据对比
  6096. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6097. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6098. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6099. 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])) &&
  6100. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6101. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6102. )
  6103. {
  6104. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6105. label_FacModeMosCal.BackColor = Color.Green;
  6106. }
  6107. else
  6108. {
  6109. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6110. label_FacModeStatus.Text = "存在故障!";
  6111. label_FacModeResult.BackColor = Color.Red;
  6112. label_FacModeResult.Text = "测试异常";
  6113. Delay_ms(500);
  6114. //存储异常并上传
  6115. FacMode_Stop(false);
  6116. return;
  6117. }
  6118. }
  6119. else
  6120. {
  6121. label_FacModeMosCal.BackColor = Color.Yellow;
  6122. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6123. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6124. Delay_ms(500);
  6125. }
  6126. //基础功能检测
  6127. if (checkBox_FacBaseFucTest.Checked)
  6128. {
  6129. label_FacModeStatus.Text = "基础功能检测";
  6130. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6131. //确认负载位置
  6132. if (checkBox_FacMode_MosCal.Checked)
  6133. {
  6134. if (MessageBox.Show("请确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6135. {
  6136. if (MessageBox.Show("再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6137. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6138. }
  6139. else
  6140. {
  6141. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6142. label_FacModeStatus.Text = "存在故障!";
  6143. label_FacModeResult.BackColor = Color.Red;
  6144. label_FacModeResult.Text = "测试异常";
  6145. Delay_ms(500);
  6146. //存储异常并上传
  6147. FacMode_Stop(false);
  6148. return;
  6149. }
  6150. }
  6151. //发送指令进入配置模式
  6152. do
  6153. {
  6154. Code[0] = 0x01;
  6155. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6156. WriteACK = false;
  6157. WriteCnt = 0;
  6158. ACK_WaitCnt = 0;
  6159. while (ACK_WaitCnt <= 2); //1s
  6160. if (textBox_RunInfo_Vol.Text != "---")
  6161. {
  6162. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6163. }
  6164. else
  6165. {
  6166. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6167. label_FacModeStatus.Text = "存在故障!";
  6168. label_FacModeResult.BackColor = Color.Red;
  6169. label_FacModeResult.Text = "测试异常";
  6170. Delay_ms(500);
  6171. //存储异常并上传
  6172. FacMode_Stop(false);
  6173. return;
  6174. }
  6175. } while (false);
  6176. //发送指令启动电机
  6177. do
  6178. {
  6179. #if false //通过运行模式3启动电机
  6180. //发送指令读取调试信息
  6181. richTextBox_DebugParam.Clear();
  6182. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6183. WriteACK = false;
  6184. WriteCnt = 0;
  6185. ACK_WaitCnt = 0;
  6186. while (ACK_WaitCnt <= 2); //1s
  6187. //获取调试信息
  6188. string DebugDefaultInfo = "";
  6189. if (richTextBox_DebugParam.Text == string.Empty)
  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. else
  6201. {
  6202. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6203. }
  6204. //设置模式
  6205. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6206. strDataTemp[0] = "整体运行模式=3";
  6207. //发送数据
  6208. Code[0] = 0;
  6209. Code[1] = 0;
  6210. for (int i = 0; i < strDataTemp.Length; i++)
  6211. {
  6212. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6213. Code[2 * i + 2] = (byte)uwDataTemp;
  6214. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6215. }
  6216. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6217. label_FacModeStatus.Text = "启动电机";
  6218. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6219. #else //通过Walk模式启动电机
  6220. //设置转速100%
  6221. var Data = new byte[1];
  6222. Data[0] = (byte)100;
  6223. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6224. //启动电机进入WALK模式
  6225. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6226. Code[0] = 0x22;
  6227. Code[1] = 0xF0;
  6228. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6229. WriteACK = false;
  6230. WriteCnt = 0;
  6231. ACK_WaitCnt = 0;
  6232. while (ACK_WaitCnt <= 2) ; //1s
  6233. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6234. {
  6235. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6236. label_FacModeStatus.Text = "存在故障!";
  6237. label_FacModeResult.BackColor = Color.Red;
  6238. label_FacModeResult.Text = "测试异常";
  6239. Delay_ms(500);
  6240. //存储异常并上传
  6241. FacMode_Stop(false);
  6242. return;
  6243. }
  6244. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6245. #endif
  6246. Delay_ms(3000);
  6247. } while (false);
  6248. //判断车速
  6249. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6250. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6251. {
  6252. label_FacModeSpeed.BackColor = Color.Green;
  6253. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6254. }
  6255. else
  6256. {
  6257. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6258. label_FacModeStatus.Text = "存在故障!";
  6259. label_FacModeResult.BackColor = Color.Red;
  6260. label_FacModeResult.Text = "测试异常";
  6261. Delay_ms(500);
  6262. //存储异常并上传
  6263. FacMode_Stop(false);
  6264. return;
  6265. }
  6266. //判断电压
  6267. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6268. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6269. {
  6270. label_FacModeVolTest.BackColor = Color.Green;
  6271. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6272. }
  6273. else
  6274. {
  6275. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6276. label_FacModeStatus.Text = "存在故障!";
  6277. label_FacModeResult.BackColor = Color.Red;
  6278. label_FacModeResult.Text = "测试异常";
  6279. Delay_ms(500);
  6280. //存储异常并上传
  6281. FacMode_Stop(false);
  6282. return;
  6283. }
  6284. //判断电流
  6285. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6286. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6287. {
  6288. label_FacModeCurrentTest.BackColor = Color.Green;
  6289. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6290. }
  6291. else
  6292. {
  6293. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6294. label_FacModeStatus.Text = "存在故障!";
  6295. label_FacModeResult.BackColor = Color.Red;
  6296. label_FacModeResult.Text = "测试异常";
  6297. Delay_ms(500);
  6298. //存储异常并上传
  6299. FacMode_Stop(false);
  6300. return;
  6301. }
  6302. //判断温度
  6303. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6304. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6305. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6306. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6307. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6308. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6309. {
  6310. label_FacModeNTC.BackColor = Color.Green;
  6311. 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");
  6312. }
  6313. else
  6314. {
  6315. 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");
  6316. label_FacModeStatus.Text = "存在故障!";
  6317. label_FacModeResult.BackColor = Color.Red;
  6318. label_FacModeResult.Text = "测试异常";
  6319. Delay_ms(500);
  6320. //存储异常并上传
  6321. FacMode_Stop(false);
  6322. return;
  6323. }
  6324. //判断转速
  6325. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6326. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6327. {
  6328. label_FacModeMotorSpeed.BackColor = Color.Green;
  6329. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6330. }
  6331. else
  6332. {
  6333. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6334. label_FacModeStatus.Text = "存在故障!";
  6335. label_FacModeResult.BackColor = Color.Red;
  6336. label_FacModeResult.Text = "测试异常";
  6337. Delay_ms(500);
  6338. //存储异常并上传
  6339. FacMode_Stop(false);
  6340. return;
  6341. }
  6342. //发送指令停止电机
  6343. do
  6344. {
  6345. //设置转速0%
  6346. var Data = new byte[1];
  6347. Data[0] = (byte)0;
  6348. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6349. #if false //通过修改调试模式停止电机
  6350. //获取调试信息
  6351. string DebugDefaultInfo = "";
  6352. if (richTextBox_DebugParam.Text == string.Empty)
  6353. {
  6354. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6355. label_FacModeStatus.Text = "存在故障!";
  6356. label_FacModeResult.BackColor = Color.Red;
  6357. label_FacModeResult.Text = "测试异常";
  6358. Delay_ms(500);
  6359. //存储异常并上传
  6360. FacMode_Stop(false);
  6361. return;
  6362. }
  6363. else
  6364. {
  6365. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6366. }
  6367. //设置模式
  6368. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6369. //发送数据
  6370. Code[0] = 0;
  6371. Code[1] = 0;
  6372. for (int i = 0; i < strDataTemp.Length; i++)
  6373. {
  6374. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6375. Code[2 * i + 2] = (byte)uwDataTemp;
  6376. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6377. }
  6378. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6379. label_FacModeStatus.Text = "停止电机";
  6380. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6381. #else //通过调整档位停止电机
  6382. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6383. Code[0] = 0x00;
  6384. Code[1] = 0xF0;
  6385. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6386. WriteACK = false;
  6387. WriteCnt = 0;
  6388. ACK_WaitCnt = 0;
  6389. while (ACK_WaitCnt <= 2) ; //1s
  6390. if (textBox_RunInfo_GearSt.Text != "OFF")
  6391. {
  6392. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6393. label_FacModeStatus.Text = "存在故障!";
  6394. label_FacModeResult.BackColor = Color.Red;
  6395. label_FacModeResult.Text = "测试异常";
  6396. Delay_ms(500);
  6397. //存储异常并上传
  6398. FacMode_Stop(false);
  6399. return;
  6400. }
  6401. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6402. #endif
  6403. Delay_ms(2000);
  6404. } while (false);
  6405. }
  6406. else
  6407. {
  6408. label_FacModeSpeed.BackColor = Color.Yellow;
  6409. label_FacModeVolTest.BackColor = Color.Yellow;
  6410. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6411. label_FacModeNTC.BackColor = Color.Yellow;
  6412. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6413. label_FacModeStatus.Text = "跳过基础功能检测!";
  6414. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6415. Delay_ms(500);
  6416. }
  6417. //力矩检测
  6418. if (checkBox_FacTor.Checked)
  6419. {
  6420. label_FacModeStatus.Text = "力矩传感器检测!";
  6421. //发送指令进入配置模式
  6422. do
  6423. {
  6424. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6425. {
  6426. break;
  6427. }
  6428. Code[0] = 0x01;
  6429. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6430. WriteACK = false;
  6431. WriteCnt = 0;
  6432. ACK_WaitCnt = 0;
  6433. while (ACK_WaitCnt <= 2) ; //1s
  6434. if (textBox_RunInfo_Vol.Text != "---")
  6435. {
  6436. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6437. Delay_ms(500);
  6438. }
  6439. else
  6440. {
  6441. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6442. label_FacModeStatus.Text = "存在故障!";
  6443. label_FacModeResult.BackColor = Color.Red;
  6444. label_FacModeResult.Text = "测试异常";
  6445. Delay_ms(500);
  6446. //存储异常并上传
  6447. FacMode_Stop(false);
  6448. return;
  6449. }
  6450. } while (false);
  6451. ushort Max = 0, Torque = 0;
  6452. //提示输入力矩信号
  6453. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  6454. ACK_WaitCnt = 0;
  6455. while (ACK_WaitCnt <= 20) //10s
  6456. {
  6457. //获取力矩值
  6458. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  6459. if (Torque > Max)
  6460. Max = Torque;
  6461. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  6462. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  6463. (ACK_WaitCnt >= 6))
  6464. {
  6465. label_FacModeTq.BackColor = Color.Green;
  6466. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6467. break;
  6468. }
  6469. }
  6470. if (ACK_WaitCnt >= 20)
  6471. {
  6472. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\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. else
  6483. {
  6484. label_FacModeTq.BackColor = Color.Yellow;
  6485. label_FacModeCad.BackColor = Color.Yellow;
  6486. label_FacModeStatus.Text = "跳过力矩检测!";
  6487. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  6488. Delay_ms(500);
  6489. }
  6490. //踏频检测
  6491. if (checkBox_FacCad.Checked)
  6492. {
  6493. label_FacModeStatus.Text = "踏频传感器检测!";
  6494. //发送指令进入配置模式
  6495. do
  6496. {
  6497. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6498. {
  6499. break;
  6500. }
  6501. Code[0] = 0x01;
  6502. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6503. WriteACK = false;
  6504. WriteCnt = 0;
  6505. ACK_WaitCnt = 0;
  6506. while (ACK_WaitCnt <= 2) ; //1s
  6507. if (textBox_RunInfo_Vol.Text != "---")
  6508. {
  6509. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6510. Delay_ms(500);
  6511. }
  6512. else
  6513. {
  6514. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6515. label_FacModeStatus.Text = "存在故障!";
  6516. label_FacModeResult.BackColor = Color.Red;
  6517. label_FacModeResult.Text = "测试异常";
  6518. Delay_ms(500);
  6519. //存储异常并上传
  6520. FacMode_Stop(false);
  6521. return;
  6522. }
  6523. } while (false);
  6524. ushort Max = 0, Cadence = 0;
  6525. //提示输入踏频信号
  6526. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  6527. ACK_WaitCnt = 0;
  6528. while (ACK_WaitCnt <= 20) //10s
  6529. {
  6530. //获取踏频
  6531. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  6532. if (Cadence > Max)
  6533. Max = Cadence;
  6534. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  6535. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  6536. (ACK_WaitCnt >= 6))
  6537. {
  6538. label_FacModeCad.BackColor = Color.Green;
  6539. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6540. break;
  6541. }
  6542. }
  6543. if (ACK_WaitCnt >= 20)
  6544. {
  6545. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6546. label_FacModeStatus.Text = "存在故障!";
  6547. label_FacModeResult.BackColor = Color.Red;
  6548. label_FacModeResult.Text = "测试异常";
  6549. Delay_ms(500);
  6550. //存储异常并上传
  6551. FacMode_Stop(false);
  6552. return;
  6553. }
  6554. }
  6555. else
  6556. {
  6557. label_FacModeTq.BackColor = Color.Yellow;
  6558. label_FacModeCad.BackColor = Color.Yellow;
  6559. label_FacModeStatus.Text = "跳过踏频检测!";
  6560. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  6561. Delay_ms(500);
  6562. }
  6563. //转把检测
  6564. if (checkBox_FacThrrotleTest.Checked)
  6565. {
  6566. label_FacModeStatus.Text = "转把检测";
  6567. //发送指令进入配置模式
  6568. do
  6569. {
  6570. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6571. {
  6572. break;
  6573. }
  6574. Code[0] = 0x01;
  6575. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6576. WriteACK = false;
  6577. WriteCnt = 0;
  6578. ACK_WaitCnt = 0;
  6579. while (ACK_WaitCnt <= 2) ; //1s
  6580. if (textBox_RunInfo_Vol.Text != "---")
  6581. {
  6582. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6583. Delay_ms(500);
  6584. }
  6585. else
  6586. {
  6587. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6588. label_FacModeStatus.Text = "存在故障!";
  6589. label_FacModeResult.BackColor = Color.Red;
  6590. label_FacModeResult.Text = "测试异常";
  6591. Delay_ms(500);
  6592. //存储异常并上传
  6593. FacMode_Stop(false);
  6594. return;
  6595. }
  6596. } while (false);
  6597. //进入TURBO档
  6598. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  6599. Code[0] = 0x04;
  6600. Code[1] = 0xF0;
  6601. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6602. WriteACK = false;
  6603. WriteCnt = 0;
  6604. ACK_WaitCnt = 0;
  6605. while (ACK_WaitCnt <= 2) ; //1s
  6606. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6607. {
  6608. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  6609. label_FacModeStatus.Text = "存在故障!";
  6610. label_FacModeResult.BackColor = Color.Red;
  6611. label_FacModeResult.Text = "测试异常";
  6612. Delay_ms(500);
  6613. //存储异常并上传
  6614. FacMode_Stop(false);
  6615. return;
  6616. }
  6617. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,10s内转动转把" + "\r\n");
  6618. ACK_WaitCnt = 0;
  6619. while (ACK_WaitCnt <= 20)
  6620. {
  6621. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  6622. {
  6623. label_FacModeGas.BackColor = Color.Green;
  6624. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  6625. break;
  6626. }
  6627. }
  6628. if (ACK_WaitCnt >= 20) //转把超时
  6629. {
  6630. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  6631. label_FacModeStatus.Text = "存在故障!";
  6632. label_FacModeResult.BackColor = Color.Red;
  6633. label_FacModeResult.Text = "测试异常";
  6634. Delay_ms(500);
  6635. //存储异常并上传
  6636. FacMode_Stop(false);
  6637. return;
  6638. }
  6639. }
  6640. else
  6641. {
  6642. label_FacModeGas.BackColor = Color.Yellow;
  6643. label_FacModeStatus.Text = "跳过转把检测!";
  6644. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  6645. Delay_ms(500);
  6646. }
  6647. //刹车检测
  6648. if (checkBox_FacBreakTest.Checked)
  6649. {
  6650. label_FacModeStatus.Text = "刹把检测";
  6651. //发送指令进入配置模式
  6652. do
  6653. {
  6654. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6655. {
  6656. break;
  6657. }
  6658. Code[0] = 0x01;
  6659. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6660. WriteACK = false;
  6661. WriteCnt = 0;
  6662. ACK_WaitCnt = 0;
  6663. while (ACK_WaitCnt <= 2) ; //1s
  6664. if (textBox_RunInfo_Vol.Text != "---")
  6665. {
  6666. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6667. Delay_ms(500);
  6668. }
  6669. else
  6670. {
  6671. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6672. label_FacModeStatus.Text = "存在故障!";
  6673. label_FacModeResult.BackColor = Color.Red;
  6674. label_FacModeResult.Text = "测试异常";
  6675. Delay_ms(500);
  6676. //存储异常并上传
  6677. FacMode_Stop(false);
  6678. return;
  6679. }
  6680. } while (false);
  6681. //设置转速100%
  6682. var Data = new byte[1];
  6683. Data[0] = (byte)100;
  6684. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6685. //启动电机进入WALK模式
  6686. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  6687. Code[0] = 0x22;
  6688. Code[1] = 0xF0;
  6689. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6690. WriteACK = false;
  6691. WriteCnt = 0;
  6692. ACK_WaitCnt = 0;
  6693. while (ACK_WaitCnt <= 2) ; //1s
  6694. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6695. {
  6696. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6697. label_FacModeStatus.Text = "存在故障!";
  6698. label_FacModeResult.BackColor = Color.Red;
  6699. label_FacModeResult.Text = "测试异常";
  6700. Delay_ms(500);
  6701. //存储异常并上传
  6702. FacMode_Stop(false);
  6703. return;
  6704. }
  6705. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  6706. ACK_WaitCnt = 0;
  6707. while (ACK_WaitCnt <= 20)
  6708. {
  6709. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  6710. {
  6711. label_FacModeBreak.BackColor = Color.Green;
  6712. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  6713. break;
  6714. }
  6715. }
  6716. if (ACK_WaitCnt >= 20) //剎把超时
  6717. {
  6718. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
  6719. label_FacModeStatus.Text = "存在故障!";
  6720. label_FacModeResult.BackColor = Color.Red;
  6721. label_FacModeResult.Text = "测试异常";
  6722. Delay_ms(500);
  6723. //存储异常并上传
  6724. FacMode_Stop(false);
  6725. return;
  6726. }
  6727. //停止电机
  6728. Code[0] = 0x00;
  6729. Code[1] = 0xF0;
  6730. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6731. WriteACK = false;
  6732. WriteCnt = 0;
  6733. ACK_WaitCnt = 0;
  6734. while (ACK_WaitCnt <= 2) ; //1s
  6735. if (textBox_RunInfo_GearSt.Text != "OFF")
  6736. {
  6737. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6738. label_FacModeStatus.Text = "存在故障!";
  6739. label_FacModeResult.BackColor = Color.Red;
  6740. label_FacModeResult.Text = "测试异常";
  6741. Delay_ms(500);
  6742. //存储异常并上传
  6743. FacMode_Stop(false);
  6744. return;
  6745. }
  6746. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  6747. Delay_ms(500);
  6748. }
  6749. else
  6750. {
  6751. label_FacModeBreak.BackColor = Color.Yellow;
  6752. label_FacModeStatus.Text = "跳过刹车检测!";
  6753. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  6754. Delay_ms(500);
  6755. }
  6756. //前后灯检测
  6757. if (checkBox_FacLightTest.Checked)
  6758. {
  6759. //前后灯检测
  6760. label_FacModeStatus.Text = "前后灯检测";
  6761. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  6762. //发送指令打开车灯
  6763. Code[0] = 0x00;
  6764. Code[1] = 0xF1;
  6765. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6766. WriteACK = false;
  6767. WriteCnt = 0;
  6768. ACK_WaitCnt = 0;
  6769. while (ACK_WaitCnt <= 2) ; //1s
  6770. if (textBox_RunInfo_LightSwitch.Text != "ON")
  6771. {
  6772. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  6773. label_FacModeStatus.Text = "存在故障!";
  6774. label_FacModeResult.BackColor = Color.Red;
  6775. label_FacModeResult.Text = "测试异常";
  6776. Delay_ms(500);
  6777. //存储异常并上传
  6778. FacMode_Stop(false);
  6779. return;
  6780. }
  6781. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  6782. Delay_ms(500);
  6783. //提示检查灯压是否正确
  6784. if (MessageBox.Show("前后灯是否正常?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  6785. {
  6786. label_FacModeLightF.BackColor = Color.Green;
  6787. label_FacModeLightB.BackColor = Color.Green;
  6788. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  6789. Delay_ms(500);
  6790. }
  6791. else
  6792. {
  6793. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  6794. label_FacModeStatus.Text = "存在故障!";
  6795. label_FacModeResult.BackColor = Color.Red;
  6796. label_FacModeResult.Text = "测试异常";
  6797. Delay_ms(500);
  6798. //存储异常并上传
  6799. FacMode_Stop(false);
  6800. return;
  6801. }
  6802. //发送指令关闭车灯
  6803. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  6804. Code[0] = 0x00;
  6805. Code[1] = 0xF0;
  6806. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6807. WriteACK = false;
  6808. WriteCnt = 0;
  6809. ACK_WaitCnt = 0;
  6810. while (ACK_WaitCnt <= 2) ; //1s
  6811. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  6812. {
  6813. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  6814. label_FacModeStatus.Text = "存在故障!";
  6815. label_FacModeResult.BackColor = Color.Red;
  6816. label_FacModeResult.Text = "测试异常";
  6817. Delay_ms(500);
  6818. //存储异常并上传
  6819. FacMode_Stop(false);
  6820. return;
  6821. }
  6822. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  6823. Delay_ms(500);
  6824. }
  6825. else
  6826. {
  6827. label_FacModeLightF.BackColor = Color.Yellow;
  6828. label_FacModeLightB.BackColor = Color.Yellow;
  6829. label_FacModeStatus.Text = "跳过前后灯检测!";
  6830. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  6831. Delay_ms(500);
  6832. }
  6833. //软件版本检测
  6834. do
  6835. {
  6836. label_FacModeStatus.Text = "软件版本确认";
  6837. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  6838. //发送指令读取版本
  6839. Class_Motor_Ver.Mode = "---";
  6840. Class_Motor_Ver.SN = "---";
  6841. Class_Motor_Ver.HW = "---";
  6842. Class_Motor_Ver.FW = "---";
  6843. Class_Motor_Ver.Special = "---";
  6844. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  6845. ACK_WaitCnt = 0;
  6846. while (ACK_WaitCnt <= 2) ; //1s
  6847. if (Class_Motor_Ver.Mode == "---")
  6848. {
  6849. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  6850. label_FacModeStatus.Text = "存在故障!";
  6851. label_FacModeResult.BackColor = Color.Red;
  6852. label_FacModeResult.Text = "测试异常";
  6853. Delay_ms(500);
  6854. //存储异常并上传
  6855. FacMode_Stop(false);
  6856. return;
  6857. }
  6858. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  6859. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  6860. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  6861. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  6862. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  6863. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  6864. //判断版本是否正确
  6865. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  6866. string VerRead = "";
  6867. try
  6868. {
  6869. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  6870. }
  6871. catch (System.Exception)
  6872. {
  6873. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  6874. label_FacModeStatus.Text = "存在故障!";
  6875. label_FacModeResult.BackColor = Color.Red;
  6876. label_FacModeResult.Text = "测试异常";
  6877. Delay_ms(500);
  6878. //存储异常并上传
  6879. FacMode_Stop(false);
  6880. return;
  6881. }
  6882. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  6883. {
  6884. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  6885. label_FacModeStatus.Text = "存在故障!";
  6886. label_FacModeResult.BackColor = Color.Red;
  6887. label_FacModeResult.Text = "测试异常";
  6888. Delay_ms(500);
  6889. //存储异常并上传
  6890. FacMode_Stop(false);
  6891. return;
  6892. }
  6893. label_FacModeFWVersion.BackColor = Color.Green;
  6894. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  6895. Delay_ms(500);
  6896. } while (false);
  6897. //测试合格
  6898. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  6899. label_FacModeStatus.Text = "测试结束!";
  6900. label_FacModeResult.BackColor = Color.Green;
  6901. label_FacModeResult.Text = "测试合格";
  6902. Delay_ms(500);
  6903. //存储并上传
  6904. FacMode_Stop(true);
  6905. return;
  6906. }
  6907. private void FacModelLabelInit()
  6908. {
  6909. //测试状态标签
  6910. label_FacModeResult.BackColor = Color.Yellow;
  6911. label_FacModeResult.Text = "测试中";
  6912. //测试过程标签
  6913. label_FacModeStatus.Text = "测试就绪";
  6914. //测试结果标签
  6915. foreach (Control c in groupBox28.Controls)
  6916. {
  6917. if (c is Label)
  6918. {
  6919. if (c.Text == string.Empty)
  6920. c.BackColor = Color.Red;
  6921. }
  6922. }
  6923. }
  6924. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  6925. {
  6926. //更新生产配置文件目录
  6927. GetDateList(false);
  6928. }
  6929. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  6930. {
  6931. //更新生产配置文件目录
  6932. GetDateList(false);
  6933. }
  6934. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  6935. {
  6936. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  6937. richTextBox_FacModeLog.ScrollToCaret();
  6938. }
  6939. /// <summary>
  6940. /// 参数检验测试停止
  6941. /// </summary>
  6942. /// <param name="OK_Flag"></param>
  6943. private void CheckMode_Stop(bool OK_Flag)
  6944. {
  6945. //打开开始按钮
  6946. button_CheckModeStart.Enabled = true;
  6947. //系统关机
  6948. var Code = new byte[32];//发送的指令数据
  6949. Code[0] = 0xF0;
  6950. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6951. //关闭串口
  6952. //mySerialProcess.SerialClose(false);
  6953. //路径设置
  6954. string LocalSavePath = "";
  6955. string ServerSavePath = "";
  6956. if (OK_Flag)
  6957. {
  6958. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  6959. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  6960. }
  6961. else
  6962. {
  6963. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  6964. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  6965. }
  6966. if (Directory.Exists(LocalSavePath) == false)
  6967. {
  6968. Directory.CreateDirectory(LocalSavePath);
  6969. }
  6970. //保存和上传
  6971. string LogSavePath = "";
  6972. string LogSaveFileName = "";
  6973. string ProductInfo = textBox_CheckModeScan.Text;
  6974. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  6975. if (Directory.Exists(LogSavePath) == false)
  6976. {
  6977. Directory.CreateDirectory(LogSavePath);
  6978. }
  6979. //测试页面
  6980. Double scaleX = PrimaryScreen.ScaleX;
  6981. Double scaleY = PrimaryScreen.ScaleY;
  6982. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  6983. Graphics g = Graphics.FromImage(bit);
  6984. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  6985. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  6986. bit.Save(LogSaveFileName);
  6987. //上传测试页面到服务器
  6988. if (myFtp.IsNetConnected == true)
  6989. {
  6990. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6991. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6992. {
  6993. myFtp.MakeDir(ServerSavePath + DateNow);
  6994. }
  6995. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6996. {
  6997. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6998. }
  6999. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7000. if (result == true)
  7001. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7002. }
  7003. //测试记录
  7004. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7005. string file_str = "";
  7006. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7007. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7008. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7009. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7010. file_str += Local_HdInformation;
  7011. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7012. //上传测试记录到服务器
  7013. if (myFtp.IsNetConnected == true)
  7014. {
  7015. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7016. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7017. {
  7018. myFtp.MakeDir(ServerSavePath + DateNow);
  7019. }
  7020. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7021. {
  7022. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7023. }
  7024. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7025. if (result == true)
  7026. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7027. }
  7028. //扫码框清空
  7029. textBox_CheckModeScan.Text = "";
  7030. }
  7031. /// <summary>
  7032. /// 参数检验开始
  7033. /// </summary>
  7034. /// <param name="sender"></param>
  7035. /// <param name="e"></param>
  7036. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7037. {
  7038. //测试项目关闭编辑
  7039. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7040. foreach (Control c in groupBox29.Controls)
  7041. {
  7042. if (c is CheckBox)
  7043. c.Enabled = false;
  7044. }
  7045. ReadLockStatus = true;
  7046. //检查配置文件
  7047. if (comboBox_CheckModeCfgFile.Text == "")
  7048. {
  7049. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7050. return;
  7051. }
  7052. //开始测试
  7053. CheckTestStart();
  7054. }
  7055. /// <summary>
  7056. /// 参数检验测试子函数
  7057. /// </summary>
  7058. private void CheckTestStart()
  7059. {
  7060. //初始化标签
  7061. CheckModeLabelInit();
  7062. richTextBox_CheckModeLog.Clear();
  7063. //按钮禁止操作
  7064. button_CheckModeStart.Enabled = false;
  7065. //记录配置文件
  7066. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7067. //检查打标信息
  7068. label_CheckModeStatus.Text = "检查扫码信息";
  7069. Delay_ms(500);
  7070. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7071. if (textBox_CheckModeScan.Text == string.Empty)
  7072. {
  7073. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7074. button__FacMode_Start.Enabled = false;
  7075. return;
  7076. }
  7077. try
  7078. {
  7079. if (中置电机ToolStripMenuItem.Checked == true)
  7080. {
  7081. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7082. {
  7083. label_CheckModeStatus.Text = "存在故障!";
  7084. label_CheckModeResult.BackColor = Color.Red;
  7085. label_CheckModeResult.Text = "标签格式错误";
  7086. button_CheckModeStart.Enabled = true;
  7087. return;
  7088. }
  7089. }
  7090. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7091. {
  7092. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  7093. {
  7094. label_CheckModeStatus.Text = "存在故障!";
  7095. label_CheckModeResult.BackColor = Color.Red;
  7096. label_CheckModeResult.Text = "标签格式错误";
  7097. button_CheckModeStart.Enabled = true;
  7098. return;
  7099. }
  7100. }
  7101. }
  7102. catch (System.Exception)
  7103. {
  7104. label_CheckModeStatus.Text = "存在故障!";
  7105. label_CheckModeResult.BackColor = Color.Red;
  7106. label_CheckModeResult.Text = "标签格式错误";
  7107. button_CheckModeStart.Enabled = true;
  7108. return;
  7109. }
  7110. //打开串口
  7111. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  7112. if (!mySerialProcess.mySerial.IsOpen)
  7113. {
  7114. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7115. button__FacMode_Start.Enabled = false;
  7116. return;
  7117. }
  7118. //流水号计数
  7119. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  7120. serial += 1;
  7121. label_CheckModeSerial.Text = serial.ToString();
  7122. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  7123. //创建线程,执行测试任务
  7124. Thread th = new Thread(CheckModeTest_Task);
  7125. th.Start();
  7126. }
  7127. /// <summary>
  7128. /// 执行一次测试任务
  7129. /// </summary>
  7130. private void CheckModeTest_Task()
  7131. {
  7132. //开始测试
  7133. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  7134. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  7135. //变量定义
  7136. var Code = new byte[255];//发送的指令数据
  7137. ushort DataTemp;
  7138. short DataTemp_Int16;
  7139. string ResultPathName = "";
  7140. label_CheckModeStatus.Text = "开始测试";
  7141. Delay_ms(500);
  7142. label_CheckModeStatus.Text = "系统开机";
  7143. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  7144. if (uARTToolStripMenuItem.Checked)
  7145. {
  7146. Code[0] = (byte)'R';
  7147. Code[1] = (byte)'E';
  7148. Code[2] = (byte)'S';
  7149. Code[3] = (byte)'E';
  7150. Code[4] = (byte)'T';
  7151. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  7152. Delay_ms(500);
  7153. }
  7154. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  7155. BootInfo = "";
  7156. Code[0] = 0xF0;
  7157. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7158. Delay_ms(1500);
  7159. Code[0] = 0xF1;
  7160. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7161. ACK_WaitCnt = 0;
  7162. while (ACK_WaitCnt <= 10) ; //5s
  7163. //检查BOOT版本
  7164. if (BootInfo != string.Empty)
  7165. {
  7166. label_CheckModeBoot.BackColor = Color.Green;
  7167. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  7168. Delay_ms(500);
  7169. }
  7170. else
  7171. {
  7172. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  7173. label_CheckModeStatus.Text = "存在故障!";
  7174. label_CheckModeResult.BackColor = Color.Red;
  7175. label_CheckModeResult.Text = "测试异常";
  7176. Delay_ms(500);
  7177. //存储异常并上传
  7178. CheckMode_Stop(false);
  7179. return;
  7180. }
  7181. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7182. {
  7183. Code[0] = 0x00;//5S协议
  7184. Code[1] = 0x00;
  7185. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7186. Delay_ms(500);
  7187. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7188. Delay_ms(500);
  7189. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  7190. }
  7191. //发送指令读取版本信息
  7192. do
  7193. {
  7194. label_CheckModeStatus.Text = "读取版本信息";
  7195. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7196. //发送指令读取版本
  7197. Class_Motor_Ver.Mode = "---";
  7198. Class_Motor_Ver.SN = "---";
  7199. Class_Motor_Ver.HW = "---";
  7200. Class_Motor_Ver.FW = "---";
  7201. Class_Motor_Ver.Special = "---";
  7202. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7203. ACK_WaitCnt = 0;
  7204. while (ACK_WaitCnt <= 2) ; //1s
  7205. if (Class_Motor_Ver.Mode == "---")
  7206. {
  7207. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  7208. label_CheckModeStatus.Text = "存在故障!";
  7209. label_CheckModeResult.BackColor = Color.Red;
  7210. label_CheckModeResult.Text = "测试异常";
  7211. Delay_ms(500);
  7212. //存储异常并上传
  7213. CheckMode_Stop(false);
  7214. return;
  7215. }
  7216. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7217. Delay_ms(500);
  7218. } while (false);
  7219. //软件版本检查
  7220. if (checkBox_CheckModeFWVer.Checked)
  7221. {
  7222. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7223. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7224. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7225. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7226. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7227. //判断版本是否正确
  7228. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  7229. string VerRead = "";
  7230. try
  7231. {
  7232. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7233. }
  7234. catch (System.Exception)
  7235. {
  7236. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7237. label_CheckModeStatus.Text = "存在故障!";
  7238. label_CheckModeResult.BackColor = Color.Red;
  7239. label_CheckModeResult.Text = "测试异常";
  7240. Delay_ms(500);
  7241. //存储异常并上传
  7242. CheckMode_Stop(false);
  7243. return;
  7244. }
  7245. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7246. {
  7247. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7248. label_CheckModeStatus.Text = "存在故障!";
  7249. label_CheckModeResult.BackColor = Color.Red;
  7250. label_CheckModeResult.Text = "测试异常";
  7251. Delay_ms(500);
  7252. //存储异常并上传
  7253. CheckMode_Stop(false);
  7254. return;
  7255. }
  7256. label_CheckModeFWVer.BackColor = Color.Green;
  7257. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7258. Delay_ms(500);
  7259. }
  7260. else
  7261. {
  7262. label_CheckModeFWVer.BackColor = Color.Yellow;
  7263. label_CheckModeStatus.Text = "跳过软件版本查询";
  7264. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  7265. Delay_ms(500);
  7266. }
  7267. //打标信息核对
  7268. if (checkBox_CheckModeSN.Checked)
  7269. {
  7270. label_CheckModeStatus.Text = "核对打标信息";
  7271. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  7272. //根据扫码信息获取型号和SN
  7273. string ScanInfo = textBox_CheckModeScan.Text;
  7274. string regexInfo = "";
  7275. string[] InfoList = { "" };
  7276. try
  7277. {
  7278. if (中置电机ToolStripMenuItem.Checked == true)
  7279. {
  7280. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  7281. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  7282. }
  7283. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7284. {
  7285. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7286. string Model = InfoList[0];
  7287. string Spec = InfoList[1];
  7288. string Sn = InfoList[2];
  7289. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  7290. InfoList[1] = Sn;
  7291. }
  7292. }
  7293. catch
  7294. {
  7295. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  7296. label_FacModeStatus.Text = "存在故障!";
  7297. label_FacModeResult.BackColor = Color.Red;
  7298. label_FacModeResult.Text = "标签格式错误";
  7299. Delay_ms(500);
  7300. //存储异常并上传
  7301. CheckMode_Stop(false);
  7302. return;
  7303. }
  7304. //核对型号
  7305. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  7306. {
  7307. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  7308. label_CheckModeStatus.Text = "存在故障!";
  7309. label_CheckModeResult.BackColor = Color.Red;
  7310. label_CheckModeResult.Text = "测试异常";
  7311. Delay_ms(500);
  7312. //存储异常并上传
  7313. CheckMode_Stop(false);
  7314. return;
  7315. }
  7316. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  7317. Delay_ms(500);
  7318. //核对SN
  7319. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  7320. {
  7321. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  7322. label_CheckModeStatus.Text = "存在故障!";
  7323. label_CheckModeResult.BackColor = Color.Red;
  7324. label_CheckModeResult.Text = "测试异常";
  7325. Delay_ms(500);
  7326. //存储异常并上传
  7327. CheckMode_Stop(false);
  7328. return;
  7329. }
  7330. label_CheckModeSN.BackColor = Color.Green;
  7331. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  7332. Delay_ms(500);
  7333. }
  7334. else
  7335. {
  7336. label_CheckModeSN.BackColor = Color.Yellow;
  7337. label_CheckModeStatus.Text = "跳过打标信息确认";
  7338. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  7339. Delay_ms(500);
  7340. }
  7341. //参数检验
  7342. if (checkBox_CheckModeCfg.Checked)
  7343. {
  7344. //读取配置文件信息
  7345. label_CheckModeStatus.Text = "参数检查";
  7346. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  7347. //配置文件
  7348. List<byte[]> CmdList = new List<byte[]>();
  7349. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  7350. //从服务器下载文件
  7351. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  7352. {
  7353. string SelectFile = "";
  7354. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  7355. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  7356. {
  7357. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  7358. }
  7359. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  7360. //打开文件
  7361. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  7362. ConfigCmd.Clear();
  7363. while (streamReader.Peek() != -1)
  7364. {
  7365. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  7366. if (fileLineInfo.Contains("["))
  7367. {
  7368. if (fileLineInfo.Contains("助力参数"))
  7369. {
  7370. fileLineInfo = streamReader.ReadLine();
  7371. }
  7372. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  7373. }
  7374. }
  7375. streamReader.Close();
  7376. }
  7377. //从本地加载文件
  7378. else
  7379. {
  7380. string SelectFile = "";
  7381. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  7382. //打开文件
  7383. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  7384. ConfigCmd.Clear();
  7385. while (streamReader.Peek() != -1)
  7386. {
  7387. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  7388. if (fileLineInfo.Contains("["))
  7389. {
  7390. if (fileLineInfo.Contains("助力参数"))
  7391. {
  7392. fileLineInfo = streamReader.ReadLine();
  7393. }
  7394. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  7395. }
  7396. }
  7397. streamReader.Close();
  7398. }
  7399. int CmdNum = ConfigCmd.Count(); //指令个数
  7400. Delay_ms(500);
  7401. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  7402. Delay_ms(500);
  7403. //逐条读取比较
  7404. try
  7405. {
  7406. foreach (string key in ConfigCmd.Keys)
  7407. {
  7408. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  7409. CmdRevStrTemp = "";
  7410. if (key.Contains("曲线"))
  7411. {
  7412. byte LineNum = 0;
  7413. var code = new byte[4];
  7414. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  7415. if (LineNum <= 5)
  7416. {
  7417. code[0] = (byte)(LineNum & 0xFF);
  7418. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7419. code[2] = (byte)(LineNum & 0xFF);
  7420. code[3] = (byte)((LineNum >> 8) & 0xFF);
  7421. }
  7422. else
  7423. {
  7424. code[0] = (byte)(LineNum & 0xFF);
  7425. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7426. code[2] = (byte)(5 & 0xFF);
  7427. code[3] = (byte)((5 >> 8) & 0xFF);
  7428. }
  7429. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  7430. }
  7431. else
  7432. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  7433. Delay_ms(500);
  7434. if (CmdRevStrTemp == string.Empty)
  7435. {
  7436. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  7437. label_CheckModeStatus.Text = "存在故障!";
  7438. label_CheckModeResult.BackColor = Color.Red;
  7439. label_CheckModeResult.Text = "测试异常";
  7440. Delay_ms(500);
  7441. //存储异常并上传
  7442. CheckMode_Stop(false);
  7443. return;
  7444. }
  7445. //比较当前指令,读取的配置文件和返回数据比较
  7446. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  7447. string ParamRead = "";
  7448. if (string.Compare(key, "[其它传感器参数]") == 0)
  7449. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //该指令包含力矩参数
  7450. else
  7451. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim();
  7452. if (ParamWrite.Contains(ParamRead))
  7453. {
  7454. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  7455. continue;
  7456. }
  7457. else
  7458. {
  7459. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  7460. label_CheckModeStatus.Text = "存在故障!";
  7461. label_CheckModeResult.BackColor = Color.Red;
  7462. label_CheckModeResult.Text = "测试异常";
  7463. Delay_ms(500);
  7464. //存储异常并上传
  7465. CheckMode_Stop(false);
  7466. return;
  7467. }
  7468. }
  7469. }
  7470. catch (System.Exception)
  7471. {
  7472. timer_1s.Enabled = false;
  7473. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7474. timer_1s.Enabled = true;
  7475. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  7476. }
  7477. }
  7478. else
  7479. {
  7480. label_CheckModeCfg.BackColor = Color.Yellow;
  7481. label_CheckModeStatus.Text = "跳过参数检验";
  7482. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  7483. Delay_ms(500);
  7484. }
  7485. label_CheckModeCfg.BackColor = Color.Green;
  7486. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  7487. Delay_ms(500);
  7488. //读取力矩传感器
  7489. do
  7490. {
  7491. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  7492. //发送指令读取力矩传感器标定数据
  7493. CmdRevStrTemp = "";
  7494. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  7495. ACK_WaitCnt = 0;
  7496. while (ACK_WaitCnt <= 2) ; //1s
  7497. if (CmdRevStrTemp == "---")
  7498. {
  7499. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  7500. label_CheckModeStatus.Text = "存在故障!";
  7501. label_CheckModeResult.BackColor = Color.Red;
  7502. label_CheckModeResult.Text = "测试异常";
  7503. Delay_ms(500);
  7504. //存储异常并上传
  7505. CheckMode_Stop(false);
  7506. return;
  7507. }
  7508. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  7509. //取力矩传感器数据
  7510. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  7511. ushort MaxTorque;
  7512. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  7513. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  7514. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  7515. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  7516. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  7517. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  7518. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  7519. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  7520. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  7521. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  7522. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  7523. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  7524. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  7525. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  7526. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  7527. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  7528. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  7529. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  7530. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  7531. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  7532. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  7533. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  7534. //传感器标定检验
  7535. if (checkBox_CheckModeTorque.Checked)
  7536. {
  7537. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  7538. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  7539. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  7540. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  7541. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  7542. //与设置值比较
  7543. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  7544. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  7545. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  7546. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  7547. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  7548. )
  7549. {
  7550. label_CheckModeTorque.BackColor = Color.Green;
  7551. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  7552. Delay_ms(500);
  7553. }
  7554. else
  7555. {
  7556. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  7557. label_CheckModeStatus.Text = "存在故障!";
  7558. label_CheckModeResult.BackColor = Color.Red;
  7559. label_CheckModeResult.Text = "测试异常";
  7560. Delay_ms(500);
  7561. //存储异常并上传
  7562. CheckMode_Stop(false);
  7563. return;
  7564. }
  7565. }
  7566. else
  7567. {
  7568. label_CheckModeFWVer.BackColor = Color.Yellow;
  7569. label_CheckModeStatus.Text = "跳过传感器标定检验";
  7570. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  7571. Delay_ms(500);
  7572. }
  7573. } while (false);
  7574. //读取MOS内阻校准参数
  7575. do
  7576. {
  7577. if (checkBox_CheckModeMos.Checked)
  7578. {
  7579. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  7580. //读取显示校准返回数据
  7581. foreach (Control c in groupBox21.Controls)
  7582. {
  7583. if (c is TextBox)
  7584. c.Text = "";
  7585. }
  7586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7587. ACK_WaitCnt = 0;
  7588. while (ACK_WaitCnt <= 2) ; //1s
  7589. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  7590. {
  7591. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  7592. label_CheckModeStatus.Text = "存在故障!";
  7593. label_CheckModeResult.BackColor = Color.Red;
  7594. label_CheckModeResult.Text = "测试异常";
  7595. Delay_ms(500);
  7596. //存储异常并上传
  7597. CheckMode_Stop(false);
  7598. return;
  7599. }
  7600. else
  7601. {
  7602. 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");
  7603. }
  7604. //与校准返回数据对比
  7605. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  7606. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  7607. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  7608. 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])) &&
  7609. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  7610. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  7611. )
  7612. {
  7613. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  7614. label_CheckModeMos.BackColor = Color.Green;
  7615. }
  7616. else
  7617. {
  7618. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  7619. label_CheckModeStatus.Text = "存在故障!";
  7620. label_CheckModeResult.BackColor = Color.Red;
  7621. label_CheckModeResult.Text = "测试异常";
  7622. Delay_ms(500);
  7623. //存储异常并上传
  7624. CheckMode_Stop(false);
  7625. return;
  7626. }
  7627. }
  7628. else
  7629. {
  7630. label_CheckModeMos.BackColor = Color.Yellow;
  7631. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  7632. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  7633. Delay_ms(500);
  7634. }
  7635. } while (false);
  7636. //测试合格
  7637. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7638. label_CheckModeStatus.Text = "测试结束!";
  7639. label_CheckModeResult.BackColor = Color.Green;
  7640. label_CheckModeResult.Text = "测试合格";
  7641. Delay_ms(500);
  7642. //存储并上传
  7643. CheckMode_Stop(true);
  7644. return;
  7645. }
  7646. private void CheckModeLabelInit()
  7647. {
  7648. //测试状态标签
  7649. label_CheckModeResult.BackColor = Color.Yellow;
  7650. label_CheckModeResult.Text = "测试中";
  7651. //测试过程标签
  7652. label_CheckModeStatus.Text = "测试就绪";
  7653. //测试结果标签
  7654. foreach (Control c in groupBox31.Controls)
  7655. {
  7656. if (c is Label)
  7657. {
  7658. if (c.Text == string.Empty)
  7659. c.BackColor = Color.Red;
  7660. }
  7661. }
  7662. }
  7663. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  7664. {
  7665. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  7666. }
  7667. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  7668. {
  7669. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  7670. }
  7671. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  7672. {
  7673. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  7674. UInt32 hour = Time / 3600;
  7675. UInt32 min = (Time % 3600) / 60;
  7676. UInt32 s = (Time % 60);
  7677. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  7678. }
  7679. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  7680. {
  7681. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  7682. richTextBox_CheckModeLog.ScrollToCaret();
  7683. }
  7684. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  7685. {
  7686. TorqueParamsForm.ShowDialog();
  7687. }
  7688. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  7689. {
  7690. if (e.KeyCode == Keys.Enter)
  7691. CheckTestStart();
  7692. }
  7693. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  7694. {
  7695. if (e.KeyCode == Keys.Enter)
  7696. TestStart();
  7697. }
  7698. private void button_SpeedDec10_Click(object sender, EventArgs e)
  7699. {
  7700. if (numericUpDown_SpeedAdj.Value <= 10)
  7701. numericUpDown_SpeedAdj.Value = 0;
  7702. else
  7703. numericUpDown_SpeedAdj.Value -= 10;
  7704. }
  7705. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  7706. {
  7707. if (numericUpDown_SpeedAdj.Value >= 90)
  7708. numericUpDown_SpeedAdj.Value = 100;
  7709. else
  7710. numericUpDown_SpeedAdj.Value += 10;
  7711. }
  7712. private void button_SpeedDec1_Click(object sender, EventArgs e)
  7713. {
  7714. if (numericUpDown_SpeedAdj.Value <= 1)
  7715. numericUpDown_SpeedAdj.Value = 0;
  7716. else
  7717. numericUpDown_SpeedAdj.Value -= 1;
  7718. }
  7719. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  7720. {
  7721. if(numericUpDown_SpeedAdj.Value >= 99)
  7722. numericUpDown_SpeedAdj.Value = 100;
  7723. else
  7724. numericUpDown_SpeedAdj.Value += 1;
  7725. }
  7726. bool WriteLockStatus = true;
  7727. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  7728. {
  7729. if (WriteLockStatus == true)
  7730. {
  7731. EnterForm1.ShowDialog();
  7732. try
  7733. {
  7734. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7735. {
  7736. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7737. {
  7738. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  7739. foreach (Control c in groupBox2.Controls)
  7740. {
  7741. if (c is CheckBox)
  7742. c.Enabled = true;
  7743. }
  7744. WriteLockStatus = !WriteLockStatus;
  7745. }
  7746. else
  7747. {
  7748. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7749. }
  7750. }
  7751. else
  7752. {
  7753. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7754. }
  7755. }
  7756. catch (Exception)
  7757. {
  7758. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7759. }
  7760. }
  7761. else
  7762. {
  7763. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7764. foreach (Control c in groupBox2.Controls)
  7765. {
  7766. if (c is CheckBox)
  7767. c.Enabled = false;
  7768. }
  7769. WriteLockStatus = !WriteLockStatus;
  7770. }
  7771. }
  7772. bool ReadLockStatus = true;
  7773. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  7774. {
  7775. if (ReadLockStatus == true)
  7776. {
  7777. EnterForm1.ShowDialog();
  7778. try
  7779. {
  7780. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7781. {
  7782. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7783. {
  7784. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  7785. foreach (Control c in groupBox29.Controls)
  7786. {
  7787. if (c is CheckBox)
  7788. c.Enabled = true;
  7789. }
  7790. ReadLockStatus = !ReadLockStatus;
  7791. }
  7792. else
  7793. {
  7794. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7795. }
  7796. }
  7797. else
  7798. {
  7799. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7800. }
  7801. }
  7802. catch (Exception)
  7803. {
  7804. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7805. }
  7806. }
  7807. else
  7808. {
  7809. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7810. foreach (Control c in groupBox29.Controls)
  7811. {
  7812. if (c is CheckBox)
  7813. c.Enabled = false;
  7814. }
  7815. ReadLockStatus = !ReadLockStatus;
  7816. }
  7817. }
  7818. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  7819. {
  7820. System.Diagnostics.Process.Start("osk.exe");
  7821. }
  7822. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  7823. {
  7824. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  7825. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  7826. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  7827. }
  7828. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  7829. {
  7830. comboBox_FacModeCfgDate.SelectedIndex = -1;
  7831. comboBox_FacModeCfgFile.SelectedIndex = -1;
  7832. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  7833. }
  7834. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  7835. {
  7836. VersionForm.ShowDialog();
  7837. }
  7838. private void button_MOS_Cal_Click(object sender, EventArgs e)
  7839. {
  7840. textBox_MOS_R1.Text = "";
  7841. textBox_MOS_R2.Text = "";
  7842. textBox_MOS_R3.Text = "";
  7843. try
  7844. {
  7845. var Code = new byte[18];
  7846. for (int i = 0; i < 18; i++)
  7847. Code[i] = 0;
  7848. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  7849. ushort uwDataTemp = 0;
  7850. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  7851. Code[2] = (byte)(uwDataTemp & 0xFF);
  7852. Code[3] = (byte)(uwDataTemp >> 8);
  7853. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  7854. Code[4] = (byte)(uwDataTemp & 0xFF);
  7855. Code[5] = (byte)(uwDataTemp >> 8);
  7856. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  7857. Code[6] = (byte)(uwDataTemp & 0xFF);
  7858. Code[7] = (byte)(uwDataTemp >> 8);
  7859. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  7860. Code[8] = (byte)(uwDataTemp & 0xFF);
  7861. Code[9] = (byte)(uwDataTemp >> 8);
  7862. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  7863. Code[10] = (byte)(uwDataTemp & 0xFF);
  7864. Code[11] = (byte)(uwDataTemp >> 8);
  7865. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  7866. }
  7867. catch (Exception)
  7868. {
  7869. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7870. }
  7871. }
  7872. private void button_MOS_Read_Click(object sender, EventArgs e)
  7873. {
  7874. foreach (Control c in groupBox21.Controls)
  7875. {
  7876. if (c is TextBox)
  7877. c.Text = "";
  7878. }
  7879. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7880. }
  7881. private void button_MOS_Write_Click(object sender, EventArgs e)
  7882. {
  7883. try
  7884. {
  7885. var Code = new byte[34];
  7886. for (int i = 0; i < 34; i++)
  7887. Code[i] = 0;
  7888. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  7889. ushort uwDataTemp = 0;
  7890. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  7891. Code[2] = (byte)(uwDataTemp & 0xFF);
  7892. Code[3] = (byte)(uwDataTemp >> 8);
  7893. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  7894. Code[4] = (byte)(uwDataTemp & 0xFF);
  7895. Code[5] = (byte)(uwDataTemp >> 8);
  7896. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  7897. Code[6] = (byte)(uwDataTemp & 0xFF);
  7898. Code[7] = (byte)(uwDataTemp >> 8);
  7899. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  7900. Code[8] = (byte)(uwDataTemp & 0xFF);
  7901. Code[9] = (byte)(uwDataTemp >> 8);
  7902. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  7903. Code[10] = (byte)(uwDataTemp & 0xFF);
  7904. Code[11] = (byte)(uwDataTemp >> 8);
  7905. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  7906. Code[12] = (byte)(uwDataTemp & 0xFF);
  7907. Code[13] = (byte)(uwDataTemp >> 8);
  7908. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  7909. Code[14] = (byte)(uwDataTemp & 0xFF);
  7910. Code[15] = (byte)(uwDataTemp >> 8);
  7911. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  7912. Code[16] = (byte)(uwDataTemp & 0xFF);
  7913. Code[17] = (byte)(uwDataTemp >> 8);
  7914. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  7915. }
  7916. catch (Exception)
  7917. {
  7918. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7919. }
  7920. }
  7921. /// <summary>
  7922. /// 测试模式点击文本框自动全选
  7923. /// </summary>
  7924. /// <param name="sender"></param>
  7925. /// <param name="e"></param>
  7926. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  7927. {
  7928. textBox_FacModeScan.SelectAll();
  7929. }
  7930. /// <summary>
  7931. /// 检验模式点击文本框自动全选
  7932. /// </summary>
  7933. /// <param name="sender"></param>
  7934. /// <param name="e"></param>
  7935. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  7936. {
  7937. textBox_CheckModeScan.SelectAll();
  7938. }
  7939. /// <summary>
  7940. /// 鼠标放置显示连接服务器信息
  7941. /// </summary>
  7942. /// <param name="sender"></param>
  7943. /// <param name="e"></param>
  7944. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  7945. {
  7946. // 创建the ToolTip
  7947. ToolTip toolTip1 = new ToolTip();
  7948. // 设置显示样式
  7949. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  7950. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  7951. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  7952. toolTip1.ShowAlways = true;//是否显示提示框
  7953. if (myFtp.IsNetConnected)
  7954. {
  7955. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + toolStripTextBox_ServerIP.Text);//设置故障内容显示
  7956. }
  7957. else
  7958. {
  7959. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  7960. }
  7961. }
  7962. /// <summary>
  7963. /// UART协议类型修改
  7964. /// </summary>
  7965. /// <param name="sender"></param>
  7966. /// <param name="e"></param>
  7967. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  7968. {
  7969. var Code = new byte[2];
  7970. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  7971. Code[1] = 0x00;
  7972. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7973. }
  7974. /// <summary>
  7975. /// 显示本机信息
  7976. /// </summary>
  7977. /// <param name="sender"></param>
  7978. /// <param name="e"></param>
  7979. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  7980. {
  7981. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  7982. }
  7983. /// <summary>
  7984. /// 量产模式删除当前选中文件
  7985. /// </summary>
  7986. /// <param name="sender"></param>
  7987. /// <param name="e"></param>
  7988. private void label112_DoubleClick(object sender, EventArgs e)
  7989. {
  7990. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7991. {
  7992. EnterForm1.ShowDialog();
  7993. try
  7994. {
  7995. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7996. {
  7997. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  7998. {
  7999. try
  8000. {
  8001. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  8002. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  8003. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  8004. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8005. }
  8006. catch (Exception)
  8007. {
  8008. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8009. }
  8010. }
  8011. else
  8012. {
  8013. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8014. }
  8015. }
  8016. }
  8017. catch (Exception)
  8018. {
  8019. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8020. }
  8021. }
  8022. }
  8023. /// <summary>
  8024. /// 检验模式删除当前选中文件
  8025. /// </summary>
  8026. /// <param name="sender"></param>
  8027. /// <param name="e"></param>
  8028. private void label138_DoubleClick(object sender, EventArgs e)
  8029. {
  8030. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8031. {
  8032. EnterForm1.ShowDialog();
  8033. try
  8034. {
  8035. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8036. {
  8037. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8038. {
  8039. try
  8040. {
  8041. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  8042. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  8043. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  8044. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8045. }
  8046. catch (Exception)
  8047. {
  8048. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8049. }
  8050. }
  8051. else
  8052. {
  8053. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8054. }
  8055. }
  8056. }
  8057. catch (Exception)
  8058. {
  8059. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8060. }
  8061. }
  8062. }
  8063. /// <summary>
  8064. /// 读取整车信息2
  8065. /// </summary>
  8066. /// <param name="sender"></param>
  8067. /// <param name="e"></param>
  8068. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  8069. {
  8070. richTextBox_BikeParam2.Clear();
  8071. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  8072. }
  8073. /// <summary>
  8074. /// 写入整车信息2
  8075. /// </summary>
  8076. /// <param name="sender"></param>
  8077. /// <param name="e"></param>
  8078. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  8079. {
  8080. var ConfigParam = new byte[34];
  8081. for (int i = 0; i < 34; i++)
  8082. ConfigParam[i] = 0;
  8083. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8084. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8085. try
  8086. {
  8087. for (int i = 0; i < strDataTemp.Length; i++)
  8088. {
  8089. short wDataTemp = 0;
  8090. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8091. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8092. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  8093. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  8094. }
  8095. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  8096. }
  8097. catch (Exception)
  8098. {
  8099. timer_1s.Enabled = false;
  8100. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8101. timer_1s.Enabled = true;
  8102. }
  8103. }
  8104. /// <summary>
  8105. /// 读取用户骑行参数
  8106. /// </summary>
  8107. /// <param name="sender"></param>
  8108. /// <param name="e"></param>
  8109. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  8110. {
  8111. richTextBox_UsrRidesParam.Clear();
  8112. if (checkBox_UserRideParam_OBC.Checked)
  8113. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  8114. else
  8115. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  8116. }
  8117. /// <summary>
  8118. /// 写入用户骑行参数
  8119. /// </summary>
  8120. /// <param name="sender"></param>
  8121. /// <param name="e"></param>
  8122. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  8123. {
  8124. var ConfigParam = new byte[34];
  8125. for (int i = 0; i < 34; i++)
  8126. ConfigParam[i] = 0;
  8127. if (checkBox_UserRideParam_OBC.Checked)
  8128. {
  8129. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8130. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8131. try
  8132. {
  8133. for (int i = 0; i < strDataTemp.Length; i++)
  8134. {
  8135. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  8136. }
  8137. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  8138. }
  8139. catch (Exception)
  8140. {
  8141. timer_1s.Enabled = false;
  8142. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8143. timer_1s.Enabled = true;
  8144. }
  8145. }
  8146. else
  8147. {
  8148. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8149. try
  8150. {
  8151. for (int i = 0; i < strDataTemp.Length; i++)
  8152. {
  8153. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  8154. }
  8155. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  8156. }
  8157. catch (Exception)
  8158. {
  8159. timer_1s.Enabled = false;
  8160. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8161. timer_1s.Enabled = true;
  8162. }
  8163. }
  8164. }
  8165. /// <summary>
  8166. /// 读取产品标签
  8167. /// </summary>
  8168. /// <param name="sender"></param>
  8169. /// <param name="e"></param>
  8170. private void button_ReadTag_Click(object sender, EventArgs e)
  8171. {
  8172. textBox_TagInfo.Text = "---";
  8173. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  8174. }
  8175. /// <summary>
  8176. /// 写入产品标签
  8177. /// </summary>
  8178. /// <param name="sender"></param>
  8179. /// <param name="e"></param>
  8180. private void button_WriteTag_Click(object sender, EventArgs e)
  8181. {
  8182. string User = textBox_TagInfo.Text;
  8183. var UserArray = new byte[32];
  8184. for (ushort i = 0; i < User.Length; i++)
  8185. {
  8186. UserArray[i] = (byte)User[i];
  8187. }
  8188. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  8189. }
  8190. /// <summary>
  8191. /// 上位机读取骑行历史
  8192. /// </summary>
  8193. /// <param name="sender"></param>
  8194. /// <param name="e"></param>
  8195. private void button_ReadRideLog_Click(object sender, EventArgs e)
  8196. {
  8197. textBox_ODO_KM.Text = "---";
  8198. textBox_ODO_TIME.Text = "---";
  8199. textBox_TRIP_KM.Text = "---";
  8200. textBox_TRIP_TIME.Text = "---";
  8201. textBox_OBC_TRIP_KM.Text = "";
  8202. textBox_OBC_TRIP_TIME.Text = "";
  8203. textBox_OBC_ODO_KM.Text = "";
  8204. textBox_OBC_ODO_TIME.Text = "";
  8205. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  8206. }
  8207. /// <summary>
  8208. /// 上位机写入骑行历史
  8209. /// </summary>
  8210. /// <param name="sender"></param>
  8211. /// <param name="e"></param>
  8212. private void button_WriteRideLog_Click(object sender, EventArgs e)
  8213. {
  8214. UInt32 Data;
  8215. var UserArray = new byte[16];
  8216. try
  8217. {
  8218. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  8219. UserArray[0] = (byte)(Data & 0xFF);
  8220. UserArray[1] = (byte)(Data >> 8);
  8221. UserArray[2] = (byte)(Data >> 16);
  8222. UserArray[3] = (byte)(Data >> 24);
  8223. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  8224. UserArray[4] = (byte)(Data & 0xFF);
  8225. UserArray[5] = (byte)(Data >> 8);
  8226. UserArray[6] = (byte)(Data >> 16);
  8227. UserArray[7] = (byte)(Data >> 24);
  8228. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  8229. UserArray[8] = (byte)(Data & 0xFF);
  8230. UserArray[9] = (byte)(Data >> 8);
  8231. UserArray[10] = (byte)(Data >> 16);
  8232. UserArray[11] = (byte)(Data >> 24);
  8233. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  8234. UserArray[12] = (byte)(Data & 0xFF);
  8235. UserArray[13] = (byte)(Data >> 8);
  8236. UserArray[14] = (byte)(Data >> 16);
  8237. UserArray[15] = (byte)(Data >> 24);
  8238. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  8239. }
  8240. catch (Exception ex)
  8241. {
  8242. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8243. }
  8244. }
  8245. /// <summary>
  8246. /// 获取删除配置文件日期列表
  8247. /// </summary>
  8248. /// <param name="sender"></param>
  8249. /// <param name="e"></param>
  8250. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  8251. {
  8252. string[] DateList = { "" };
  8253. //网络断开时直接退出
  8254. if (!myFtp.IsNetConnected)
  8255. return;
  8256. //从服务器更新日期列表
  8257. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  8258. toolStripTextBox_DelCfgFile.Items.Clear();
  8259. //日期列表加载,显示最近30条
  8260. if (DateList.Length > 30)
  8261. {
  8262. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  8263. toolStripTextBox_DelCfgFile.Items.Add("-----");
  8264. }
  8265. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  8266. {
  8267. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  8268. }
  8269. }
  8270. /// <summary>
  8271. /// 删除指定配置文件
  8272. /// </summary>
  8273. /// <param name="sender"></param>
  8274. /// <param name="e"></param>
  8275. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  8276. {
  8277. //提示输入文件名
  8278. Scan scan_form = new Scan();
  8279. scan_form.ShowDialog();
  8280. do
  8281. {
  8282. if (scan_form.textBox_Scan.Text == string.Empty)
  8283. {
  8284. timer_1s.Enabled = false;
  8285. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8286. timer_1s.Enabled = true;
  8287. break;
  8288. }
  8289. string DelFile = scan_form.textBox_Scan.Text;
  8290. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8291. {
  8292. EnterForm1.ShowDialog();
  8293. try
  8294. {
  8295. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8296. {
  8297. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8298. {
  8299. try
  8300. {
  8301. if (DelFile.Contains("."))
  8302. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  8303. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  8304. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  8305. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  8306. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8307. }
  8308. catch (Exception)
  8309. {
  8310. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8311. }
  8312. }
  8313. else
  8314. {
  8315. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8316. }
  8317. }
  8318. }
  8319. catch (Exception)
  8320. {
  8321. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8322. }
  8323. }
  8324. } while (false);
  8325. }
  8326. /// <summary>
  8327. /// 获取删除样机测试记录日期列表
  8328. /// </summary>
  8329. /// <param name="sender"></param>
  8330. /// <param name="e"></param>
  8331. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  8332. {
  8333. string[] DateList = { "" };
  8334. //网络断开时直接退出
  8335. if (!myFtp.IsNetConnected)
  8336. return;
  8337. //从服务器更新日期列表
  8338. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  8339. toolStripTextBox_DelLogFile.Items.Clear();
  8340. //日期列表加载,显示最近30天
  8341. if (DateList.Length > 30)
  8342. {
  8343. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  8344. toolStripTextBox_DelLogFile.Items.Add("-----");
  8345. }
  8346. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  8347. {
  8348. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  8349. }
  8350. }
  8351. /// <summary>
  8352. /// 删除指定的样机测试记录
  8353. /// </summary>
  8354. /// <param name="sender"></param>
  8355. /// <param name="e"></param>
  8356. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  8357. {
  8358. //提示输入文件名
  8359. Scan scan_form = new Scan();
  8360. scan_form.ShowDialog();
  8361. do
  8362. {
  8363. if (scan_form.textBox_Scan.Text == string.Empty)
  8364. {
  8365. timer_1s.Enabled = false;
  8366. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8367. timer_1s.Enabled = true;
  8368. break;
  8369. }
  8370. string DelFile = scan_form.textBox_Scan.Text;
  8371. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8372. {
  8373. EnterForm1.ShowDialog();
  8374. try
  8375. {
  8376. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8377. {
  8378. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8379. {
  8380. try
  8381. {
  8382. //删除指定目录下面所有文件和文件夹
  8383. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  8384. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  8385. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8386. }
  8387. catch (Exception)
  8388. {
  8389. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8390. }
  8391. }
  8392. else
  8393. {
  8394. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8395. }
  8396. }
  8397. }
  8398. catch (Exception)
  8399. {
  8400. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8401. }
  8402. }
  8403. } while (false);
  8404. }
  8405. /// <summary>
  8406. /// CAN协议选择
  8407. /// </summary>
  8408. /// <param name="sender"></param>
  8409. /// <param name="e"></param>
  8410. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  8411. {
  8412. cANToolStripMenuItem.Checked= true;
  8413. uARTToolStripMenuItem.Checked = false;
  8414. UART协议ToolStripMenuItem.Visible = false;
  8415. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8416. }
  8417. /// <summary>
  8418. /// UART协议选择
  8419. /// </summary>
  8420. /// <param name="sender"></param>
  8421. /// <param name="e"></param>
  8422. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  8423. {
  8424. cANToolStripMenuItem.Checked = false;
  8425. uARTToolStripMenuItem.Checked = true;
  8426. UART协议ToolStripMenuItem.Visible = true;
  8427. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8428. }
  8429. /// <summary>
  8430. /// 清除流水号
  8431. /// </summary>
  8432. /// <param name="sender"></param>
  8433. /// <param name="e"></param>
  8434. private void label131_DoubleClick(object sender, EventArgs e)
  8435. {
  8436. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8437. {
  8438. label_FacModeSerial.Text = "0";
  8439. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  8440. }
  8441. }
  8442. /// <summary>
  8443. /// 清除流水号
  8444. /// </summary>
  8445. /// <param name="sender"></param>
  8446. /// <param name="e"></param>
  8447. private void label135_DoubleClick(object sender, EventArgs e)
  8448. {
  8449. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8450. {
  8451. label_CheckModeSerial.Text = "0";
  8452. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  8453. }
  8454. }
  8455. }
  8456. }