mainForm.cs 452 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617
  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.2";
  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. //指令窗口显示
  77. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  78. #endregion
  79. #region 故障日志结构体定义
  80. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  81. [StructLayout(LayoutKind.Sequential)]
  82. public struct MC_ErrorLogSaveInfo_Struct_t
  83. {
  84. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  85. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  86. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  87. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  88. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  89. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  90. //电机运行信息,占用空间32bytes
  91. [StructLayout(LayoutKind.Sequential)]
  92. public struct MC_RunInfo_Struct_t
  93. {
  94. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  95. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  96. public ushort Power; //电功率 1W,地址偏移4
  97. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  98. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  99. public byte Cadence; //踏频 1rpm,地址偏移10
  100. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  101. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  102. public byte GearSt; //助力档位,地址偏移13
  103. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  104. public byte SOC; //剩余电量 1%,地址偏移15
  105. public ushort RemainDistance; //续航里程 1km,地址偏移16
  106. public ushort Torque_AD; //力矩寄存器,地址偏移18
  107. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  108. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  109. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  110. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  111. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  112. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  113. public UInt32 RS; //预留 4bytes
  114. };
  115. [MarshalAs(UnmanagedType.Struct)]
  116. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  117. //控制变量
  118. public Int16 IqCurrent; //Pu, 地址偏移 48
  119. public Int16 IqVoltage; //Pu, 地址偏移 50
  120. public Int16 IdCurrent; //Pu, 地址偏移 52
  121. public Int16 IdVoltage; //Pu, 地址偏移 54
  122. //状态机
  123. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  124. //预留
  125. public UInt16 RS1;
  126. public UInt16 RS2;
  127. public UInt16 RS3;
  128. };
  129. #endregion
  130. #region 屏幕缩放比例获取
  131. public class PrimaryScreen
  132. {
  133. #region Win32 API
  134. [DllImport("user32.dll")]
  135. static extern IntPtr GetDC(IntPtr ptr);
  136. [DllImport("gdi32.dll")]
  137. static extern int GetDeviceCaps(
  138. IntPtr hdc, // handle to DC
  139. int nIndex // index of capability
  140. );
  141. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  142. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  143. #endregion
  144. #region DeviceCaps常量
  145. const int HORZRES = 8;
  146. const int VERTRES = 10;
  147. const int LOGPIXELSX = 88;
  148. const int LOGPIXELSY = 90;
  149. const int DESKTOPVERTRES = 117;
  150. const int DESKTOPHORZRES = 118;
  151. #endregion
  152. #region 属性
  153. /// <summary>
  154. /// 获取屏幕分辨率当前物理大小
  155. /// </summary>
  156. public static Size WorkingArea
  157. {
  158. get
  159. {
  160. IntPtr hdc = GetDC(IntPtr.Zero);
  161. Size size = new Size();
  162. size.Width = GetDeviceCaps(hdc, HORZRES);
  163. size.Height = GetDeviceCaps(hdc, VERTRES);
  164. ReleaseDC(IntPtr.Zero, hdc);
  165. return size;
  166. }
  167. }
  168. /// <summary>
  169. /// 当前系统DPI_X 大小 一般为96
  170. /// </summary>
  171. public static int DpiX
  172. {
  173. get
  174. {
  175. IntPtr hdc = GetDC(IntPtr.Zero);
  176. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  177. ReleaseDC(IntPtr.Zero, hdc);
  178. return DpiX;
  179. }
  180. }
  181. /// <summary>
  182. /// 当前系统DPI_Y 大小 一般为96
  183. /// </summary>
  184. public static int DpiY
  185. {
  186. get
  187. {
  188. IntPtr hdc = GetDC(IntPtr.Zero);
  189. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  190. ReleaseDC(IntPtr.Zero, hdc);
  191. return DpiX;
  192. }
  193. }
  194. /// <summary>
  195. /// 获取真实设置的桌面分辨率大小
  196. /// </summary>
  197. public static Size DESKTOP
  198. {
  199. get
  200. {
  201. IntPtr hdc = GetDC(IntPtr.Zero);
  202. Size size = new Size();
  203. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  204. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  205. ReleaseDC(IntPtr.Zero, hdc);
  206. return size;
  207. }
  208. }
  209. /// <summary>
  210. /// 获取宽度缩放百分比
  211. /// </summary>
  212. public static float ScaleX
  213. {
  214. get
  215. {
  216. IntPtr hdc = GetDC(IntPtr.Zero);
  217. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  218. int d = GetDeviceCaps(hdc, HORZRES);
  219. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  220. ReleaseDC(IntPtr.Zero, hdc);
  221. return ScaleX;
  222. }
  223. }
  224. /// <summary>
  225. /// 获取高度缩放百分比
  226. /// </summary>
  227. public static float ScaleY
  228. {
  229. get
  230. {
  231. IntPtr hdc = GetDC(IntPtr.Zero);
  232. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  233. ReleaseDC(IntPtr.Zero, hdc);
  234. return ScaleY;
  235. }
  236. }
  237. #endregion
  238. }
  239. #endregion
  240. public static mainForm mainform1 = null;
  241. public mainForm()
  242. {
  243. InitializeComponent();
  244. mainform1 = this;
  245. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  246. stopwatch.Start();
  247. //端口初始化
  248. mySerialProcess.Init();
  249. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  250. //检查备忘录文件
  251. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  252. {
  253. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  254. }
  255. //检验流水号记录文件
  256. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  257. {
  258. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  259. }
  260. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  261. {
  262. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  263. }
  264. //检查文件夹
  265. if (!Directory.Exists(localInfo.LocalPath))
  266. {
  267. Directory.CreateDirectory(localInfo.LocalPath);
  268. }
  269. if (!Directory.Exists(localInfo.LocalDataPath))
  270. {
  271. Directory.CreateDirectory(localInfo.LocalDataPath);
  272. }
  273. if (!Directory.Exists(localInfo.ToolsPath))
  274. {
  275. Directory.CreateDirectory(localInfo.ToolsPath);
  276. }
  277. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  278. {
  279. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  280. }
  281. //检查配置文件
  282. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  283. {
  284. //打开文件
  285. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  286. string sLine = "";
  287. ArrayList array_CfgInfo = new ArrayList();
  288. array_CfgInfo.Clear();
  289. while (sLine != null)
  290. {
  291. sLine = objReader.ReadLine();
  292. array_CfgInfo.Add(sLine);
  293. }
  294. objReader.Close();
  295. //解析配置文件
  296. try
  297. {
  298. //Port Set
  299. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  300. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  301. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  302. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  303. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  304. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  305. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  306. //Option
  307. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  308. 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
  309. 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
  310. if (array_CfgInfo[9].ToString().Split(':')[1] == "False")
  311. {
  312. checkBox_OffLineFacMode.Checked = false;
  313. checkBox_OffLineFacMode.Enabled = false;
  314. checkBox_OffLineCheckMode.Checked = false;
  315. checkBox_OffLineCheckMode.Enabled = false;
  316. }
  317. else
  318. {
  319. checkBox_OffLineFacMode.Checked = true;
  320. checkBox_OffLineFacMode.Enabled = true;
  321. checkBox_OffLineCheckMode.Checked = true;
  322. checkBox_OffLineCheckMode.Enabled = true;
  323. }
  324. //Server Set
  325. toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
  326. toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
  327. toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
  328. toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
  329. toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
  330. //MacInfo
  331. toolStripTextBox_MAC.Text = array_CfgInfo[19].ToString().Split(':')[1];
  332. toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
  333. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  334. toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
  335. //Log Address
  336. textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
  337. textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
  338. //电机类型
  339. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[29].ToString().Split(':')[1] == "True");
  340. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  341. //检测阈值
  342. toolStripTextBox_ThVol.Text = array_CfgInfo[33].ToString().Split(':')[1];
  343. toolStripTextBox_ThCur.Text = array_CfgInfo[34].ToString().Split(':')[1];
  344. toolStripTextBox_ThSpeed.Text = array_CfgInfo[35].ToString().Split(':')[1];
  345. toolStripTextBox_ThTor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  346. toolStripTextBox_ThCad.Text = array_CfgInfo[37].ToString().Split(':')[1];
  347. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[38].ToString().Split(':')[1];
  348. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[39].ToString().Split(':')[1];
  349. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[40].ToString().Split(':')[1];
  350. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[41].ToString().Split(':')[1];
  351. //MOS内阻校准系数
  352. toolStripTextBox_MosCalK.Text = array_CfgInfo[44].ToString().Split(':')[1];
  353. toolStripTextBox_MOS1.Text= array_CfgInfo[45].ToString().Split(':')[1];
  354. toolStripTextBox_MOS2.Text = array_CfgInfo[46].ToString().Split(':')[1];
  355. toolStripTextBox_MOS3.Text = array_CfgInfo[47].ToString().Split(':')[1];
  356. //通信协议类型
  357. cANToolStripMenuItem.Checked = (array_CfgInfo[50].ToString().Split(':')[1] == "True");
  358. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  359. //自动更新开关
  360. 打开ToolStripMenuItem.Checked = (array_CfgInfo[54].ToString().Split(':')[1] == "True");
  361. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  362. }
  363. catch (System.Exception)
  364. {
  365. timer_1s.Enabled = false;
  366. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  367. timer_1s.Enabled = true;
  368. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  369. }
  370. }
  371. else //不存在配置文件,生成文件写入默认值
  372. {
  373. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  374. }
  375. //解析本地流水号记录
  376. do
  377. {
  378. //测试模式
  379. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  380. //检验模式
  381. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  382. } while (false);
  383. //获取本机信息,读取时间较长,优先从本地文件获取
  384. do
  385. {
  386. try
  387. {
  388. //本地文件为空,读取信息保存
  389. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  390. {
  391. Local_HdInformation = "";
  392. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  393. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  394. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  395. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  396. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  397. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  398. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  399. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  400. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  401. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  402. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  403. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  404. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  405. }
  406. //从本地读取,计算机名和IP地址重新读
  407. else
  408. {
  409. Local_HdInformation = "";
  410. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  411. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  412. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  413. for (int i = 0; i < fileInfo.Length; i++)
  414. Local_HdInformation += fileInfo[i] + "\r\n";
  415. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  416. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  417. }
  418. }
  419. catch(Exception)
  420. {
  421. }
  422. } while (false);
  423. //系统登录
  424. do
  425. {
  426. EnterForm1.ShowDialog();
  427. try
  428. {
  429. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  430. {
  431. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  432. {
  433. //隐藏设置项
  434. 其它配置项ToolStripMenuItem.Visible = false;
  435. 写入存储ToolStripMenuItem.Visible = false;
  436. 离线使用ToolStripMenuItem.Visible = false;
  437. 服务器配置ToolStripMenuItem.Visible = false;
  438. 判断阈值ToolStripMenuItem.Visible = false;
  439. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  440. mOS内阻范围ToolStripMenuItem.Visible = false;
  441. 力矩传感器检验ToolStripMenuItem.Visible = false;
  442. //显示生产信息
  443. 生产信息ToolStripMenuItem.Visible = true;
  444. //显示电机类型,但不可编辑
  445. 电机类型ToolStripMenuItem.Visible = true;
  446. 中置电机ToolStripMenuItem.Enabled = false;
  447. 轮毂电机ToolStripMenuItem.Enabled = false;
  448. if (uARTToolStripMenuItem.Checked)
  449. UART协议ToolStripMenuItem.Visible = true;
  450. //隐藏研发调试界面
  451. tabPage_MotorParam.Parent = null;
  452. tabPage_BikeParam.Parent = null;
  453. tabPage_BikeParam2.Parent = null;
  454. tabPage_ControlParam.Parent = null;
  455. tabPage_SensorParam.Parent = null;
  456. tabPage_AssistParam.Parent = null;
  457. tabPage_UsrRideParam.Parent = null;
  458. tabPage_DebugParam.Parent = null;
  459. tabPage_RecordInfo.Parent = null;
  460. tabPage_OtherInfo.Parent = null;
  461. tabPage_OBC.Parent = null;
  462. tabPage_RAMorFLASH.Parent = null;
  463. tabPage_FactoryMode.Parent = null;
  464. tabPage_DebugInfo.Parent = null;
  465. //显示运行信息
  466. tabPage_RunInfo.Parent = tabControl2;
  467. //根据电机类型修改生产信息和电机类型
  468. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  469. {
  470. 中置电机ToolStripMenuItem.Checked = true;
  471. 轮毂电机ToolStripMenuItem.Checked = false;
  472. toolStripTextBox_MACPD.Text = "MM_MC1";
  473. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  474. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  475. }
  476. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  477. {
  478. 中置电机ToolStripMenuItem.Checked = false;
  479. 轮毂电机ToolStripMenuItem.Checked = true;
  480. toolStripTextBox_MACPD.Text = "GF_250_1";
  481. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  482. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  483. }
  484. //显示对应生产测试界面
  485. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  486. {
  487. tabPage_ProductMode_Write.Parent = tabControl1;
  488. tabPage_ProductMode_Write.Select();
  489. tabPage_ProductMode_Read.Parent = null;
  490. }
  491. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  492. {
  493. tabPage_ProductMode_Read.Parent = tabControl1;
  494. tabPage_ProductMode_Read.Select();
  495. tabPage_ProductMode_Write.Parent = null;
  496. }
  497. //应答指令不提示
  498. ACK_DisFlag = false;
  499. //退出登录
  500. break;
  501. }
  502. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  503. {
  504. //隐藏工作台内容,新建窗口完成配置
  505. groupBox1.Visible = false;
  506. groupBox3.Visible = false;
  507. tabControl2.Visible = false;
  508. //隐藏提示信息
  509. label_StarInfo.Visible = false;
  510. //打开参数配置框
  511. GenerateParamsForm.ShowDialog();
  512. System.Environment.Exit(0);
  513. //退出登录
  514. break;
  515. }
  516. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  517. {
  518. //隐藏量产界面
  519. tabPage_ProductMode_Read.Parent = null;
  520. tabPage_ProductMode_Write.Parent = null;
  521. //隐藏配置项
  522. 其它配置项ToolStripMenuItem.Visible = false;
  523. 离线使用ToolStripMenuItem.Visible = false;
  524. 服务器配置ToolStripMenuItem.Visible = false;
  525. 判断阈值ToolStripMenuItem.Visible = false;
  526. 力矩传感器检验ToolStripMenuItem.Visible = false;
  527. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  528. mOS内阻范围ToolStripMenuItem.Visible = false;
  529. //显示生产信息
  530. 生产信息ToolStripMenuItem.Visible = true;
  531. //显示电机类型,但不可编辑
  532. 电机类型ToolStripMenuItem.Visible = true;
  533. 中置电机ToolStripMenuItem.Enabled = true;
  534. 轮毂电机ToolStripMenuItem.Enabled = true;
  535. if (uARTToolStripMenuItem.Checked)
  536. UART协议ToolStripMenuItem.Visible = true;
  537. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  538. {
  539. 中置电机ToolStripMenuItem.Checked = true;
  540. 轮毂电机ToolStripMenuItem.Checked = false;
  541. toolStripTextBox_MACPD.Text = "MM_MC1";
  542. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  543. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  544. }
  545. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  546. {
  547. 中置电机ToolStripMenuItem.Checked = false;
  548. 轮毂电机ToolStripMenuItem.Checked = true;
  549. toolStripTextBox_MACPD.Text = "GF_250_1";
  550. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  551. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  552. }
  553. //退出登录
  554. break;
  555. }
  556. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  557. {
  558. //隐藏设置项
  559. 其它配置项ToolStripMenuItem.Visible = false;
  560. 写入存储ToolStripMenuItem.Visible = false;
  561. 离线使用ToolStripMenuItem.Visible = false;
  562. 服务器配置ToolStripMenuItem.Visible = false;
  563. 判断阈值ToolStripMenuItem.Visible = false;
  564. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  565. mOS内阻范围ToolStripMenuItem.Visible = false;
  566. 力矩传感器检验ToolStripMenuItem.Visible = false;
  567. //显示生产信息
  568. 生产信息ToolStripMenuItem.Visible = true;
  569. //显示电机类型,但不可编辑
  570. 电机类型ToolStripMenuItem.Visible = false;
  571. 中置电机ToolStripMenuItem.Enabled = false;
  572. 轮毂电机ToolStripMenuItem.Enabled = false;
  573. if (uARTToolStripMenuItem.Checked)
  574. UART协议ToolStripMenuItem.Visible = true;
  575. //隐藏研发调试界面
  576. tabPage_MotorParam.Parent = null;
  577. tabPage_BikeParam.Parent = null;
  578. tabPage_BikeParam2.Parent = null;
  579. tabPage_ControlParam.Parent = null;
  580. tabPage_SensorParam.Parent = null;
  581. tabPage_AssistParam.Parent = null;
  582. tabPage_UsrRideParam.Parent = null;
  583. tabPage_DebugParam.Parent = null;
  584. tabPage_RecordInfo.Parent = null;
  585. tabPage_OtherInfo.Parent = null;
  586. tabPage_OBC.Parent = null;
  587. tabPage_RAMorFLASH.Parent = null;
  588. tabPage_FactoryMode.Parent = null;
  589. tabPage_DebugInfo.Parent = null;
  590. //显示运行信息
  591. tabPage_RunInfo.Parent = tabControl2;
  592. //目前仅轮毂使用
  593. 中置电机ToolStripMenuItem.Checked = false;
  594. 轮毂电机ToolStripMenuItem.Checked = true;
  595. toolStripTextBox_MACPD.Text = "GF_250_1";
  596. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  597. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  598. //显示量产测试界面
  599. tabPage_ProductMode_Write.Parent = tabControl1;
  600. tabPage_ProductMode_Write.Select();
  601. tabPage_ProductMode_Read.Parent = null;
  602. //允许离线使用
  603. 允许ToolStripMenuItem.Checked = false;
  604. 不允许ToolStripMenuItem.Checked = true;
  605. checkBox_OffLineFacMode.Checked = false;
  606. checkBox_OffLineFacMode.Enabled = true;
  607. checkBox_OffLineCheckMode.Checked = false;
  608. checkBox_OffLineCheckMode.Enabled = true;
  609. //应答指令不提示
  610. ACK_DisFlag = false;
  611. //退出登录
  612. break;
  613. }
  614. else if (EnterForm1.comboBox_User.Text == "研发调试")
  615. {
  616. //隐藏量产界面
  617. tabPage_ProductMode_Read.Parent = null;
  618. tabPage_ProductMode_Write.Parent = null;
  619. 服务器配置ToolStripMenuItem.Visible = false;
  620. if (uARTToolStripMenuItem.Checked)
  621. UART协议ToolStripMenuItem.Visible = true;
  622. //退出登录
  623. break;
  624. }
  625. else if (EnterForm1.comboBox_User.Text == "管理员")
  626. {
  627. //不隐藏任何界面
  628. //...
  629. //退出登录
  630. break;
  631. }
  632. else
  633. {
  634. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  635. //重新登录
  636. continue;
  637. }
  638. }
  639. else
  640. {
  641. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  642. //重新登录
  643. continue;
  644. }
  645. }
  646. catch (Exception)
  647. {
  648. System.Environment.Exit(0);
  649. }
  650. } while (true);
  651. //配置网络FTP服务器
  652. myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text, "admin", "ttium_admin");
  653. //创建线程,定时检测网络连接状态
  654. Thread th = new Thread(NetworkCheck);
  655. th.IsBackground = true;
  656. th.Start();
  657. //允许跨线程访问
  658. Control.CheckForIllegalCrossThreadCalls = false;
  659. }
  660. /// <summary>
  661. /// 检查网络状态线程
  662. /// </summary>
  663. private void NetworkCheck()
  664. {
  665. //允许离线使用,直接退出
  666. if (允许ToolStripMenuItem.Checked == true) //允许离线使用
  667. {
  668. timer_1s.Enabled = false;
  669. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  670. timer_1s.Enabled = true;
  671. return;
  672. }
  673. //不允许离线使用,实时监测网络状态
  674. else
  675. {
  676. //初始化第一次连接FTP服务器
  677. bool Result = myFtp.CheckFtp();
  678. if (Result == true)//服务器连接成功
  679. {
  680. myFtp.IsNetConnected = true;
  681. //上传登录日志
  682. do
  683. {
  684. //日志文件名
  685. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  686. string fileName = date;
  687. //日志内容
  688. string fileInfo = Local_HdInformation;
  689. //保存本地
  690. if (!Directory.Exists(localInfo.LocalLogPath))
  691. Directory.CreateDirectory(localInfo.LocalLogPath);
  692. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  693. //上传服务器
  694. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  695. } while (false);
  696. }
  697. else//服务器连接失败
  698. {
  699. myFtp.IsNetConnected = false;
  700. if (EnterForm1.comboBox_User.Text != "管理员")
  701. {
  702. timer_1s.Enabled = false;
  703. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  704. timer_1s.Enabled = true;
  705. this.Close();
  706. }
  707. }
  708. //创建定时器,定时10s检查网络
  709. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  710. timer_CheckNet.Enabled = true;
  711. timer_CheckNet.Interval = 30000;
  712. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  713. timer_CheckNet.Start();
  714. while (true)
  715. {
  716. Thread.Sleep(1);
  717. if (myFtp.IsNetConnected == false)
  718. {
  719. label_Server_ComStatus.Text = "网络已断开";
  720. label_ServerStatus.BackColor = Color.Red;
  721. }
  722. else
  723. {
  724. label_Server_ComStatus.Text = "网络已连接";
  725. label_ServerStatus.BackColor = Color.Green;
  726. }
  727. }
  728. }
  729. }
  730. /// <summary>
  731. /// 线程中定时任务,检查网络状态
  732. /// </summary>
  733. /// <param name="sender"></param>
  734. /// <param name="e"></param>
  735. private void timer_CheckNet_Tick(object sender, EventArgs e)
  736. {
  737. //连接FTP服务器
  738. bool Result = myFtp.CheckFtp();
  739. if (Result == true)//服务器连接成功
  740. {
  741. myFtp.IsNetConnected = true;
  742. //允许使用
  743. groupBox1.Enabled = true;
  744. groupBox3.Enabled = true;
  745. tabControl2.Enabled = true;
  746. }
  747. else//服务器连接失败
  748. {
  749. myFtp.IsNetConnected = false;
  750. if (EnterForm1.comboBox_User.Text != "管理员")
  751. {
  752. timer_1s.Enabled = false;
  753. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  754. timer_1s.Enabled = true;
  755. //禁止使用
  756. groupBox1.Enabled = false;
  757. groupBox3.Enabled = false;
  758. tabControl2.Enabled = false;
  759. }
  760. }
  761. }
  762. #region 非独占性延时函数
  763. public static void Delay_ms(int milliSecond)
  764. {
  765. int start = Environment.TickCount;
  766. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  767. {
  768. Application.DoEvents();
  769. }
  770. }
  771. #endregion
  772. private void MainForm_Load(object sender, System.EventArgs e)
  773. {
  774. //页面初始化
  775. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  776. label_Computername.Text = System.Environment.UserName;
  777. label_UserName.Text = EnterForm1.comboBox_User.Text;
  778. this.Text += Version;
  779. //检查版本,自动更新
  780. do
  781. {
  782. if (打开ToolStripMenuItem.Checked == false)//关闭自动更新
  783. {
  784. break;
  785. }
  786. //检查网络状态
  787. if (myFtp.CheckFtp() == false)
  788. {
  789. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  790. break;
  791. }
  792. else
  793. {
  794. //检查本地文件删除
  795. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  796. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  797. //读取最新版本号
  798. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  799. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  800. string sLine = "";
  801. ArrayList arrText = new ArrayList();//创建一个动态数组
  802. while (sLine != null)
  803. {
  804. sLine = objReader.ReadLine();
  805. arrText.Add(sLine);
  806. }
  807. objReader.Close();
  808. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  809. //检查是否有最新版本
  810. string[] VerOld = mainForm.Version.Trim().Split('.');
  811. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  812. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  813. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  814. if (VerNew_int <= VerOld_int)
  815. {
  816. //版本已是最新,跳出
  817. break;
  818. }
  819. //确认下载最新版本
  820. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  821. {
  822. string SavePath = Directory.GetCurrentDirectory();
  823. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  824. foreach (string file in FileList)
  825. {
  826. if (file.Contains(".exe"))
  827. {
  828. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  829. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  830. System.Environment.Exit(0);
  831. }
  832. }
  833. }
  834. }
  835. } while (false);
  836. //下拉控件初始值设定
  837. comboBox_WorkMode.SelectedIndex = 0;
  838. comboBox_GearSt.SelectedIndex = 0;
  839. comboBox_LightSwitch.SelectedIndex = 1;
  840. comboBox_OBC_SetGearST.SelectedIndex = 0;
  841. comboBox_OBC_LightSw.SelectedIndex = 1;
  842. comboBox_AssistTorque.SelectedIndex = 0;
  843. comboBox_AssistCadence.SelectedIndex = 0;
  844. //combobox事件定义
  845. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  846. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  847. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  848. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  849. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  850. //端口自动连接
  851. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  852. {
  853. try
  854. {
  855. PortConnect();
  856. }
  857. catch (System.Exception)
  858. {
  859. timer_1s.Enabled = false;
  860. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  861. timer_1s.Enabled = true;
  862. }
  863. }
  864. //不识别联动装置盒自动打开界面
  865. #if true
  866. groupBox1.Visible = true;
  867. groupBox3.Visible = true;
  868. tabControl2.Visible = true;
  869. label_StarInfo.Visible = false;
  870. #endif
  871. //创建线程,定时解析数据
  872. Thread th = new Thread(Task_SerialProcess);
  873. th.IsBackground = true;
  874. th.Start();
  875. }
  876. #region 结构体与字节流相互转换
  877. public static class MyConverter
  878. {
  879. /// <summary>
  880. /// 由结构体转换为byte数组
  881. /// </summary>
  882. public static byte[] StructureToByte<T>(T structure)
  883. {
  884. int size = Marshal.SizeOf(typeof(T));
  885. byte[] buffer = new byte[size];
  886. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  887. try
  888. {
  889. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  890. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  891. }
  892. finally
  893. {
  894. Marshal.FreeHGlobal(bufferIntPtr);
  895. }
  896. return buffer;
  897. }
  898. /// <summary>
  899. /// 由byte数组转换为结构体
  900. /// </summary>
  901. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  902. {
  903. object structure = null;
  904. int size = Marshal.SizeOf(typeof(T));
  905. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  906. try
  907. {
  908. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  909. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  910. }
  911. finally
  912. {
  913. Marshal.FreeHGlobal(allocIntPtr);
  914. }
  915. return (T)structure;
  916. }
  917. }
  918. #endregion
  919. #region 故障日志解析显示
  920. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  921. {
  922. string SaveData = "";
  923. //Log1
  924. if (Log1.Error_Index != 0xFFFF)
  925. {
  926. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  927. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  928. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  929. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  930. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  931. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  932. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  933. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  934. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  935. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  936. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  937. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  938. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  939. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  940. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  941. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  942. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  943. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  944. {
  945. SaveData += "续航:" + "---km" + ", ";
  946. }
  947. else
  948. {
  949. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  950. }
  951. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  952. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  953. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  954. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  955. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  956. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  957. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  958. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  959. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  960. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  961. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  962. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  963. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  964. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  965. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  966. SaveData += "\r\n\r\n";
  967. richTextBox_Record.AppendText(SaveData);
  968. SaveData = "";
  969. }
  970. //Log2
  971. if (Log2.Error_Index != 0xFFFF)
  972. {
  973. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  974. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  975. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  976. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  977. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  978. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  979. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  980. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  981. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  982. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  983. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  984. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  985. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  986. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  987. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  988. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  989. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  990. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  991. {
  992. SaveData += "续航:" + "---km" + ", ";
  993. }
  994. else
  995. {
  996. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  997. }
  998. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  999. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1000. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1001. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1002. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1003. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1004. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1005. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1006. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1007. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1008. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1009. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1010. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1011. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1012. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1013. SaveData += "\r\n\r\n";
  1014. richTextBox_Record.AppendText(SaveData);
  1015. SaveData = "";
  1016. }
  1017. }
  1018. #endregion
  1019. #region 串口数据解析线程
  1020. /// <summary>
  1021. /// 串口数据解析线程
  1022. /// </summary>
  1023. private void Task_SerialProcess()
  1024. {
  1025. //创建定时器,定时读取串口数据
  1026. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1027. timer_ReadSerial.Enabled = true;
  1028. timer_ReadSerial.Interval = 20;
  1029. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1030. timer_ReadSerial.Start();
  1031. while (true)
  1032. {
  1033. Thread.Sleep(1);
  1034. };
  1035. }
  1036. /// <summary>
  1037. /// 串口解析定时器
  1038. /// </summary>
  1039. /// <param name="sender"></param>
  1040. /// <param name="e"></param>
  1041. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1042. {
  1043. //串口解析
  1044. Serial_process(mySerialProcess.buffer);
  1045. }
  1046. #endregion
  1047. #region 数据解析
  1048. public void Serial_process(List<byte> buffer)
  1049. {
  1050. byte DataNum = 0; //记录每条命令数据段的长度
  1051. ushort PackageID, Cmd;
  1052. byte[] Data = new byte[1024];
  1053. try
  1054. {
  1055. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1056. {
  1057. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1058. {
  1059. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1060. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1061. {
  1062. int CmdLen = buffer[5];
  1063. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1064. while (CmdLen > 0) //读取命令段
  1065. {
  1066. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1067. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1068. if (DataNum <= (CmdLen - 2))
  1069. {
  1070. for (int i = 0; i < DataNum; i++)
  1071. {
  1072. Data[i] = buffer[i + 8];
  1073. }
  1074. // 串口接收的数据 显示在子窗口
  1075. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1076. {
  1077. string strTemp = String.Empty;
  1078. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1079. for (int i = 0; i < CmdLen + 11; i++)
  1080. {
  1081. strTemp += (buffer[i].ToString("X2") + " ");
  1082. }
  1083. strTemp += "\n";
  1084. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1085. }
  1086. buffer.RemoveRange(0, CmdLen + 11);
  1087. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1088. DataRevToString(Cmd, Data);//指令数据转为字符串
  1089. }
  1090. }
  1091. }
  1092. else
  1093. {
  1094. buffer.RemoveAt(0);//ID不对
  1095. }
  1096. }
  1097. else
  1098. {
  1099. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1100. }
  1101. }
  1102. }
  1103. catch (Exception)
  1104. {
  1105. }
  1106. }
  1107. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1108. {
  1109. int DataTemp;
  1110. ushort uData16;
  1111. unchecked
  1112. {
  1113. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1114. }
  1115. #region 解析发送给CDL的指令
  1116. if (ID == 0x7FF)
  1117. {
  1118. switch (CmdTemp)
  1119. {
  1120. case 0x1100://
  1121. {
  1122. unchecked
  1123. {
  1124. this.Invoke((EventHandler)(delegate
  1125. {
  1126. //CDL连接成功
  1127. mySerialProcess.CDL_Online_Flag = true;
  1128. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1129. groupBox1.Visible = true;
  1130. groupBox3.Visible = true;
  1131. tabControl2.Visible = true;
  1132. label_StarInfo.Visible = false;
  1133. }));
  1134. }
  1135. break;
  1136. }
  1137. default: break;
  1138. }
  1139. }
  1140. #endregion
  1141. #region 解析电机的命令
  1142. else if ((ID == 0x715) || (ID == 0x710))
  1143. {
  1144. switch (CmdTemp)
  1145. {
  1146. case 0x1020://电机运行信息
  1147. {
  1148. unchecked
  1149. {
  1150. this.Invoke((EventHandler)(delegate
  1151. {
  1152. MC_RunInfo_Refresh = true;
  1153. //车速
  1154. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1155. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1156. //输出转速
  1157. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1158. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1159. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1160. Class_MotorSpeed.Data = DataTemp;
  1161. //电功率
  1162. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1163. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1164. //母线电压
  1165. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1166. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1167. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1168. //母线电流
  1169. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1170. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1171. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1172. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1173. Class_CurrentData.Data = DataTemp;
  1174. //踏频
  1175. DataTemp = (ushort)(Data[10]);
  1176. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1177. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1178. Class_CadenceData.Data = DataTemp;
  1179. //踩踏力矩
  1180. DataTemp = (ushort)(Data[11]);
  1181. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1182. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1183. Class_TorqueData.Data = DataTemp;
  1184. //踩踏方向
  1185. DataTemp = (ushort)(Data[12]);
  1186. if (DataTemp == 0)
  1187. {
  1188. textBox_RunInfo_Dir.Text = "正向";
  1189. }
  1190. else if (DataTemp == 1)
  1191. {
  1192. textBox_RunInfo_Dir.Text = "反向";
  1193. }
  1194. else if (DataTemp == 2)
  1195. {
  1196. textBox_RunInfo_Dir.Text = "停止";
  1197. }
  1198. //助力档位
  1199. DataTemp = (ushort)(Data[13]);
  1200. if (DataTemp == 0x33)
  1201. {
  1202. textBox_RunInfo_GearSt.Text = "SMART";
  1203. //comboBox_GearSt.SelectedIndex = 5;
  1204. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1205. }
  1206. else if (DataTemp == 0x22)
  1207. {
  1208. textBox_RunInfo_GearSt.Text = "WALK";
  1209. //comboBox_GearSt.SelectedIndex = 6;
  1210. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1211. }
  1212. else
  1213. {
  1214. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1215. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1216. //comboBox_GearSt.SelectedIndex = DataTemp;
  1217. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1218. }
  1219. //大灯状态
  1220. DataTemp = (ushort)(Data[14]);
  1221. if (DataTemp == 0xF0)
  1222. {
  1223. textBox_RunInfo_LightSwitch.Text = "OFF";
  1224. //comboBox_LightSwitch.SelectedIndex = 1;
  1225. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1226. }
  1227. else if (DataTemp == 0xF1)
  1228. {
  1229. textBox_RunInfo_LightSwitch.Text = "ON";
  1230. //comboBox_LightSwitch.SelectedIndex = 0;
  1231. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1232. }
  1233. //剩余电量
  1234. DataTemp = (ushort)(Data[15]);
  1235. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1236. //剩余续航里程
  1237. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1238. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1239. {
  1240. textBox_RunInfo_Range.Text = "---";
  1241. }
  1242. else
  1243. {
  1244. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1245. }
  1246. //预留(显示力矩Reg),空2bytes
  1247. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1248. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1249. //平均功耗
  1250. DataTemp = (ushort)(Data[20]);
  1251. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1252. //PCB温度
  1253. DataTemp = (ushort)(Data[21]);
  1254. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1255. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1256. Class_MotorTemp.Data = DataTemp - 40;
  1257. //绕组温度
  1258. DataTemp = (ushort)(Data[22]);
  1259. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1260. //MCU温度
  1261. DataTemp = (ushort)(Data[23]);
  1262. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1263. //单次里程
  1264. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1265. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1266. //单次时间
  1267. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1268. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1269. //数据保存
  1270. RunInfoAutoSave();
  1271. }));
  1272. }
  1273. break;
  1274. }
  1275. case 0x1104://故障码
  1276. {
  1277. unchecked
  1278. {
  1279. this.Invoke((EventHandler)(delegate
  1280. {
  1281. MC_ErrorCode_Refresh = true;
  1282. textBox_ErrorCode.Text =
  1283. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1284. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1285. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1286. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1287. "H";
  1288. }));
  1289. }
  1290. break;
  1291. }
  1292. case 0xA903://反馈指令
  1293. {
  1294. unchecked
  1295. {
  1296. this.Invoke((EventHandler)(delegate
  1297. {
  1298. if (ACK_DisFlag == true)
  1299. {
  1300. timer_1s.Enabled = false;
  1301. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1302. timer_1s.Enabled = true;
  1303. //关机反馈
  1304. PowerOffAckStatus = true;
  1305. }
  1306. //应答标志置位
  1307. WriteACK = true;
  1308. WriteCnt++;
  1309. }));
  1310. }
  1311. break;
  1312. }
  1313. case 0xB226://马达参数
  1314. {
  1315. unchecked
  1316. {
  1317. this.Invoke((EventHandler)(delegate
  1318. {
  1319. richTextBox_MotorParam.Clear();
  1320. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1321. {
  1322. if (i == 6)
  1323. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1324. else
  1325. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1326. }
  1327. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1328. }));
  1329. }
  1330. break;
  1331. }
  1332. case 0xB31A://整车信息
  1333. {
  1334. unchecked
  1335. {
  1336. this.Invoke((EventHandler)(delegate
  1337. {
  1338. richTextBox_BikeParam.Clear();
  1339. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1340. {
  1341. if (i == 9)
  1342. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1343. else
  1344. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1345. //更新前后灯参数
  1346. if (i == 8)
  1347. {
  1348. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1349. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1350. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1351. }
  1352. //更新开关机参数
  1353. else if (i == 11)
  1354. {
  1355. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1356. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1357. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1358. }
  1359. }
  1360. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1361. }));
  1362. }
  1363. break;
  1364. }
  1365. case 0xB420://控制器参数
  1366. {
  1367. unchecked
  1368. {
  1369. this.Invoke((EventHandler)(delegate
  1370. {
  1371. richTextBox_ControlParam.Clear();
  1372. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1373. {
  1374. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1375. //转把定速巡航
  1376. if (i == 13)
  1377. {
  1378. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1379. }
  1380. }
  1381. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1382. }));
  1383. }
  1384. break;
  1385. }
  1386. case 0xB528://传感器参数
  1387. {
  1388. unchecked
  1389. {
  1390. this.Invoke((EventHandler)(delegate
  1391. {
  1392. richTextBox_SensorParam.Clear();
  1393. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1394. {
  1395. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1396. }
  1397. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1398. //更新生产模式页面传感器零点和标定值
  1399. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1400. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1401. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1402. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1403. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1404. }));
  1405. }
  1406. break;
  1407. }
  1408. case 0xB64C://助力参数
  1409. {
  1410. unchecked
  1411. {
  1412. this.Invoke((EventHandler)(delegate
  1413. {
  1414. richTextBox_AssistParam.Clear();
  1415. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1416. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1417. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1418. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1419. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1420. {
  1421. if (i < index_1) //数据占用2bytes
  1422. {
  1423. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1424. }
  1425. else if (i <= index_2) //数据占用4bytes
  1426. {
  1427. 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])) + ", ");
  1428. }
  1429. else if (i < index_3) //数据占用2bytes,无符号
  1430. {
  1431. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1432. }
  1433. else if (i <= index_4) //数据占用2bytes,有符号
  1434. {
  1435. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1436. }
  1437. else //数据占用2bytes,无符号
  1438. {
  1439. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1440. }
  1441. }
  1442. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1443. }));
  1444. }
  1445. break;
  1446. }
  1447. case 0xB74C://历史记录
  1448. {
  1449. unchecked
  1450. {
  1451. this.Invoke((EventHandler)(delegate
  1452. {
  1453. richTextBox_Record.Clear();
  1454. for (int i = 0; i < myParams.Record.Count; i++)
  1455. {
  1456. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1457. }
  1458. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1459. }));
  1460. }
  1461. break;
  1462. }
  1463. case 0xB83A://调试参数
  1464. {
  1465. unchecked
  1466. {
  1467. this.Invoke((EventHandler)(delegate
  1468. {
  1469. richTextBox_DebugParam.Clear();
  1470. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1471. {
  1472. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1473. }
  1474. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1475. }));
  1476. }
  1477. break;
  1478. }
  1479. case 0xB904://存储标志
  1480. {
  1481. unchecked
  1482. {
  1483. this.Invoke((EventHandler)(delegate
  1484. {
  1485. ushort Flag = 0;
  1486. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1487. if (Flag == 0)
  1488. {
  1489. radioButton_EE_SaveNo.Checked = true;
  1490. radioButton_EE_SaveYes.Checked = false;
  1491. }
  1492. else
  1493. {
  1494. radioButton_EE_SaveNo.Checked = false;
  1495. radioButton_EE_SaveYes.Checked = true;
  1496. }
  1497. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1498. if (Flag == 0)
  1499. {
  1500. radioButton_SIP_SaveNo.Checked = true;
  1501. radioButton_SIP_SaveYes.Checked = false;
  1502. }
  1503. else
  1504. {
  1505. radioButton_SIP_SaveNo.Checked = false;
  1506. radioButton_SIP_SaveYes.Checked = true;
  1507. }
  1508. }));
  1509. }
  1510. break;
  1511. }
  1512. case 0x1240://电机版本信息
  1513. {
  1514. unchecked
  1515. {
  1516. this.Invoke((EventHandler)(delegate
  1517. {
  1518. //电机型号
  1519. textBox_Model.Text = "";
  1520. textBox_OBC_ReadModel.Text = "";
  1521. textBox_FacModeName.Text = "";
  1522. for (ushort i = 0; i < 16; i++)
  1523. {
  1524. if (Data[i] == 0x2E)
  1525. {
  1526. break;
  1527. }
  1528. textBox_Model.Text += ((char)Data[i]).ToString();
  1529. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1530. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1531. }
  1532. Class_Motor_Ver.Mode = textBox_Model.Text;
  1533. //电机SN
  1534. textBox_SN.Text = "";
  1535. textBox_OBC_ReadSN.Text = "";
  1536. textBox_FacModeNum.Text = "";
  1537. for (ushort i = 0; i < 16; i++)
  1538. {
  1539. if (Data[16 + i] == 0x2E)
  1540. {
  1541. break;
  1542. }
  1543. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1544. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1545. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1546. }
  1547. Class_Motor_Ver.SN = textBox_SN.Text;
  1548. //电机HW
  1549. textBox_HW.Text = "";
  1550. textBox_OBC_ReadHW.Text = "";
  1551. textBox_FacModeHW.Text = "";
  1552. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1553. {
  1554. if (Data[32 + i] == 0x2E)
  1555. {
  1556. break;
  1557. }
  1558. else if (Data[32 + i] == 'r')
  1559. {
  1560. Data[32 + i] = (byte)'.';
  1561. break;
  1562. }
  1563. string strTemp = "";
  1564. strTemp = ((char)Data[32 + i]).ToString();
  1565. textBox_HW.Text += strTemp;
  1566. textBox_OBC_ReadHW.Text += strTemp;
  1567. textBox_FacModeHW.Text += strTemp;
  1568. }
  1569. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1570. {
  1571. if (Data[40 + i] == 0x2E)
  1572. {
  1573. break;
  1574. }
  1575. else if (Data[40 + i] == 'r')
  1576. {
  1577. Data[40 + i] = (byte)'.';
  1578. break;
  1579. }
  1580. string strTemp = "";
  1581. strTemp = ((char)Data[40 + i]).ToString();
  1582. textBox_HW.Text += strTemp;
  1583. textBox_OBC_ReadHW.Text += strTemp;
  1584. textBox_FacModeHW.Text += strTemp;
  1585. }
  1586. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1587. {
  1588. string strTemp = "";
  1589. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1590. textBox_HW.Text += strTemp;
  1591. textBox_OBC_ReadHW.Text += strTemp;
  1592. textBox_FacModeHW.Text += strTemp;
  1593. }
  1594. Class_Motor_Ver.HW = textBox_HW.Text;
  1595. //电机FW
  1596. textBox_FW.Text = "";
  1597. textBox_OBC_ReadFW.Text = "";
  1598. textBox_FacModeFW.Text = "";
  1599. for (ushort i = 0; i < 16; i++)
  1600. {
  1601. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1602. {
  1603. break;
  1604. }
  1605. if (Data[48 + i] == 'r')
  1606. {
  1607. Data[48 + i] = (byte)'.';
  1608. }
  1609. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1610. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1611. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1612. }
  1613. Class_Motor_Ver.FW = textBox_FW.Text;
  1614. }));
  1615. }
  1616. break;
  1617. }
  1618. case 0xA610://自定义1
  1619. {
  1620. unchecked
  1621. {
  1622. this.Invoke((EventHandler)(delegate
  1623. {
  1624. textBox_User1.Text = "";
  1625. for (ushort i = 0; i < 16; i++)
  1626. {
  1627. if (Data[i] == 0x2E)
  1628. {
  1629. break;
  1630. }
  1631. textBox_User1.Text += ((char)Data[i]).ToString();
  1632. }
  1633. }));
  1634. }
  1635. break;
  1636. }
  1637. case 0xA710://自定义2
  1638. {
  1639. unchecked
  1640. {
  1641. this.Invoke((EventHandler)(delegate
  1642. {
  1643. textBox_User2.Text = "";
  1644. for (ushort i = 0; i < 16; i++)
  1645. {
  1646. if (Data[i] == 0x2E)
  1647. {
  1648. break;
  1649. }
  1650. textBox_User2.Text += ((char)Data[i]).ToString();
  1651. }
  1652. }));
  1653. }
  1654. break;
  1655. }
  1656. case 0xA810://自定义1
  1657. {
  1658. unchecked
  1659. {
  1660. this.Invoke((EventHandler)(delegate
  1661. {
  1662. textBox_User3.Text = "";
  1663. for (ushort i = 0; i < 16; i++)
  1664. {
  1665. if (Data[i] == 0x2E)
  1666. {
  1667. break;
  1668. }
  1669. textBox_User3.Text += ((char)Data[i]).ToString();
  1670. }
  1671. }));
  1672. }
  1673. break;
  1674. }
  1675. case 0xA520://生产信息
  1676. {
  1677. unchecked
  1678. {
  1679. this.Invoke((EventHandler)(delegate
  1680. {
  1681. //生产商
  1682. textBox_MAC.Text = "";
  1683. for (ushort i = 0; i < 8; i++)
  1684. {
  1685. if (Data[i] == 0x2E)
  1686. {
  1687. break;
  1688. }
  1689. textBox_MAC.Text += ((char)Data[i]).ToString();
  1690. }
  1691. //生产地
  1692. textBox_MACAdd.Text = "";
  1693. for (ushort i = 0; i < 8; i++)
  1694. {
  1695. if (Data[8 + i] == 0x2E)
  1696. {
  1697. break;
  1698. }
  1699. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1700. }
  1701. //生产日期
  1702. textBox_MACDate.Text = "";
  1703. for (ushort i = 0; i < 8; i++)
  1704. {
  1705. if (Data[16 + i] == 0x2E)
  1706. {
  1707. break;
  1708. }
  1709. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1710. }
  1711. //品牌信息
  1712. textBox_PP.Text = "";
  1713. for (ushort i = 0; i < 8; i++)
  1714. {
  1715. if (Data[24 + i] == 0x2E)
  1716. {
  1717. break;
  1718. }
  1719. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1720. }
  1721. }));
  1722. }
  1723. break;
  1724. }
  1725. case 0xA408://密钥
  1726. {
  1727. unchecked
  1728. {
  1729. this.Invoke((EventHandler)(delegate
  1730. {
  1731. textBox_Key.Text = "";
  1732. for (ushort i = 0; i < 8; i++)
  1733. {
  1734. textBox_Key.Text += ((char)Data[i]).ToString();
  1735. }
  1736. }));
  1737. }
  1738. break;
  1739. }
  1740. case 0xAB09://存储器数据
  1741. case 0xAB0A:
  1742. case 0xAB0B:
  1743. case 0xAB0C:
  1744. {
  1745. unchecked
  1746. {
  1747. this.Invoke((EventHandler)(delegate
  1748. {
  1749. long ByteNum = 0;
  1750. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1751. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1752. {
  1753. for (int i = 0; i < ByteNum; i++)
  1754. {
  1755. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1756. }
  1757. }
  1758. else //根据设置自动转换10进制显示
  1759. {
  1760. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1761. {
  1762. switch (ByteNum)
  1763. {
  1764. case 1:
  1765. {
  1766. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1767. break;
  1768. }
  1769. case 2:
  1770. {
  1771. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1772. break;
  1773. }
  1774. case 3:
  1775. {
  1776. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1777. break;
  1778. }
  1779. case 4:
  1780. {
  1781. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1782. break;
  1783. }
  1784. default:
  1785. {
  1786. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1787. break;
  1788. }
  1789. }
  1790. }
  1791. else //16进制显示
  1792. {
  1793. switch (ByteNum)
  1794. {
  1795. case 1:
  1796. {
  1797. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1798. break;
  1799. }
  1800. case 2:
  1801. {
  1802. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1803. break;
  1804. }
  1805. case 3:
  1806. {
  1807. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1808. break;
  1809. }
  1810. case 4:
  1811. {
  1812. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1813. break;
  1814. }
  1815. default:
  1816. {
  1817. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1818. break;
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }));
  1824. }
  1825. break;
  1826. }
  1827. case 0xAB88://故障日志
  1828. {
  1829. unchecked
  1830. {
  1831. this.Invoke((EventHandler)(delegate
  1832. {
  1833. //电机存储的故障日志,一包128字节包含2条故障日志
  1834. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1835. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1836. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1837. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1838. //数据显示
  1839. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1840. }));
  1841. }
  1842. break;
  1843. }
  1844. case 0x1401://在线检测结果
  1845. {
  1846. unchecked
  1847. {
  1848. this.Invoke((EventHandler)(delegate
  1849. {
  1850. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1851. }));
  1852. }
  1853. break;
  1854. }
  1855. case 0x1510://骑行历史信息
  1856. {
  1857. unchecked
  1858. {
  1859. this.Invoke((EventHandler)(delegate
  1860. {
  1861. long DataTemp32;
  1862. //ODO里程
  1863. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1864. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1865. textBox_ODO_KM.Text = DataTemp32.ToString();
  1866. //ODO时间
  1867. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1868. if (DataTemp32 >= 60 * 100000)
  1869. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1870. else
  1871. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1872. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1873. //TRIP里程
  1874. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1875. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1876. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1877. //TRIP时间
  1878. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1879. if (DataTemp32 >= 60 * 100000)
  1880. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1881. else
  1882. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1883. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1884. }));
  1885. }
  1886. break;
  1887. }
  1888. case 0x1720://客户信息
  1889. {
  1890. unchecked
  1891. {
  1892. this.Invoke((EventHandler)(delegate
  1893. {
  1894. //软件标识
  1895. textBox_SP.Text = "";
  1896. textBox_OBC_ReadSP.Text = "";
  1897. textBox_FacModeSP.Text = "";
  1898. for (ushort i = 0; i < 23; i++)
  1899. {
  1900. if (Data[i] == 'r')
  1901. {
  1902. Data[i] = (byte)'.';
  1903. }
  1904. textBox_SP.Text += ((char)Data[i]).ToString();
  1905. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1906. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1907. }
  1908. //Git提交版本信息
  1909. textBox_FacModeGit.Text = "";
  1910. for (ushort i = 0; i < 9; i++)
  1911. {
  1912. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  1913. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  1914. }
  1915. Class_Motor_Ver.Special = textBox_SP.Text;
  1916. }));
  1917. }
  1918. break;
  1919. }
  1920. case 0xBA20: //调试信息
  1921. {
  1922. unchecked
  1923. {
  1924. this.Invoke((EventHandler)(delegate
  1925. {
  1926. MC_DebugInfo_Refresh = true;
  1927. //系统状态机
  1928. DataTemp = (short)(Data[0]);
  1929. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  1930. //二层状态机
  1931. DataTemp = (short)(Data[1]);
  1932. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  1933. //电机状态机
  1934. DataTemp = (short)(Data[2]);
  1935. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  1936. //助力状态机
  1937. DataTemp = (short)(Data[3]);
  1938. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  1939. //IdRef
  1940. DataTemp = (short)(Data[5] * 256 + Data[4]);
  1941. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  1942. //IqRef
  1943. DataTemp = (short)(Data[7] * 256 + Data[6]);
  1944. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  1945. //UdRef
  1946. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1947. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  1948. //UqRef
  1949. DataTemp = (short)(Data[11] * 256 + Data[10]);
  1950. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  1951. //瞬时力矩
  1952. DataTemp = (short)(Data[13] * 256 + Data[12]);
  1953. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  1954. //时间滤波力矩
  1955. DataTemp = (short)(Data[15] * 256 + Data[14]);
  1956. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  1957. //踏频滤波力矩
  1958. DataTemp = (short)(Data[17] * 256 + Data[16]);
  1959. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  1960. //IdFdb
  1961. DataTemp = (short)(Data[19] * 256 + Data[18]);
  1962. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  1963. //IqFdb
  1964. DataTemp = (short)(Data[21] * 256 + Data[20]);
  1965. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  1966. //助力输出
  1967. DataTemp = (short)(Data[23] * 256 + Data[22]);
  1968. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  1969. //数据保存
  1970. RunInfoAutoSave();
  1971. }));
  1972. }
  1973. break;
  1974. }
  1975. case 0xBB20: //产品标签信息
  1976. {
  1977. unchecked
  1978. {
  1979. this.Invoke((EventHandler)(delegate
  1980. {
  1981. //产品标签
  1982. textBox_TagInfo.Text = "";
  1983. for (ushort i = 0; i < 32; i++)
  1984. {
  1985. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  1986. }
  1987. }));
  1988. }
  1989. break;
  1990. }
  1991. case 0xBC20: //内阻校正信息
  1992. {
  1993. unchecked
  1994. {
  1995. this.Invoke((EventHandler)(delegate
  1996. {
  1997. //内阻1
  1998. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1999. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2000. //内阻2
  2001. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2002. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2003. //内阻3
  2004. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2005. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2006. //K1
  2007. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2008. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2009. //K2
  2010. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2011. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2012. //K3
  2013. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2014. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2015. //K4
  2016. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2017. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2018. //K5
  2019. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2020. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2021. }));
  2022. }
  2023. break;
  2024. }
  2025. case 0xBD20: //整车信息2
  2026. {
  2027. unchecked
  2028. {
  2029. this.Invoke((EventHandler)(delegate
  2030. {
  2031. richTextBox_BikeParam2.Clear();
  2032. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2033. {
  2034. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2035. }
  2036. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2037. }));
  2038. }
  2039. break;
  2040. }
  2041. case 0xBE20: //用户骑行参数
  2042. {
  2043. unchecked
  2044. {
  2045. this.Invoke((EventHandler)(delegate
  2046. {
  2047. richTextBox_UsrRidesParam.Clear();
  2048. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2049. {
  2050. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2051. }
  2052. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2053. }));
  2054. }
  2055. break;
  2056. }
  2057. case 0xC109: //Boot版本信息
  2058. {
  2059. BootInfo = "";
  2060. for (ushort i = 0; i < 9; i++)
  2061. {
  2062. BootInfo += ((char)Data[i]).ToString();
  2063. }
  2064. break;
  2065. }
  2066. default:
  2067. {
  2068. break;
  2069. }
  2070. }
  2071. }
  2072. #endregion
  2073. #region 解析BMS广播的命令
  2074. else if (ID == 0x720)
  2075. {
  2076. switch (CmdTemp)
  2077. {
  2078. case 0x1010://BMS运行信息
  2079. {
  2080. unchecked
  2081. {
  2082. this.Invoke((EventHandler)(delegate
  2083. {
  2084. BMS_RunInfo_Refresh = true;
  2085. richTextBox_OBC_BMS_RunInfo.Clear();
  2086. //电压
  2087. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2088. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2089. //电流
  2090. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2091. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2092. //剩余容量
  2093. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2094. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2095. //满充容量
  2096. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2097. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2098. //电芯温度
  2099. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2100. //剩余电量
  2101. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2102. //电池状态
  2103. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2104. //SOH
  2105. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2106. //循环次数
  2107. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2108. }));
  2109. }
  2110. break;
  2111. }
  2112. default: break;
  2113. }
  2114. }
  2115. #endregion
  2116. #region 解析电机发送OBC的命令
  2117. else if (ID == 0x713)
  2118. {
  2119. switch (CmdTemp)
  2120. {
  2121. case 0x5408://电机用户参数
  2122. {
  2123. unchecked
  2124. {
  2125. this.Invoke((EventHandler)(delegate
  2126. {
  2127. richTextBox_OBC_ReadUserInfo.Clear();
  2128. //默认周长
  2129. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2130. //启动模式
  2131. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2132. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2133. //限速
  2134. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2135. //周长微调
  2136. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2137. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2138. //助力方案
  2139. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2140. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2141. //关机时间
  2142. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2143. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2144. //限速微调
  2145. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2146. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2147. //定速巡航
  2148. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2149. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2150. }));
  2151. }
  2152. break;
  2153. }
  2154. case 0x5303://电机应答反馈
  2155. {
  2156. unchecked
  2157. {
  2158. this.Invoke((EventHandler)(delegate
  2159. {
  2160. timer_1s.Enabled = false;
  2161. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2162. timer_1s.Enabled = true;
  2163. }));
  2164. }
  2165. break;
  2166. }
  2167. case 0x5620: //用户骑行参数
  2168. {
  2169. unchecked
  2170. {
  2171. this.Invoke((EventHandler)(delegate
  2172. {
  2173. richTextBox_UsrRidesParam.Clear();
  2174. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2175. {
  2176. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2177. }
  2178. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2179. }));
  2180. }
  2181. break;
  2182. }
  2183. default: break;
  2184. }
  2185. }
  2186. #endregion
  2187. }
  2188. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2189. {
  2190. CmdRevStrTemp = "";
  2191. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2192. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2193. ushort len = (ushort)(CmdTemp & 0x00FF);
  2194. for (int i = 0; i < len ; i++)
  2195. {
  2196. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2197. }
  2198. }
  2199. #endregion
  2200. /// <summary>
  2201. /// 端口连接或断开
  2202. /// </summary>
  2203. private void PortConnect()
  2204. {
  2205. bool result = false;
  2206. if (连接ToolStripMenuItem.Text == "连接")
  2207. {
  2208. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2209. if (result)
  2210. {
  2211. toolStripComboBox_ComNum.Enabled = false;
  2212. toolStripComboBox_Baudrate.Enabled = false;
  2213. 刷新ToolStripMenuItem.Enabled = false;
  2214. 连接ToolStripMenuItem.Text = "断开";
  2215. 连接ToolStripMenuItem.Checked = true;
  2216. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2217. label_PortStatus.BackColor = Color.Green;
  2218. }
  2219. }
  2220. else if (连接ToolStripMenuItem.Text == "断开")
  2221. {
  2222. checkBox_OBC_StartSetGearSt.Checked = false;
  2223. checkBox_OBC_StartReadBMS.Checked = false;
  2224. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2225. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2226. toolStripComboBox_ComNum.Enabled = true;
  2227. toolStripComboBox_Baudrate.Enabled = true;
  2228. 刷新ToolStripMenuItem.Enabled = true;
  2229. 连接ToolStripMenuItem.Text = "连接";
  2230. 连接ToolStripMenuItem.Checked = false;
  2231. label_COM_Sta.Text = "连接状态:未连接";
  2232. label_PortStatus.BackColor = Color.Red;
  2233. }
  2234. }
  2235. /// <summary>
  2236. /// 端口连接事件
  2237. /// </summary>
  2238. /// <param name="sender"></param>
  2239. /// <param name="e"></param>
  2240. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2241. {
  2242. PortConnect();
  2243. }
  2244. /// <summary>
  2245. /// 端口号刷新事件
  2246. /// </summary>
  2247. /// <param name="sender"></param>
  2248. /// <param name="e"></param>
  2249. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2250. {
  2251. toolStripComboBox_ComNum.Items.Clear();
  2252. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2253. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2254. }
  2255. /// <summary>
  2256. /// 转速调节事件
  2257. /// </summary>
  2258. /// <param name="sender"></param>
  2259. /// <param name="e"></param>
  2260. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  2261. {
  2262. //生产模式转速设置值更新
  2263. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  2264. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  2265. //设置转速百分比
  2266. var Data = new byte[1];
  2267. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  2268. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  2269. }
  2270. /// <summary>
  2271. /// 存储标志修改事件
  2272. /// </summary>
  2273. /// <param name="sender"></param>
  2274. /// <param name="e"></param>
  2275. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2276. {
  2277. if (写入存储ToolStripMenuItem.Checked)
  2278. {
  2279. EnterForm1.ShowDialog();
  2280. try
  2281. {
  2282. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2283. {
  2284. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2285. {
  2286. 写入存储ToolStripMenuItem.Checked = false;
  2287. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2288. }
  2289. else
  2290. {
  2291. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2292. }
  2293. }
  2294. else
  2295. {
  2296. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2297. }
  2298. }
  2299. catch (Exception)
  2300. {
  2301. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2302. }
  2303. }
  2304. else
  2305. {
  2306. 写入存储ToolStripMenuItem.Checked = true;
  2307. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2308. }
  2309. }
  2310. /// <summary>
  2311. /// 1s定时器
  2312. /// </summary>
  2313. /// <param name="sender"></param>
  2314. /// <param name="e"></param>
  2315. private void timer_1s_Tick(object sender, EventArgs e)
  2316. {
  2317. //时间更新
  2318. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2319. //MC_Runinfo超时清除
  2320. if (MC_RunInfo_Refresh == false)
  2321. {
  2322. MC_RunInfo_Refresh_Cnt++;
  2323. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2324. {
  2325. MC_RunInfo_Clear();
  2326. MC_RunInfo_Refresh_Cnt = 0;
  2327. }
  2328. }
  2329. else
  2330. {
  2331. MC_RunInfo_Refresh_Cnt = 0;
  2332. }
  2333. MC_RunInfo_Refresh = false;
  2334. //MC_Debuginfo超时清除
  2335. if (MC_DebugInfo_Refresh == false)
  2336. {
  2337. MC_DebugInfo_Refresh_Cnt++;
  2338. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2339. {
  2340. MC_DebugInfo_Clear();
  2341. MC_DebugInfo_Refresh_Cnt = 0;
  2342. }
  2343. }
  2344. else
  2345. {
  2346. MC_DebugInfo_Refresh_Cnt = 0;
  2347. }
  2348. MC_DebugInfo_Refresh = false;
  2349. //BMS_RunInfo超时清除
  2350. if (BMS_RunInfo_Refresh == false)
  2351. {
  2352. BMS_RunInfo_Refresh_Cnt++;
  2353. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2354. {
  2355. richTextBox_OBC_BMS_RunInfo.Clear();
  2356. BMS_RunInfo_Refresh_Cnt = 0;
  2357. }
  2358. }
  2359. else
  2360. {
  2361. BMS_RunInfo_Refresh_Cnt = 0;
  2362. }
  2363. BMS_RunInfo_Refresh = false;
  2364. //故障码超时清除
  2365. if (MC_ErrorCode_Refresh == false)
  2366. {
  2367. MC_ErrorCode_Refresh_Cnt++;
  2368. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2369. {
  2370. textBox_ErrorCode.Text = "---";
  2371. MC_ErrorCode_Refresh_Cnt = 0;
  2372. }
  2373. }
  2374. else
  2375. {
  2376. MC_ErrorCode_Refresh_Cnt = 0;
  2377. }
  2378. MC_ErrorCode_Refresh = false;
  2379. //CDL连接超时
  2380. if (识别通讯盒ToolStripMenuItem.Checked)
  2381. {
  2382. if (mySerialProcess.CDL_Online_Flag == false)
  2383. {
  2384. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2385. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2386. {
  2387. timer_1s.Enabled = false;
  2388. MessageBox.Show("连接失败!", "提示");
  2389. timer_1s.Enabled = true;
  2390. //关闭串口
  2391. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2392. toolStripComboBox_ComNum.Enabled = true;
  2393. toolStripComboBox_Baudrate.Enabled = true;
  2394. 刷新ToolStripMenuItem.Enabled = true;
  2395. 连接ToolStripMenuItem.Text = "连接";
  2396. 连接ToolStripMenuItem.Checked = false;
  2397. label_COM_Sta.Text = "连接状态:未连接";
  2398. label_PortStatus.BackColor = Color.Red;
  2399. }
  2400. }
  2401. }
  2402. //OBC定时发送设置档位
  2403. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2404. {
  2405. var CtrlCode = new byte[2];
  2406. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2407. CtrlCode[0] = 0x33;
  2408. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2409. CtrlCode[0] = 0x22;
  2410. else
  2411. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2412. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2413. CtrlCode[1] = 0xF1;
  2414. else
  2415. CtrlCode[1] = 0xF0;
  2416. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2417. {
  2418. checkBox_OBC_StartSetGearSt.Checked = false;
  2419. }
  2420. }
  2421. //OBC定时发送查询电池
  2422. if (checkBox_OBC_StartReadBMS.Checked == true)
  2423. {
  2424. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2425. {
  2426. checkBox_OBC_StartReadBMS.Checked = false;
  2427. }
  2428. }
  2429. //定时读取存储器
  2430. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2431. {
  2432. var Address = new byte[4];
  2433. UInt32 Address_Begin;
  2434. UInt32 Addres_End;
  2435. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2436. richTextBox_RamFlasgData.Clear();
  2437. do
  2438. {
  2439. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2440. {
  2441. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2442. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2443. continue;
  2444. }
  2445. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2446. {
  2447. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2448. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2449. continue;
  2450. }
  2451. else
  2452. {
  2453. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2454. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2455. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2456. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2457. if (Addres_End < Address_Begin)
  2458. {
  2459. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2460. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2461. continue;
  2462. }
  2463. else
  2464. {
  2465. var SendByte = new byte[8];
  2466. SendByte[0] = (byte)(Address_Begin >> 24);
  2467. SendByte[1] = (byte)(Address_Begin >> 16);
  2468. SendByte[2] = (byte)(Address_Begin >> 8);
  2469. SendByte[3] = (byte)(Address_Begin);
  2470. SendByte[4] = (byte)(Addres_End >> 24);
  2471. SendByte[5] = (byte)(Addres_End >> 16);
  2472. SendByte[6] = (byte)(Addres_End >> 8);
  2473. SendByte[7] = (byte)(Addres_End);
  2474. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2475. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2476. }
  2477. }
  2478. } while (false);
  2479. }
  2480. //写入参数等待计时
  2481. ACK_WaitCnt++;
  2482. }
  2483. /// <summary>
  2484. /// 运行信息清除
  2485. /// </summary>
  2486. private void MC_RunInfo_Clear()
  2487. {
  2488. foreach (Control c in tabPage_RunInfo.Controls)
  2489. {
  2490. if ((c is TextBox))
  2491. {
  2492. if (c.Name != textBox_ErrorCode.ToString())
  2493. c.Text = "---";
  2494. }
  2495. }
  2496. }
  2497. /// <summary>
  2498. /// 调试信息清除
  2499. /// </summary>
  2500. private void MC_DebugInfo_Clear()
  2501. {
  2502. foreach (Control c in tabPage_DebugInfo.Controls)
  2503. {
  2504. if ((c is TextBox))
  2505. {
  2506. if (c.Name != textBox_ErrorCode.ToString())
  2507. c.Text = "---";
  2508. }
  2509. }
  2510. }
  2511. /// <summary>
  2512. /// 读取马达参数
  2513. /// </summary>
  2514. /// <param name="sender"></param>
  2515. /// <param name="e"></param>
  2516. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2517. {
  2518. richTextBox_MotorParam.Clear();
  2519. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2520. }
  2521. /// <summary>
  2522. /// 写入马达参数
  2523. /// </summary>
  2524. /// <param name="sender"></param>
  2525. /// <param name="e"></param>
  2526. private void button_Write_Click(object sender, EventArgs e)
  2527. {
  2528. var ConfigParam = new byte[40];
  2529. for (int i = 0; i < 40; i++)
  2530. ConfigParam[i] = 0;
  2531. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2532. short wDataTemp = 0;
  2533. ushort DataTemp = 0;
  2534. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2535. try
  2536. {
  2537. for (int i = 0; i < strDataTemp.Length; i++)
  2538. {
  2539. if (i == 6)
  2540. {
  2541. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2542. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2543. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2544. }
  2545. else
  2546. {
  2547. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2548. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2549. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2550. }
  2551. }
  2552. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2553. }
  2554. catch (Exception)
  2555. {
  2556. timer_1s.Enabled = false;
  2557. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2558. timer_1s.Enabled = true;
  2559. }
  2560. }
  2561. /// <summary>
  2562. /// 读取整车信息
  2563. /// </summary>
  2564. /// <param name="sender"></param>
  2565. /// <param name="e"></param>
  2566. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2567. {
  2568. richTextBox_BikeParam.Clear();
  2569. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2570. }
  2571. /// <summary>
  2572. /// 写入整车信息
  2573. /// </summary>
  2574. /// <param name="sender"></param>
  2575. /// <param name="e"></param>
  2576. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2577. {
  2578. var ConfigParam = new byte[28];
  2579. for (int i = 0; i < 28; i++)
  2580. ConfigParam[i] = 0;
  2581. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2582. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2583. try
  2584. {
  2585. for (int i = 0; i < strDataTemp.Length; i++)
  2586. {
  2587. short wDataTemp = 0;
  2588. //前后灯参数修改
  2589. if (i == 8)
  2590. {
  2591. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2592. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2593. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2594. }
  2595. //开关机参数
  2596. else if (i == 11)
  2597. {
  2598. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2599. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2600. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2601. }
  2602. else
  2603. {
  2604. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2605. }
  2606. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2607. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2608. }
  2609. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2610. }
  2611. catch (Exception)
  2612. {
  2613. timer_1s.Enabled = false;
  2614. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2615. timer_1s.Enabled = true;
  2616. }
  2617. }
  2618. /// <summary>
  2619. /// 读取控制器参数
  2620. /// </summary>
  2621. /// <param name="sender"></param>
  2622. /// <param name="e"></param>
  2623. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2624. {
  2625. richTextBox_ControlParam.Clear();
  2626. comboBox_Bike_CCS.SelectedIndex = 0;
  2627. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2628. }
  2629. /// <summary>
  2630. /// 写入控制器参数
  2631. /// </summary>
  2632. /// <param name="sender"></param>
  2633. /// <param name="e"></param>
  2634. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2635. {
  2636. var ConfigParam = new byte[34];
  2637. for (int i = 0; i < 34; i++)
  2638. ConfigParam[i] = 0;
  2639. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2640. ushort uwDataTemp = 0;
  2641. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2642. try
  2643. {
  2644. for (int i = 0; i < strDataTemp.Length; i++)
  2645. {
  2646. if (i == 13)
  2647. {
  2648. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2649. }
  2650. else
  2651. {
  2652. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2653. }
  2654. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2655. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2656. }
  2657. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2658. }
  2659. catch (Exception)
  2660. {
  2661. timer_1s.Enabled = false;
  2662. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2663. timer_1s.Enabled = true;
  2664. }
  2665. }
  2666. /// <summary>
  2667. /// 读取助力参数
  2668. /// </summary>
  2669. /// <param name="sender"></param>
  2670. /// <param name="e"></param>
  2671. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2672. {
  2673. var ConfigParam = new byte[4];
  2674. int AssistNum = 0;
  2675. try
  2676. {
  2677. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2678. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2679. ConfigParam[1] = (byte)(AssistNum >> 8);
  2680. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2681. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2682. ConfigParam[3] = (byte)(AssistNum >> 8);
  2683. richTextBox_AssistParam.Clear();
  2684. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2685. }
  2686. catch (Exception)
  2687. {
  2688. timer_1s.Enabled = false;
  2689. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2690. timer_1s.Enabled = true;
  2691. }
  2692. }
  2693. /// <summary>
  2694. /// 写入助力参数
  2695. /// </summary>
  2696. /// <param name="sender"></param>
  2697. /// <param name="e"></param>
  2698. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2699. {
  2700. var ConfigParam = new byte[80];
  2701. for (int i = 0; i < 80; i++)
  2702. ConfigParam[i] = 0;
  2703. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2704. long lDataTemp = 0;
  2705. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2706. int index_1 = 0, index_2 = 0;
  2707. try
  2708. {
  2709. for (int i = 0; i < strDataTemp.Length; i++)
  2710. {
  2711. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2712. {
  2713. index_1 = i;
  2714. break;
  2715. }
  2716. }
  2717. for (int i = 0; i < strDataTemp.Length; i++)
  2718. {
  2719. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2720. {
  2721. index_2 = i;
  2722. break;
  2723. }
  2724. }
  2725. for (int i = 0; i < strDataTemp.Length; i++)
  2726. {
  2727. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2728. if (i < index_1)
  2729. {
  2730. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2731. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2732. }
  2733. else if (i <= index_2)
  2734. {
  2735. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2736. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2737. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2738. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2739. }
  2740. else
  2741. {
  2742. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2743. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2744. }
  2745. }
  2746. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2747. }
  2748. catch (Exception)
  2749. {
  2750. timer_1s.Enabled = false;
  2751. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2752. timer_1s.Enabled = true;
  2753. }
  2754. }
  2755. /// <summary>
  2756. /// 读取调试参数
  2757. /// </summary>
  2758. /// <param name="sender"></param>
  2759. /// <param name="e"></param>
  2760. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2761. {
  2762. richTextBox_DebugParam.Clear();
  2763. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2764. }
  2765. /// <summary>
  2766. /// 写入调试参数
  2767. /// </summary>
  2768. /// <param name="sender"></param>
  2769. /// <param name="e"></param>
  2770. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2771. {
  2772. var ConfigParam = new byte[60];
  2773. for (int i = 0; i < 60; i++)
  2774. ConfigParam[i] = 0;
  2775. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2776. ushort uwDataTemp = 0;
  2777. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2778. try
  2779. {
  2780. for (int i = 0; i < strDataTemp.Length; i++)
  2781. {
  2782. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2783. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2784. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2785. }
  2786. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2787. }
  2788. catch (Exception)
  2789. {
  2790. timer_1s.Enabled = false;
  2791. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2792. timer_1s.Enabled = true;
  2793. }
  2794. }
  2795. /// <summary>
  2796. /// 读取历史
  2797. /// </summary>
  2798. /// <param name="sender"></param>
  2799. /// <param name="e"></param>
  2800. private void button_ReadRecord_Click(object sender, EventArgs e)
  2801. {
  2802. richTextBox_Record.Clear();
  2803. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2804. }
  2805. /// <summary>
  2806. /// 读取传感器参数
  2807. /// </summary>
  2808. /// <param name="sender"></param>
  2809. /// <param name="e"></param>
  2810. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2811. {
  2812. richTextBox_SensorParam.Clear();
  2813. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2814. }
  2815. /// <summary>
  2816. /// 写入力矩传感器标定值
  2817. /// </summary>
  2818. /// <param name="sender"></param>
  2819. /// <param name="e"></param>
  2820. private void button_Write_Cal_Click(object sender, EventArgs e)
  2821. {
  2822. var ConfigParam = new byte[4];
  2823. for (int i = 0; i < 4; i++)
  2824. ConfigParam[i] = 0;
  2825. ushort uwDataTemp = 0;
  2826. try
  2827. {
  2828. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2829. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2830. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2831. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2832. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2833. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2834. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2835. }
  2836. catch (Exception)
  2837. {
  2838. timer_1s.Enabled = false;
  2839. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2840. timer_1s.Enabled = true;
  2841. }
  2842. }
  2843. /// <summary>
  2844. /// 写入传感器参数
  2845. /// </summary>
  2846. /// <param name="sender"></param>
  2847. /// <param name="e"></param>
  2848. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2849. {
  2850. var ConfigParam = new byte[14];
  2851. for (int i = 0; i < 14; i++)
  2852. ConfigParam[i] = 0;
  2853. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2854. ushort uwDataTemp = 0;
  2855. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2856. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2857. int index = 0;
  2858. try
  2859. {
  2860. for (int i = 0; i < strDataTemp.Length; i++)
  2861. {
  2862. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2863. {
  2864. index = i;
  2865. break;
  2866. }
  2867. }
  2868. for (int i = 0; i < (strDataTemp.Length - index); i++)
  2869. {
  2870. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  2871. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2872. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2873. }
  2874. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  2875. }
  2876. catch (Exception)
  2877. {
  2878. timer_1s.Enabled = false;
  2879. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2880. timer_1s.Enabled = true;
  2881. }
  2882. }
  2883. /// <summary>
  2884. /// 写入型号
  2885. /// </summary>
  2886. /// <param name="sender"></param>
  2887. /// <param name="e"></param>
  2888. private void button_WriteModel_Click(object sender, EventArgs e)
  2889. {
  2890. string Mode = textBox_Model.Text;
  2891. var ModeArray = new byte[16];
  2892. for (ushort i = 0; i < Mode.Length; i++)
  2893. {
  2894. ModeArray[i] = (byte)Mode[i];
  2895. }
  2896. if (Mode.Length < 16)
  2897. {
  2898. ModeArray[Mode.Length] = (byte)'.';
  2899. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2900. {
  2901. ModeArray[Mode.Length + 1 + i] = 0x20;
  2902. }
  2903. }
  2904. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2905. }
  2906. /// <summary>
  2907. /// 写入SN
  2908. /// </summary>
  2909. /// <param name="sender"></param>
  2910. /// <param name="e"></param>
  2911. private void button_WriteSN_Click(object sender, EventArgs e)
  2912. {
  2913. string SN = textBox_SN.Text;
  2914. var SNArray = new byte[16];
  2915. for (ushort i = 0; i < SN.Length; i++)
  2916. {
  2917. SNArray[i] = (byte)SN[i];
  2918. }
  2919. if (SN.Length < 16)
  2920. {
  2921. SNArray[SN.Length] = (byte)'.';
  2922. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2923. {
  2924. SNArray[SN.Length + 1 + i] = 0x20;
  2925. }
  2926. }
  2927. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2928. }
  2929. /// <summary>
  2930. /// 查询版本信息
  2931. /// </summary>
  2932. /// <param name="sender"></param>
  2933. /// <param name="e"></param>
  2934. private void button_ReadVersion_Click(object sender, EventArgs e)
  2935. {
  2936. textBox_Model.Text = "---";
  2937. textBox_SN.Text = "---";
  2938. textBox_HW.Text = "---";
  2939. textBox_FW.Text = "---";
  2940. textBox_SP.Text = "---";
  2941. textBox_OBC_ReadModel.Text = "---";
  2942. textBox_OBC_ReadSN.Text = "---";
  2943. textBox_OBC_ReadHW.Text = "---";
  2944. textBox_OBC_ReadFW.Text = "---";
  2945. textBox_OBC_ReadSP.Text = "---";
  2946. textBox_FacModeName.Text = "---";
  2947. textBox_FacModeNum.Text = "---";
  2948. textBox_FacModeHW.Text = "---";
  2949. textBox_FacModeFW.Text = "---";
  2950. textBox_FacModeSP.Text = "---";
  2951. Class_Motor_Ver.Mode = "---";
  2952. Class_Motor_Ver.SN = "---";
  2953. Class_Motor_Ver.HW = "---";
  2954. Class_Motor_Ver.FW = "---";
  2955. Class_Motor_Ver.Special = "---";
  2956. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2957. }
  2958. /// <summary>
  2959. /// 查询自定义1
  2960. /// </summary>
  2961. /// <param name="sender"></param>
  2962. /// <param name="e"></param>
  2963. private void button_ReadUser1_Click(object sender, EventArgs e)
  2964. {
  2965. textBox_User1.Text = "---";
  2966. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  2967. }
  2968. /// <summary>
  2969. /// 查询自定义2
  2970. /// </summary>
  2971. /// <param name="sender"></param>
  2972. /// <param name="e"></param>
  2973. private void button_ReadUser2_Click(object sender, EventArgs e)
  2974. {
  2975. textBox_User2.Text = "---";
  2976. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  2977. }
  2978. /// <summary>
  2979. /// 查询自定义3
  2980. /// </summary>
  2981. /// <param name="sender"></param>
  2982. /// <param name="e"></param>
  2983. private void button_ReadUser3_Click(object sender, EventArgs e)
  2984. {
  2985. textBox_User3.Text = "---";
  2986. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  2987. }
  2988. /// <summary>
  2989. /// 写入自定义字符串1
  2990. /// </summary>
  2991. /// <param name="sender"></param>
  2992. /// <param name="e"></param>
  2993. private void button_WriteUser1_Click(object sender, EventArgs e)
  2994. {
  2995. string User = textBox_User1.Text;
  2996. var UserArray = new byte[16];
  2997. for (ushort i = 0; i < User.Length; i++)
  2998. {
  2999. UserArray[i] = (byte)User[i];
  3000. }
  3001. if (User.Length < 16)
  3002. {
  3003. UserArray[User.Length] = (byte)'.';
  3004. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3005. {
  3006. UserArray[User.Length + 1 + i] = 0x20;
  3007. }
  3008. }
  3009. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3010. }
  3011. /// <summary>
  3012. /// 写入自定义字符串2
  3013. /// </summary>
  3014. /// <param name="sender"></param>
  3015. /// <param name="e"></param>
  3016. private void button_WriteUser2_Click(object sender, EventArgs e)
  3017. {
  3018. string User = textBox_User2.Text;
  3019. var UserArray = new byte[16];
  3020. for (ushort i = 0; i < User.Length; i++)
  3021. {
  3022. UserArray[i] = (byte)User[i];
  3023. }
  3024. if (User.Length < 16)
  3025. {
  3026. UserArray[User.Length] = (byte)'.';
  3027. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3028. {
  3029. UserArray[User.Length + 1 + i] = 0x20;
  3030. }
  3031. }
  3032. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3033. }
  3034. /// <summary>
  3035. /// 写入自定义字符串3
  3036. /// </summary>
  3037. /// <param name="sender"></param>
  3038. /// <param name="e"></param>
  3039. private void button_WriteUser3_Click(object sender, EventArgs e)
  3040. {
  3041. string User = textBox_User3.Text;
  3042. var UserArray = new byte[16];
  3043. for (ushort i = 0; i < User.Length; i++)
  3044. {
  3045. UserArray[i] = (byte)User[i];
  3046. }
  3047. if (User.Length < 16)
  3048. {
  3049. UserArray[User.Length] = (byte)'.';
  3050. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3051. {
  3052. UserArray[User.Length + 1 + i] = 0x20;
  3053. }
  3054. }
  3055. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3056. }
  3057. /// <summary>
  3058. /// 查询生产信息
  3059. /// </summary>
  3060. /// <param name="sender"></param>
  3061. /// <param name="e"></param>
  3062. private void button_ReadMAC_Click(object sender, EventArgs e)
  3063. {
  3064. textBox_MAC.Text = "---";
  3065. textBox_MACAdd.Text = "---";
  3066. textBox_MACDate.Text = "---";
  3067. textBox_PP.Text = "---";
  3068. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3069. }
  3070. /// <summary>
  3071. /// 写入生产信息
  3072. /// </summary>
  3073. /// <param name="sender"></param>
  3074. /// <param name="e"></param>
  3075. private void button_WriteMac_Click(object sender, EventArgs e)
  3076. {
  3077. var MACArray = new byte[32];
  3078. //填入生产商
  3079. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3080. {
  3081. MACArray[i] = (byte)textBox_MAC.Text[i];
  3082. }
  3083. if (textBox_MAC.Text.Length < 8)
  3084. {
  3085. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3086. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3087. {
  3088. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3089. }
  3090. }
  3091. //填入生产地
  3092. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3093. {
  3094. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3095. }
  3096. if (textBox_MACAdd.Text.Length < 8)
  3097. {
  3098. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3099. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3100. {
  3101. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3102. }
  3103. }
  3104. //填入生产日期
  3105. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3106. {
  3107. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3108. }
  3109. if (textBox_MACDate.Text.Length < 8)
  3110. {
  3111. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3112. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3113. {
  3114. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3115. }
  3116. }
  3117. //填入品牌
  3118. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3119. {
  3120. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3121. }
  3122. if (textBox_PP.Text.Length < 8)
  3123. {
  3124. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3125. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3126. {
  3127. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3128. }
  3129. }
  3130. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3131. }
  3132. /// <summary>
  3133. /// 查询密钥
  3134. /// </summary>
  3135. /// <param name="sender"></param>
  3136. /// <param name="e"></param>
  3137. private void button_ReadKey_Click(object sender, EventArgs e)
  3138. {
  3139. textBox_Key.Text = "---";
  3140. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3141. }
  3142. /// <summary>
  3143. /// 写入校验密钥
  3144. /// </summary>
  3145. /// <param name="sender"></param>
  3146. /// <param name="e"></param>
  3147. private void button_WriteKey_Click(object sender, EventArgs e)
  3148. {
  3149. string Key = textBox_Key.Text;
  3150. var KeyArray = new byte[8];
  3151. if (Key.Length != 8)
  3152. {
  3153. timer_1s.Enabled = false;
  3154. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3155. timer_1s.Enabled = true;
  3156. return;
  3157. }
  3158. for (ushort i = 0; i < Key.Length; i++)
  3159. {
  3160. KeyArray[i] = (byte)Key[i];
  3161. }
  3162. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3163. }
  3164. /// <summary>
  3165. /// 查询在线检测结果
  3166. /// </summary>
  3167. /// <param name="sender"></param>
  3168. /// <param name="e"></param>
  3169. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3170. {
  3171. textBox_Online.Text = "---";
  3172. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3173. }
  3174. /// <summary>
  3175. /// 系统清除
  3176. /// </summary>
  3177. /// <param name="sender"></param>
  3178. /// <param name="e"></param>
  3179. private void button_SystemClear_Click(object sender, EventArgs e)
  3180. {
  3181. var Code = new byte[5];
  3182. Code[0] = (byte)'C';
  3183. Code[1] = (byte)'L';
  3184. Code[2] = (byte)'E';
  3185. Code[3] = (byte)'A';
  3186. Code[4] = (byte)'R';
  3187. timer_1s.Enabled = false;
  3188. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3189. {
  3190. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3191. {
  3192. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3193. {
  3194. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3195. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3196. }
  3197. }
  3198. }
  3199. timer_1s.Enabled = true;
  3200. }
  3201. /// <summary>
  3202. /// 参数还原
  3203. /// </summary>
  3204. /// <param name="sender"></param>
  3205. /// <param name="e"></param>
  3206. private void button_Recovery_Click(object sender, EventArgs e)
  3207. {
  3208. var Code = new byte[8];
  3209. Code[0] = (byte)'R';
  3210. Code[1] = (byte)'E';
  3211. Code[2] = (byte)'C';
  3212. Code[3] = (byte)'O';
  3213. Code[4] = (byte)'V';
  3214. Code[5] = (byte)'E';
  3215. Code[6] = (byte)'R';
  3216. Code[7] = (byte)'Y';
  3217. timer_1s.Enabled = false;
  3218. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3219. {
  3220. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3221. {
  3222. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3223. {
  3224. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3225. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3226. }
  3227. }
  3228. }
  3229. timer_1s.Enabled = true;
  3230. }
  3231. /// <summary>
  3232. /// 系统复位
  3233. /// </summary>
  3234. /// <param name="sender"></param>
  3235. /// <param name="e"></param>
  3236. private void button_Reset_Click(object sender, EventArgs e)
  3237. {
  3238. var Code_Off = new byte[5];
  3239. var Code_Reset = new byte[5];
  3240. Code_Off[0] = (byte)'O';
  3241. Code_Off[1] = (byte)'F';
  3242. Code_Off[2] = (byte)'F';
  3243. Code_Off[3] = (byte)'.';
  3244. Code_Off[4] = (byte)'.';
  3245. Code_Reset[0] = (byte)'R';
  3246. Code_Reset[1] = (byte)'E';
  3247. Code_Reset[2] = (byte)'S';
  3248. Code_Reset[3] = (byte)'E';
  3249. Code_Reset[4] = (byte)'T';
  3250. timer_1s.Enabled = false;
  3251. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3252. {
  3253. timer_1s.Enabled = true;
  3254. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3255. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3256. PowerOffAckStatus = false;
  3257. Delay_ms(250);
  3258. int TryCnt = 3;
  3259. while ((TryCnt--) >= 0)
  3260. {
  3261. if (!PowerOffAckStatus)
  3262. {
  3263. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3264. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3265. PowerOffAckStatus = false;
  3266. Delay_ms(250);
  3267. }
  3268. else break;
  3269. }
  3270. if (PowerOffAckStatus)
  3271. {
  3272. timer_1s.Enabled = false;
  3273. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3274. timer_1s.Enabled = true;
  3275. }
  3276. else
  3277. {
  3278. timer_1s.Enabled = false;
  3279. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3280. timer_1s.Enabled = true;
  3281. }
  3282. }
  3283. timer_1s.Enabled = true;
  3284. }
  3285. /// <summary>
  3286. /// 记录清除
  3287. /// </summary>
  3288. /// <param name="sender"></param>
  3289. /// <param name="e"></param>
  3290. private void button_ClearLog_Click(object sender, EventArgs e)
  3291. {
  3292. var Code = new byte[9];
  3293. Code[0] = (byte)'L';
  3294. Code[1] = (byte)'O';
  3295. Code[2] = (byte)'G';
  3296. Code[3] = (byte)' ';
  3297. Code[4] = (byte)'C';
  3298. Code[5] = (byte)'L';
  3299. Code[6] = (byte)'E';
  3300. Code[7] = (byte)'A';
  3301. Code[8] = (byte)'R';
  3302. timer_1s.Enabled = false;
  3303. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3304. {
  3305. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3306. {
  3307. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3308. {
  3309. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3310. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3311. }
  3312. }
  3313. }
  3314. timer_1s.Enabled = true;
  3315. }
  3316. /// <summary>
  3317. /// 打开系统计算器
  3318. /// </summary>
  3319. /// <param name="sender"></param>
  3320. /// <param name="e"></param>
  3321. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3322. {
  3323. System.Diagnostics.Process.Start("calc.exe");
  3324. }
  3325. /// <summary>
  3326. ///故障转换和显示
  3327. /// </summary>
  3328. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3329. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3330. "",""};
  3331. private string ErrorInfoDisplay(UInt32 Code)
  3332. {
  3333. string Result = "";
  3334. if (Code == 0)
  3335. {
  3336. Result = "无故障";
  3337. }
  3338. else
  3339. {
  3340. for (int i = 0; i < 32; i++)
  3341. {
  3342. if ((Code & 0x01) == 0x01)
  3343. {
  3344. Result += ErrorInfo[i] + " ";
  3345. }
  3346. Code >>= 1;
  3347. }
  3348. }
  3349. return Result;
  3350. }
  3351. /// <summary>
  3352. /// 鼠标滑过故障码显示具体内容
  3353. /// </summary>
  3354. /// <param name="sender"></param>
  3355. /// <param name="e"></param>
  3356. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3357. {
  3358. // 创建the ToolTip
  3359. ToolTip toolTip1 = new ToolTip();
  3360. // 设置显示样式
  3361. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3362. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3363. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3364. toolTip1.ShowAlways = true;//是否显示提示框
  3365. // 设置伴随的对象.
  3366. string ErrorCode = this.textBox_ErrorCode.Text;
  3367. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3368. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3369. }
  3370. /// <summary>
  3371. /// 数据记录
  3372. /// </summary>
  3373. private void RunInfoAutoSave()
  3374. {
  3375. if (运行信息记录ToolStripMenuItem.Checked == true)
  3376. {
  3377. if (RunInfoSaveFilename == string.Empty)
  3378. {
  3379. return;
  3380. }
  3381. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3382. foreach (Control c in tabPage_RunInfo.Controls)
  3383. {
  3384. if (c is TextBox)
  3385. {
  3386. SaveData += c.Text + " , ";
  3387. }
  3388. }
  3389. foreach (Control c in tabPage_DebugInfo.Controls)
  3390. {
  3391. if (c is TextBox)
  3392. {
  3393. SaveData += c.Text + " , ";
  3394. }
  3395. }
  3396. SaveData += "\r\n";
  3397. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3398. }
  3399. }
  3400. /// <summary>
  3401. /// 打开或关闭数据记录
  3402. /// </summary>
  3403. /// <param name="sender"></param>
  3404. /// <param name="e"></param>
  3405. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3406. {
  3407. if (运行信息记录ToolStripMenuItem.Checked == false)
  3408. {
  3409. if (mySerialProcess.mySerial.IsOpen == true)
  3410. {
  3411. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3412. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3413. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3414. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3415. timer_1s.Enabled = false;
  3416. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3417. timer_1s.Enabled = true;
  3418. 运行信息记录ToolStripMenuItem.Checked = true;
  3419. }
  3420. else
  3421. {
  3422. timer_1s.Enabled = false;
  3423. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3424. timer_1s.Enabled = true;
  3425. }
  3426. }
  3427. else
  3428. {
  3429. 运行信息记录ToolStripMenuItem.Checked = false;
  3430. timer_1s.Enabled = false;
  3431. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3432. timer_1s.Enabled = true;
  3433. }
  3434. }
  3435. /// <summary>
  3436. /// 仪表启动控制档位开关事件
  3437. /// </summary>
  3438. /// <param name="sender"></param>
  3439. /// <param name="e"></param>
  3440. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3441. {
  3442. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3443. {
  3444. //检查串口是否打开
  3445. if (!mySerialProcess.mySerial.IsOpen)
  3446. {
  3447. timer_1s.Enabled = false;
  3448. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3449. timer_1s.Enabled = true;
  3450. checkBox_OBC_StartSetGearSt.Checked = false;
  3451. return;
  3452. }
  3453. //检查是否选择档位和打开车灯
  3454. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3455. {
  3456. timer_1s.Enabled = false;
  3457. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3458. timer_1s.Enabled = true;
  3459. checkBox_OBC_StartSetGearSt.Checked = false;
  3460. return;
  3461. }
  3462. }
  3463. }
  3464. /// <summary>
  3465. /// OBC查询电机用户参数
  3466. /// </summary>
  3467. /// <param name="sender"></param>
  3468. /// <param name="e"></param>
  3469. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3470. {
  3471. richTextBox_OBC_ReadUserInfo.Clear();
  3472. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3473. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3474. }
  3475. /// <summary>
  3476. /// OBC设置电机用户参数
  3477. /// </summary>
  3478. /// <param name="sender"></param>
  3479. /// <param name="e"></param>
  3480. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3481. {
  3482. var UserInfoCode = new byte[8];
  3483. for (int i = 0; i < UserInfoCode.Length; i++)
  3484. UserInfoCode[i] = 0;
  3485. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3486. {
  3487. timer_1s.Enabled = false;
  3488. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3489. timer_1s.Enabled = true;
  3490. return;
  3491. }
  3492. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3493. {
  3494. timer_1s.Enabled = false;
  3495. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3496. timer_1s.Enabled = true;
  3497. return;
  3498. }
  3499. //周长微调
  3500. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3501. //启动模式
  3502. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3503. //助力方案
  3504. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3505. //自动关机时间
  3506. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3507. //限速微调
  3508. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3509. //定速巡航开关
  3510. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3511. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3512. }
  3513. /// <summary>
  3514. /// OBC查询电机版本信息
  3515. /// </summary>
  3516. /// <param name="sender"></param>
  3517. /// <param name="e"></param>
  3518. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3519. {
  3520. textBox_Model.Text = "---";
  3521. textBox_SN.Text = "---";
  3522. textBox_HW.Text = "---";
  3523. textBox_FW.Text = "---";
  3524. textBox_SP.Text = "---";
  3525. textBox_OBC_ReadModel.Text = "---";
  3526. textBox_OBC_ReadSN.Text = "---";
  3527. textBox_OBC_ReadHW.Text = "---";
  3528. textBox_OBC_ReadFW.Text = "---";
  3529. textBox_OBC_ReadSP.Text = "---";
  3530. textBox_FacModeName.Text = "---";
  3531. textBox_FacModeNum.Text = "---";
  3532. textBox_FacModeHW.Text = "---";
  3533. textBox_FacModeFW.Text = "---";
  3534. textBox_FacModeSP.Text = "---";
  3535. Class_Motor_Ver.Mode = "---";
  3536. Class_Motor_Ver.SN = "---";
  3537. Class_Motor_Ver.HW = "---";
  3538. Class_Motor_Ver.FW = "---";
  3539. Class_Motor_Ver.Special = "---";
  3540. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3541. }
  3542. /// <summary>
  3543. /// OBC读取骑行历史
  3544. /// </summary>
  3545. /// <param name="sender"></param>
  3546. /// <param name="e"></param>
  3547. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3548. {
  3549. textBox_OBC_TRIP_KM.Text = "";
  3550. textBox_OBC_TRIP_TIME.Text = "";
  3551. textBox_OBC_ODO_KM.Text = "";
  3552. textBox_OBC_ODO_TIME.Text = "";
  3553. textBox_ODO_KM.Text = "---";
  3554. textBox_ODO_TIME.Text = "---";
  3555. textBox_TRIP_KM.Text = "---";
  3556. textBox_TRIP_TIME.Text = "---";
  3557. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3558. }
  3559. /// <summary>
  3560. /// OBC清除TRIP里程
  3561. /// </summary>
  3562. /// <param name="sender"></param>
  3563. /// <param name="e"></param>
  3564. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3565. {
  3566. var Code = new byte[5];
  3567. Code[0] = (byte)'C';
  3568. Code[1] = (byte)'L';
  3569. Code[2] = (byte)'E';
  3570. Code[3] = (byte)'A';
  3571. Code[4] = (byte)'R';
  3572. timer_1s.Enabled = false;
  3573. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3574. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3575. timer_1s.Enabled = true;
  3576. }
  3577. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3578. {
  3579. if (checkBox_OBC_StartReadBMS.Checked == true)
  3580. {
  3581. //检查串口是否打开
  3582. if (!mySerialProcess.mySerial.IsOpen)
  3583. {
  3584. timer_1s.Enabled = false;
  3585. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3586. timer_1s.Enabled = true;
  3587. checkBox_OBC_StartReadBMS.Checked = false;
  3588. return;
  3589. }
  3590. }
  3591. }
  3592. /// <summary>
  3593. /// 写入力矩传感器参数
  3594. /// </summary>
  3595. /// <param name="sender"></param>
  3596. /// <param name="e"></param>
  3597. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3598. {
  3599. var ConfigParam = new byte[46];
  3600. for (int i = 0; i < 14; i++)
  3601. ConfigParam[i] = 0;
  3602. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3603. ushort uwDataTemp = 0;
  3604. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3605. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3606. int index = 0;
  3607. try
  3608. {
  3609. for (int i = 0; i < strDataTemp.Length; i++)
  3610. {
  3611. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3612. {
  3613. index = i;
  3614. break;
  3615. }
  3616. }
  3617. for (int i = 0; i < (index + 1); i++)
  3618. {
  3619. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3620. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3621. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3622. }
  3623. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3624. }
  3625. catch (Exception)
  3626. {
  3627. timer_1s.Enabled = false;
  3628. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3629. timer_1s.Enabled = true;
  3630. }
  3631. }
  3632. /// <summary>
  3633. /// 查询存储标志
  3634. /// </summary>
  3635. /// <param name="sender"></param>
  3636. /// <param name="e"></param>
  3637. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3638. {
  3639. radioButton_EE_SaveYes.Checked = false;
  3640. radioButton_EE_SaveNo.Checked = false;
  3641. radioButton_SIP_SaveYes.Checked = false;
  3642. radioButton_SIP_SaveNo.Checked = false;
  3643. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3644. }
  3645. /// <summary>
  3646. /// 写入存储标志
  3647. /// </summary>
  3648. /// <param name="sender"></param>
  3649. /// <param name="e"></param>
  3650. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3651. {
  3652. var SaveFlag = new byte[6];
  3653. for (int i = 0; i < 6; i++)
  3654. SaveFlag[i] = 0;
  3655. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3656. {
  3657. timer_1s.Enabled = false;
  3658. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3659. timer_1s.Enabled = true;
  3660. return;
  3661. }
  3662. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3663. {
  3664. timer_1s.Enabled = false;
  3665. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3666. timer_1s.Enabled = true;
  3667. return;
  3668. }
  3669. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3670. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3671. SaveFlag[3] = 0;
  3672. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3673. SaveFlag[5] = 0;
  3674. timer_1s.Enabled = false;
  3675. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3676. {
  3677. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3678. }
  3679. timer_1s.Enabled = true;
  3680. }
  3681. /// <summary>
  3682. /// 读取指定地址数据
  3683. /// </summary>
  3684. /// <param name="sender"></param>
  3685. /// <param name="e"></param>
  3686. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3687. {
  3688. var Address = new byte[4];
  3689. UInt32 Address_Begin;
  3690. UInt32 Addres_End;
  3691. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3692. richTextBox_RamFlasgData.Clear();
  3693. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3694. {
  3695. timer_1s.Enabled = false;
  3696. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3697. timer_1s.Enabled = true;
  3698. return;
  3699. }
  3700. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3701. {
  3702. timer_1s.Enabled = false;
  3703. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3704. timer_1s.Enabled = true;
  3705. return;
  3706. }
  3707. else
  3708. {
  3709. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3710. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3711. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3712. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3713. if (Addres_End < Address_Begin)
  3714. {
  3715. timer_1s.Enabled = false;
  3716. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3717. timer_1s.Enabled = true;
  3718. return;
  3719. }
  3720. else
  3721. {
  3722. var SendByte = new byte[8];
  3723. SendByte[0] = (byte)(Address_Begin >> 24);
  3724. SendByte[1] = (byte)(Address_Begin >> 16);
  3725. SendByte[2] = (byte)(Address_Begin >> 8);
  3726. SendByte[3] = (byte)(Address_Begin);
  3727. SendByte[4] = (byte)(Addres_End >> 24);
  3728. SendByte[5] = (byte)(Addres_End >> 16);
  3729. SendByte[6] = (byte)(Addres_End >> 8);
  3730. SendByte[7] = (byte)(Addres_End);
  3731. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3732. }
  3733. }
  3734. }
  3735. /// <summary>
  3736. /// 工作模式选择
  3737. /// </summary>
  3738. /// <param name="sender"></param>
  3739. /// <param name="e"></param>
  3740. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3741. {
  3742. var RunMode = new byte[1];
  3743. if (comboBox_WorkMode.Text == "配置模式")
  3744. RunMode[0] = 0x01;
  3745. else if (comboBox_WorkMode.Text == "调试模式")
  3746. RunMode[0] = 0x02;
  3747. else
  3748. RunMode[0] = 0x00;
  3749. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3750. }
  3751. /// <summary>
  3752. /// 助力档位选择
  3753. /// </summary>
  3754. /// <param name="sender"></param>
  3755. /// <param name="e"></param>
  3756. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3757. {
  3758. var CtrlCode = new byte[2];
  3759. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3760. CtrlCode[0] = 0x33;
  3761. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3762. CtrlCode[0] = 0x22;
  3763. else
  3764. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3765. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3766. CtrlCode[1] = 0xF1;
  3767. else
  3768. CtrlCode[1] = 0xF0;
  3769. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3770. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3771. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3772. }
  3773. /// <summary>
  3774. /// 仪表档位选择
  3775. /// </summary>
  3776. /// <param name="sender"></param>
  3777. /// <param name="e"></param>
  3778. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3779. {
  3780. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3781. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3782. }
  3783. /// <summary>
  3784. /// 生产模式初始化
  3785. /// </summary>
  3786. /// <param name="sender"></param>
  3787. /// <param name="e"></param>
  3788. private void button_FacModeInit_Click(object sender, EventArgs e)
  3789. {
  3790. var Code = new byte[5];
  3791. Code[0] = (byte)'C';
  3792. Code[1] = (byte)'L';
  3793. Code[2] = (byte)'E';
  3794. Code[3] = (byte)'A';
  3795. Code[4] = (byte)'R';
  3796. timer_1s.Enabled = false;
  3797. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3798. {
  3799. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3800. {
  3801. timer_1s.Enabled = true;
  3802. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3803. PowerOffAckStatus = false;
  3804. Delay_ms(250);
  3805. int TryCnt = 3;
  3806. while ((TryCnt--) >= 0)
  3807. {
  3808. if (!PowerOffAckStatus)
  3809. {
  3810. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3811. PowerOffAckStatus = false;
  3812. Delay_ms(250);
  3813. }
  3814. else break;
  3815. }
  3816. if (PowerOffAckStatus)
  3817. {
  3818. timer_1s.Enabled = false;
  3819. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3820. timer_1s.Enabled = true;
  3821. }
  3822. else
  3823. {
  3824. timer_1s.Enabled = false;
  3825. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3826. timer_1s.Enabled = true;
  3827. }
  3828. timer_1s.Enabled = true;
  3829. }
  3830. }
  3831. timer_1s.Enabled = true;
  3832. //清除历史测试记录
  3833. textBox_FacModeSensorADC0.Text = "";
  3834. textBox_FacModeSensorADC1.Text = "";
  3835. textBox_FacModeSensorADC2.Text = "";
  3836. textBox_FacModeSensorADC3.Text = "";
  3837. textBox_FacModeSensorADC4.Text = "";
  3838. LightSwitchStatus = false;
  3839. MotorRunStatus = false;
  3840. trackBar_FacModeMotorSpeedAdj.Value = 5;
  3841. textBox_FacModeName.Text = "";
  3842. textBox_FacModeNum.Text = "";
  3843. textBox_FacModeHW.Text = "";
  3844. textBox_FacModeFW.Text = "";
  3845. }
  3846. /// <summary>
  3847. /// 生产模式读取传感器参数
  3848. /// </summary>
  3849. /// <param name="sender"></param>
  3850. /// <param name="e"></param>
  3851. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3852. {
  3853. richTextBox_SensorParam.Clear();
  3854. textBox_FacModeSensorADC0.Text = "";
  3855. textBox_FacModeSensorADC1.Text = "";
  3856. textBox_FacModeSensorADC2.Text = "";
  3857. textBox_FacModeSensorADC3.Text = "";
  3858. textBox_FacModeSensorADC4.Text = "";
  3859. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3860. }
  3861. /// <summary>
  3862. /// 生产模式传感器标定1
  3863. /// </summary>
  3864. /// <param name="sender"></param>
  3865. /// <param name="e"></param>
  3866. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  3867. {
  3868. var ConfigParam = new byte[4];
  3869. for (int i = 0; i < 4; i++)
  3870. ConfigParam[i] = 0;
  3871. ushort uwDataTemp = 0;
  3872. try
  3873. {
  3874. uwDataTemp = 1;//负载序号
  3875. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3876. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3877. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  3878. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3879. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3880. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3881. Delay_ms(200);
  3882. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3883. }
  3884. catch (Exception)
  3885. {
  3886. timer_1s.Enabled = false;
  3887. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3888. timer_1s.Enabled = true;
  3889. }
  3890. }
  3891. /// <summary>
  3892. /// 生产模式传感器标定2
  3893. /// </summary>
  3894. /// <param name="sender"></param>
  3895. /// <param name="e"></param>
  3896. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  3897. {
  3898. var ConfigParam = new byte[4];
  3899. for (int i = 0; i < 4; i++)
  3900. ConfigParam[i] = 0;
  3901. ushort uwDataTemp = 0;
  3902. try
  3903. {
  3904. uwDataTemp = 2;//负载序号
  3905. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3906. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3907. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  3908. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3909. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3910. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3911. Delay_ms(200);
  3912. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3913. }
  3914. catch (Exception)
  3915. {
  3916. timer_1s.Enabled = false;
  3917. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3918. timer_1s.Enabled = true;
  3919. }
  3920. }
  3921. /// <summary>
  3922. /// 生产模式传感器标定3
  3923. /// </summary>
  3924. /// <param name="sender"></param>
  3925. /// <param name="e"></param>
  3926. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  3927. {
  3928. var ConfigParam = new byte[4];
  3929. for (int i = 0; i < 4; i++)
  3930. ConfigParam[i] = 0;
  3931. ushort uwDataTemp = 0;
  3932. try
  3933. {
  3934. uwDataTemp = 3;//负载序号
  3935. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3936. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3937. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  3938. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3939. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3940. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3941. Delay_ms(200);
  3942. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3943. }
  3944. catch (Exception)
  3945. {
  3946. timer_1s.Enabled = false;
  3947. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3948. timer_1s.Enabled = true;
  3949. }
  3950. }
  3951. /// <summary>
  3952. /// 生产模式传感器标定3
  3953. /// </summary>
  3954. /// <param name="sender"></param>
  3955. /// <param name="e"></param>
  3956. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  3957. {
  3958. var ConfigParam = new byte[4];
  3959. for (int i = 0; i < 4; i++)
  3960. ConfigParam[i] = 0;
  3961. ushort uwDataTemp = 0;
  3962. try
  3963. {
  3964. uwDataTemp = 4;//负载序号
  3965. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3966. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3967. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  3968. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3969. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3970. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3971. Delay_ms(200);
  3972. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3973. }
  3974. catch (Exception)
  3975. {
  3976. timer_1s.Enabled = false;
  3977. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3978. timer_1s.Enabled = true;
  3979. }
  3980. }
  3981. /// <summary>
  3982. /// 生产模式开关灯
  3983. /// </summary>
  3984. /// <param name="sender"></param>
  3985. /// <param name="e"></param>
  3986. bool LightSwitchStatus = false;
  3987. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  3988. {
  3989. var CtrlCode = new byte[2];
  3990. CtrlCode[0] = 0x00;
  3991. if (LightSwitchStatus)
  3992. {
  3993. CtrlCode[1] = 0xF0;
  3994. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  3995. }
  3996. else
  3997. {
  3998. CtrlCode[1] = 0xF1;
  3999. button_FacModeLightSW.BackColor = Color.Yellow;
  4000. }
  4001. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4002. {
  4003. LightSwitchStatus = !LightSwitchStatus;
  4004. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4005. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4006. }
  4007. }
  4008. /// <summary>
  4009. /// 生产模式电机控制
  4010. /// </summary>
  4011. /// <param name="sender"></param>
  4012. /// <param name="e"></param>
  4013. bool MotorRunStatus = false;
  4014. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4015. {
  4016. string DebugDefaultInfo = "";
  4017. //获取调试信息
  4018. if (richTextBox_DebugParam.Text == string.Empty)
  4019. {
  4020. richTextBox_DebugParam.Clear();
  4021. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4022. }
  4023. Delay_ms(200);
  4024. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4025. //获取参数
  4026. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4027. if (strDataTemp.Length != 29)
  4028. {
  4029. timer_1s.Enabled = false;
  4030. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4031. timer_1s.Enabled = true;
  4032. return;
  4033. }
  4034. //设置参数
  4035. var ConfigParam = new byte[60];
  4036. for (int i = 0; i < 60; i++)
  4037. ConfigParam[i] = 0;
  4038. ConfigParam[0] = 0x00;
  4039. ushort uwDataTemp = 0;
  4040. if (!MotorRunStatus) //停止状态
  4041. {
  4042. //设置速度环
  4043. strDataTemp[0] = "整体运行模式=3";
  4044. //发送数据
  4045. try
  4046. {
  4047. for (int i = 0; i < strDataTemp.Length; i++)
  4048. {
  4049. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4050. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4051. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4052. }
  4053. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4054. return;
  4055. }
  4056. catch (Exception)
  4057. {
  4058. timer_1s.Enabled = false;
  4059. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4060. timer_1s.Enabled = true;
  4061. }
  4062. Delay_ms(200);
  4063. //设置转速百分比100%
  4064. trackBar_FacModeMotorSpeedAdj.Value = 100;
  4065. MotorRunStatus = !MotorRunStatus;
  4066. button_FacModeMotorRun.BackColor = Color.Yellow;
  4067. Delay_ms(200);
  4068. //电机进入配置模式
  4069. var RunMode = new byte[1];
  4070. RunMode[0] = 0x01;
  4071. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4072. }
  4073. else //运转状态
  4074. {
  4075. //设置转速百分比0%
  4076. trackBar_FacModeMotorSpeedAdj.Value = 0;
  4077. MotorRunStatus = !MotorRunStatus;
  4078. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4079. Delay_ms(200);
  4080. //还原为原始值
  4081. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4082. try
  4083. {
  4084. for (int i = 0; i < strDataTemp.Length; i++)
  4085. {
  4086. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4087. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4088. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4089. }
  4090. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4091. return;
  4092. }
  4093. catch (Exception)
  4094. {
  4095. timer_1s.Enabled = false;
  4096. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4097. timer_1s.Enabled = true;
  4098. }
  4099. Delay_ms(200);
  4100. //电机退出配置模式
  4101. var RunMode = new byte[1];
  4102. RunMode[0] = 0x00;
  4103. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4104. }
  4105. }
  4106. /// <summary>
  4107. /// 生产模式转速调节
  4108. /// </summary>
  4109. /// <param name="sender"></param>
  4110. /// <param name="e"></param>
  4111. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  4112. {
  4113. //转速百分比更新
  4114. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  4115. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  4116. }
  4117. /// <summary>
  4118. /// 生产模式写入型号
  4119. /// </summary>
  4120. /// <param name="sender"></param>
  4121. /// <param name="e"></param>
  4122. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4123. {
  4124. string Mode = textBox_FacModeName.Text;
  4125. var ModeArray = new byte[16];
  4126. for (ushort i = 0; i < Mode.Length; i++)
  4127. {
  4128. ModeArray[i] = (byte)Mode[i];
  4129. }
  4130. if (Mode.Length < 16)
  4131. {
  4132. ModeArray[Mode.Length] = (byte)'.';
  4133. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4134. {
  4135. ModeArray[Mode.Length + 1 + i] = 0x20;
  4136. }
  4137. }
  4138. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4139. }
  4140. /// <summary>
  4141. /// 生产模式写入SN
  4142. /// </summary>
  4143. /// <param name="sender"></param>
  4144. /// <param name="e"></param>
  4145. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4146. {
  4147. string SN = textBox_FacModeNum.Text;
  4148. var SNArray = new byte[16];
  4149. for (ushort i = 0; i < SN.Length; i++)
  4150. {
  4151. SNArray[i] = (byte)SN[i];
  4152. }
  4153. if (SN.Length < 16)
  4154. {
  4155. SNArray[SN.Length] = (byte)'.';
  4156. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4157. {
  4158. SNArray[SN.Length + 1 + i] = 0x20;
  4159. }
  4160. }
  4161. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4162. }
  4163. /// <summary>
  4164. /// 生产模式读取版本信息
  4165. /// </summary>
  4166. /// <param name="sender"></param>
  4167. /// <param name="e"></param>
  4168. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4169. {
  4170. textBox_Model.Text = "---";
  4171. textBox_SN.Text = "---";
  4172. textBox_HW.Text = "---";
  4173. textBox_FW.Text = "---";
  4174. textBox_SP.Text = "---";
  4175. textBox_OBC_ReadModel.Text = "---";
  4176. textBox_OBC_ReadSN.Text = "---";
  4177. textBox_OBC_ReadHW.Text = "---";
  4178. textBox_OBC_ReadFW.Text = "---";
  4179. textBox_OBC_ReadSP.Text = "---";
  4180. textBox_FacModeName.Text = "---";
  4181. textBox_FacModeNum.Text = "---";
  4182. textBox_FacModeHW.Text = "---";
  4183. textBox_FacModeFW.Text = "---";
  4184. textBox_FacModeSP.Text = "---";
  4185. textBox_FacModeGit.Text = "---";
  4186. Class_Motor_Ver.Mode = "---";
  4187. Class_Motor_Ver.SN = "---";
  4188. Class_Motor_Ver.HW = "---";
  4189. Class_Motor_Ver.FW = "---";
  4190. Class_Motor_Ver.Special = "---";
  4191. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4192. }
  4193. /// <summary>
  4194. /// 生产模式写入生产信息
  4195. /// </summary>
  4196. /// <param name="sender"></param>
  4197. /// <param name="e"></param>
  4198. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4199. {
  4200. var MACArray = new byte[32];
  4201. string MacDefaultInfo = "";
  4202. string MacAddDefaultInfo = "";
  4203. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4204. string MacPPDefaultInfo = "";
  4205. do
  4206. {
  4207. //填入生产商
  4208. if (toolStripTextBox_MAC.Text == string.Empty)
  4209. {
  4210. break;
  4211. }
  4212. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4213. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4214. {
  4215. MACArray[i] = (byte)MacDefaultInfo[i];
  4216. }
  4217. if (MacDefaultInfo.Length < 8)
  4218. {
  4219. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4220. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4221. {
  4222. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4223. }
  4224. }
  4225. //填入生产地
  4226. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4227. {
  4228. break;
  4229. }
  4230. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4231. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4232. {
  4233. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4234. }
  4235. if (MacAddDefaultInfo.Length < 8)
  4236. {
  4237. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4238. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4239. {
  4240. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4241. }
  4242. }
  4243. //填入生产日期
  4244. if (toolStripTextBox_MACDate.Text == string.Empty)
  4245. {
  4246. break;
  4247. }
  4248. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4249. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4250. {
  4251. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4252. }
  4253. if (MacDateDefaultInfo.Length < 8)
  4254. {
  4255. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4256. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4257. {
  4258. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4259. }
  4260. }
  4261. //填入产品标识
  4262. if (toolStripTextBox_MACPD.Text == string.Empty)
  4263. {
  4264. break;
  4265. }
  4266. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4267. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4268. {
  4269. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4270. }
  4271. if (MacPPDefaultInfo.Length < 8)
  4272. {
  4273. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4274. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4275. {
  4276. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4277. }
  4278. }
  4279. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4280. return;
  4281. } while (false);
  4282. timer_1s.Enabled = false;
  4283. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4284. timer_1s.Enabled = true;
  4285. }
  4286. /// <summary>
  4287. /// 生产模式保存测试页面
  4288. /// </summary>
  4289. /// <param name="sender"></param>
  4290. /// <param name="e"></param>
  4291. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4292. {
  4293. Button_FacModeSaveResult.Text = "存储中…";
  4294. string[] AssistParams = new string[15];
  4295. do
  4296. {
  4297. //读取一次马达参数
  4298. richTextBox_MotorParam.Clear();
  4299. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4300. Delay_ms(100);
  4301. //读取一次整车参数
  4302. richTextBox_BikeParam.Clear();
  4303. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4304. Delay_ms(100);
  4305. //读取一次控制参数
  4306. richTextBox_ControlParam.Clear();
  4307. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4308. Delay_ms(100);
  4309. //查询传感器
  4310. richTextBox_SensorParam.Clear();
  4311. textBox_FacModeSensorADC0.Text = "";
  4312. textBox_FacModeSensorADC1.Text = "";
  4313. textBox_FacModeSensorADC2.Text = "";
  4314. textBox_FacModeSensorADC3.Text = "";
  4315. textBox_FacModeSensorADC4.Text = "";
  4316. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4317. Delay_ms(100);
  4318. //读取15次助力参数
  4319. for (int i = 1; i <= 15; i++)
  4320. {
  4321. var ConfigParam = new byte[4];
  4322. richTextBox_AssistParam.Clear();
  4323. ConfigParam[0] = (byte)(i & 0xFF);
  4324. ConfigParam[1] = (byte)(i >> 8);
  4325. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4326. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4327. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4328. Delay_ms(200);
  4329. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4330. }
  4331. //读取一次调试信息
  4332. richTextBox_DebugParam.Clear();
  4333. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4334. Delay_ms(100);
  4335. //读取一次历史信息
  4336. richTextBox_Record.Clear();
  4337. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4338. Delay_ms(100);
  4339. //读取一次电机运行信息
  4340. var CtrlCode = new byte[2];
  4341. CtrlCode[0] = 0x00;
  4342. CtrlCode[1] = 0xF0;
  4343. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4344. Delay_ms(100);
  4345. //读取一次版本信息
  4346. textBox_Model.Text = "---";
  4347. textBox_SN.Text = "---";
  4348. textBox_HW.Text = "---";
  4349. textBox_FW.Text = "---";
  4350. textBox_OBC_ReadModel.Text = "---";
  4351. textBox_OBC_ReadSN.Text = "---";
  4352. textBox_OBC_ReadHW.Text = "---";
  4353. textBox_OBC_ReadFW.Text = "---";
  4354. textBox_FacModeName.Text = "---";
  4355. textBox_FacModeNum.Text = "---";
  4356. textBox_FacModeHW.Text = "---";
  4357. textBox_FacModeFW.Text = "---";
  4358. Class_Motor_Ver.Mode = "---";
  4359. Class_Motor_Ver.SN = "---";
  4360. Class_Motor_Ver.HW = "---";
  4361. Class_Motor_Ver.FW = "---";
  4362. Class_Motor_Ver.Special = "---";
  4363. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4364. Delay_ms(100);
  4365. //读取一次生产信息
  4366. textBox_MAC.Text = "";
  4367. textBox_MACAdd.Text = "";
  4368. textBox_MACDate.Text = "";
  4369. textBox_PP.Text = "";
  4370. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4371. Delay_ms(100);
  4372. //读取一次自定义信息
  4373. textBox_User1.Text = "---";
  4374. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4375. Delay_ms(100);
  4376. textBox_User2.Text = "---";
  4377. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4378. Delay_ms(100);
  4379. textBox_User3.Text = "---";
  4380. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4381. Delay_ms(100);
  4382. //读取一次密钥
  4383. textBox_Key.Text = "---";
  4384. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4385. Delay_ms(100);
  4386. //读取一次存储标志
  4387. radioButton_EE_SaveYes.Checked = false;
  4388. radioButton_EE_SaveNo.Checked = false;
  4389. radioButton_SIP_SaveYes.Checked = false;
  4390. radioButton_SIP_SaveNo.Checked = false;
  4391. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4392. Delay_ms(100);
  4393. //读取一次MOS内阻校准参数
  4394. foreach (Control c in groupBox21.Controls)
  4395. {
  4396. if (c is TextBox)
  4397. c.Text = "";
  4398. }
  4399. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4400. Delay_ms(100);
  4401. //提示检查
  4402. #if false
  4403. timer_1s.Enabled = false;
  4404. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4405. {
  4406. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4407. timer_1s.Enabled = true;
  4408. return;
  4409. }
  4410. timer_1s.Enabled = true;
  4411. Delay_ms(200);
  4412. #endif
  4413. //判断数据是否有效
  4414. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4415. {
  4416. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4417. break;
  4418. }
  4419. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4420. {
  4421. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4422. break;
  4423. }
  4424. //设置文件存储路径
  4425. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4426. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4427. Save_Path += PD_PathName;
  4428. if (!Directory.Exists(Save_Path))
  4429. Directory.CreateDirectory(Save_Path);
  4430. //保存页面
  4431. string PIC_SaveFileName = "";
  4432. Double scaleX = PrimaryScreen.ScaleX;
  4433. Double scaleY = PrimaryScreen.ScaleY;
  4434. //保存页面
  4435. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4436. Graphics g = Graphics.FromImage(bit);
  4437. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4438. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4439. bit.Save(PIC_SaveFileName);
  4440. //保存数据
  4441. string DataFileName = "";
  4442. string FileInfo = "";
  4443. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4444. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4445. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4446. FileInfo += "\r\n";
  4447. FileInfo += "[电机信息]\r\n";
  4448. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4449. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4450. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4451. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4452. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4453. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4454. FileInfo += "\r\n";
  4455. FileInfo += "[马达参数]\r\n";
  4456. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4457. FileInfo += "\r\n";
  4458. FileInfo += "[整车参数]\r\n";
  4459. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4460. FileInfo += "\r\n";
  4461. FileInfo += "[控制参数]\r\n";
  4462. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4463. FileInfo += "\r\n";
  4464. FileInfo += "[传感器参数]\r\n";
  4465. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4466. FileInfo += "\r\n";
  4467. FileInfo += "[助力参数]\r\n";
  4468. for(int i=0;i<15;i++)
  4469. {
  4470. FileInfo += AssistParams[i] + "\r\n";
  4471. }
  4472. FileInfo += "[调试参数]\r\n";
  4473. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4474. FileInfo += "\r\n";
  4475. FileInfo += "[历史信息]\r\n";
  4476. FileInfo += richTextBox_Record.Text + "\r\n";
  4477. FileInfo += "\r\n";
  4478. FileInfo += "[MOS内阻校准参数]\r\n";
  4479. FileInfo += textBox_MOS_K1.Text + ", ";
  4480. FileInfo += textBox_MOS_K2.Text + ", ";
  4481. FileInfo += textBox_MOS_K3.Text + ", ";
  4482. FileInfo += textBox_MOS_K4.Text + ", ";
  4483. FileInfo += textBox_MOS_K5.Text + ", ";
  4484. FileInfo += textBox_MOS_R1.Text + ", ";
  4485. FileInfo += textBox_MOS_R2.Text + ", ";
  4486. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4487. FileInfo += "\r\n";
  4488. FileInfo += "[生产信息]\r\n";
  4489. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4490. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4491. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4492. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4493. FileInfo += "\r\n";
  4494. FileInfo += "[自定义信息]\r\n";
  4495. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4496. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4497. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4498. FileInfo += "\r\n";
  4499. FileInfo += "[校验密钥]\r\n";
  4500. FileInfo += textBox_Key.Text + "\r\n";
  4501. FileInfo += "\r\n";
  4502. FileInfo += "[存储标志]\r\n";
  4503. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4504. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4505. FileInfo += "\r\n";
  4506. FileInfo += Local_HdInformation;
  4507. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4508. Delay_ms(1000);
  4509. timer_1s.Enabled = false;
  4510. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4511. timer_1s.Enabled = true;
  4512. //数据上传
  4513. if (myFtp.IsNetConnected == true)
  4514. {
  4515. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4516. //检查路径
  4517. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4518. {
  4519. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4520. }
  4521. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4522. {
  4523. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4524. }
  4525. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4526. {
  4527. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4528. }
  4529. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4530. {
  4531. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4532. }
  4533. //上传文件
  4534. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4535. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4536. if ((result1 & result2) == true)
  4537. {
  4538. timer_1s.Enabled = false;
  4539. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4540. timer_1s.Enabled = true;
  4541. }
  4542. else
  4543. {
  4544. timer_1s.Enabled = false;
  4545. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4546. timer_1s.Enabled = true;
  4547. }
  4548. }
  4549. else
  4550. {
  4551. timer_1s.Enabled = false;
  4552. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4553. timer_1s.Enabled = true;
  4554. }
  4555. Button_FacModeSaveResult.Text = "保存数据";
  4556. return;
  4557. } while (false);
  4558. timer_1s.Enabled = false;
  4559. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4560. timer_1s.Enabled = true;
  4561. Button_FacModeSaveResult.Text = "保存数据";
  4562. }
  4563. /// <summary>
  4564. /// 工具箱页面保存
  4565. /// </summary>
  4566. /// <param name="sender"></param>
  4567. /// <param name="e"></param>
  4568. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4569. {
  4570. Double scaleX = PrimaryScreen.ScaleX;
  4571. Double scaleY = PrimaryScreen.ScaleY;
  4572. //保存页面
  4573. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4574. Graphics g = Graphics.FromImage(bit);
  4575. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4576. SaveFileDialog sf = new SaveFileDialog();
  4577. sf.Title = "页面保存";
  4578. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4579. sf.Filter = "图片|*.png";
  4580. timer_1s.Enabled = false;
  4581. if (sf.ShowDialog() == DialogResult.OK)
  4582. {
  4583. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4584. }
  4585. timer_1s.Enabled = true;
  4586. }
  4587. /// <summary>
  4588. /// 生产模式关机
  4589. /// </summary>
  4590. /// <param name="sender"></param>
  4591. /// <param name="e"></param>
  4592. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4593. {
  4594. var Code_Off = new byte[5];
  4595. var Code_Reset = new byte[5];
  4596. Code_Off[0] = (byte)'O';
  4597. Code_Off[1] = (byte)'F';
  4598. Code_Off[2] = (byte)'F';
  4599. Code_Off[3] = (byte)'.';
  4600. Code_Off[4] = (byte)'.';
  4601. Code_Reset[0] = (byte)'R';
  4602. Code_Reset[1] = (byte)'E';
  4603. Code_Reset[2] = (byte)'S';
  4604. Code_Reset[3] = (byte)'E';
  4605. Code_Reset[4] = (byte)'T';
  4606. timer_1s.Enabled = false;
  4607. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4608. {
  4609. timer_1s.Enabled = true;
  4610. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4611. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4612. PowerOffAckStatus = false;
  4613. Delay_ms(250);
  4614. int TryCnt = 3;
  4615. while ((TryCnt--) >= 0)
  4616. {
  4617. if (!PowerOffAckStatus)
  4618. {
  4619. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4620. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4621. PowerOffAckStatus = false;
  4622. Delay_ms(250);
  4623. }
  4624. else break;
  4625. }
  4626. if (PowerOffAckStatus)
  4627. {
  4628. timer_1s.Enabled = false;
  4629. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4630. timer_1s.Enabled = true;
  4631. }
  4632. else
  4633. {
  4634. timer_1s.Enabled = false;
  4635. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4636. timer_1s.Enabled = true;
  4637. }
  4638. }
  4639. timer_1s.Enabled = true;
  4640. }
  4641. //仪表电源键按下
  4642. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4643. {
  4644. var Code = new byte[2];
  4645. Code[0] = 0;
  4646. Code[1] = 0b00100000;
  4647. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4648. }
  4649. /// <summary>
  4650. /// 仪表加键按下
  4651. /// </summary>
  4652. /// <param name="sender"></param>
  4653. /// <param name="e"></param>
  4654. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4655. {
  4656. var Code = new byte[2];
  4657. Code[0] = 0;
  4658. Code[1] = 0b00010000;
  4659. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4660. }
  4661. /// <summary>
  4662. /// 仪表减键按下
  4663. /// </summary>
  4664. /// <param name="sender"></param>
  4665. /// <param name="e"></param>
  4666. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4667. {
  4668. var Code = new byte[2];
  4669. Code[0] = 0;
  4670. Code[1] = 0b00001000;
  4671. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4672. }
  4673. /// <summary>
  4674. /// 仪表Walk键按下
  4675. /// </summary>
  4676. /// <param name="sender"></param>
  4677. /// <param name="e"></param>
  4678. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4679. {
  4680. var Code = new byte[2];
  4681. Code[0] = 0;
  4682. Code[1] = 0b00000100;
  4683. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4684. }
  4685. /// <summary>
  4686. /// 仪表Light键按下
  4687. /// </summary>
  4688. /// <param name="sender"></param>
  4689. /// <param name="e"></param>
  4690. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4691. {
  4692. var Code = new byte[2];
  4693. Code[0] = 0;
  4694. Code[1] = 0b00000010;
  4695. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4696. }
  4697. /// <summary>
  4698. /// 仪表Set键按下
  4699. /// </summary>
  4700. /// <param name="sender"></param>
  4701. /// <param name="e"></param>
  4702. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4703. {
  4704. var Code = new byte[2];
  4705. Code[0] = 0;
  4706. Code[1] = 0b00000001;
  4707. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4708. }
  4709. /// <summary>
  4710. /// 导出电机故障日志
  4711. /// </summary>
  4712. /// <param name="sender"></param>
  4713. /// <param name="e"></param>
  4714. private void button_ExportLog_Click(object sender, EventArgs e)
  4715. {
  4716. var Address = new byte[4];
  4717. UInt32 Address_Begin;
  4718. UInt32 Addres_End;
  4719. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4720. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4721. richTextBox_Record.Clear();
  4722. textBox_LogAddrBegin.ReadOnly = true;
  4723. textBox_LogAddrEnd.ReadOnly = true;
  4724. if (!mySerialProcess.mySerial.IsOpen)
  4725. {
  4726. timer_1s.Enabled = false;
  4727. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4728. timer_1s.Enabled = true;
  4729. return;
  4730. }
  4731. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4732. {
  4733. timer_1s.Enabled = false;
  4734. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4735. timer_1s.Enabled = true;
  4736. return;
  4737. }
  4738. else
  4739. {
  4740. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4741. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4742. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4743. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4744. if (Addres_End <= Address_Begin)
  4745. {
  4746. timer_1s.Enabled = false;
  4747. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4748. timer_1s.Enabled = true;
  4749. return;
  4750. }
  4751. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4752. {
  4753. timer_1s.Enabled = false;
  4754. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4755. timer_1s.Enabled = true;
  4756. return;
  4757. }
  4758. else
  4759. {
  4760. UInt32 ReadCount = 0;
  4761. button_ExportLog.Text = "导出中...";
  4762. button_ExportLog.Enabled = false;
  4763. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4764. for (ushort i = 0; i < ReadCount; i++)
  4765. {
  4766. var SendByte = new byte[8];
  4767. UInt32 Address_Temp_Begin;
  4768. UInt32 Address_Temp_End;
  4769. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4770. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4771. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4772. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4773. SendByte[3] = (byte)(Address_Temp_Begin);
  4774. Address_Temp_End = Address_Temp_Begin + 127;
  4775. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4776. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4777. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4778. SendByte[7] = (byte)(Address_Temp_End);
  4779. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4780. Delay_ms(200);//Thread.Sleep(200);
  4781. }
  4782. button_ExportLog.Text = "导出日志";
  4783. button_ExportLog.Enabled = true;
  4784. }
  4785. }
  4786. }
  4787. /// <summary>
  4788. /// 保存日志信息
  4789. /// </summary>
  4790. /// <param name="sender"></param>
  4791. /// <param name="e"></param>
  4792. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4793. {
  4794. string SaveInfo = "";
  4795. if (richTextBox_Record.Text == string.Empty)
  4796. {
  4797. timer_1s.Enabled = false;
  4798. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4799. timer_1s.Enabled = true;
  4800. return;
  4801. }
  4802. //获取保存信息
  4803. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4804. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4805. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4806. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4807. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4808. SaveInfo += "\r\n";
  4809. SaveInfo += richTextBox_Record.Text;
  4810. //设置保存路径和文件名
  4811. SaveFileDialog sf = new SaveFileDialog();
  4812. sf.Title = "数据保存";
  4813. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4814. sf.FileName.Replace(" ", "");
  4815. sf.Filter = "日志|*.ttlog";
  4816. if (sf.ShowDialog() == DialogResult.OK)
  4817. {
  4818. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4819. }
  4820. }
  4821. /// <summary>
  4822. /// 双击修改日志起始地址
  4823. /// </summary>
  4824. /// <param name="sender"></param>
  4825. /// <param name="e"></param>
  4826. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4827. {
  4828. textBox_LogAddrBegin.ReadOnly = false;
  4829. }
  4830. /// <summary>
  4831. /// 双击修改日志结束地址
  4832. /// </summary>
  4833. /// <param name="sender"></param>
  4834. /// <param name="e"></param>
  4835. private void label88_DoubleClick(object sender, EventArgs e)
  4836. {
  4837. textBox_LogAddrEnd.ReadOnly = false;
  4838. }
  4839. /// <summary>
  4840. /// 存储器自动读取选择
  4841. /// </summary>
  4842. /// <param name="sender"></param>
  4843. /// <param name="e"></param>
  4844. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4845. {
  4846. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4847. {
  4848. //检查串口是否打开
  4849. if (!mySerialProcess.mySerial.IsOpen)
  4850. {
  4851. timer_1s.Enabled = false;
  4852. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4853. timer_1s.Enabled = true;
  4854. checkBox_ReadRanFlash_AutoSW.Checked = false;
  4855. return;
  4856. }
  4857. }
  4858. }
  4859. /// <summary>
  4860. /// 系统开机按钮
  4861. /// </summary>
  4862. /// <param name="sender"></param>
  4863. /// <param name="e"></param>
  4864. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4865. {
  4866. byte[] Data = new byte[1];
  4867. Data[0] = 0xF1;
  4868. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4869. }
  4870. /// <summary>
  4871. /// 系统关机按钮
  4872. /// </summary>
  4873. /// <param name="sender"></param>
  4874. /// <param name="e"></param>
  4875. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4876. {
  4877. byte[] Data = new byte[1];
  4878. Data[0] = 0xF0;
  4879. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4880. }
  4881. /// <summary>
  4882. /// 连接开机选择
  4883. /// </summary>
  4884. /// <param name="sender"></param>
  4885. /// <param name="e"></param>
  4886. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4887. {
  4888. //输入用户名
  4889. EnterForm1.ShowDialog();
  4890. try
  4891. {
  4892. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4893. {
  4894. if (EnterForm1.comboBox_User.Text == "管理员")
  4895. {
  4896. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  4897. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4898. }
  4899. else
  4900. {
  4901. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4902. }
  4903. }
  4904. else
  4905. {
  4906. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4907. }
  4908. }
  4909. catch (Exception)
  4910. {
  4911. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4912. }
  4913. }
  4914. /// <summary>
  4915. /// 断开关机选择
  4916. /// </summary>
  4917. /// <param name="sender"></param>
  4918. /// <param name="e"></param>
  4919. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4920. {
  4921. //输入用户名
  4922. EnterForm1.ShowDialog();
  4923. try
  4924. {
  4925. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4926. {
  4927. if (EnterForm1.comboBox_User.Text == "管理员")
  4928. {
  4929. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  4930. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4931. }
  4932. else
  4933. {
  4934. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4935. }
  4936. }
  4937. else
  4938. {
  4939. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4940. }
  4941. }
  4942. catch (Exception)
  4943. {
  4944. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4945. }
  4946. }
  4947. /// <summary>
  4948. /// 识别通讯盒选择
  4949. /// </summary>
  4950. /// <param name="sender"></param>
  4951. /// <param name="e"></param>
  4952. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  4953. {
  4954. //输入用户名
  4955. EnterForm1.ShowDialog();
  4956. try
  4957. {
  4958. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4959. {
  4960. if (EnterForm1.comboBox_User.Text == "管理员")
  4961. {
  4962. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  4963. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4964. }
  4965. else
  4966. {
  4967. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4968. }
  4969. }
  4970. else
  4971. {
  4972. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4973. }
  4974. }
  4975. catch (Exception)
  4976. {
  4977. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4978. }
  4979. }
  4980. /// <summary>
  4981. /// 将配置信息导出为cfg文件
  4982. /// </summary>
  4983. private void ConfigFileSave(bool DeleteFlag, string FileName)
  4984. {
  4985. if (DeleteFlag)
  4986. {
  4987. if (File.Exists(FileName))
  4988. File.Delete(FileName);
  4989. }
  4990. string CfgFileInfo = "";
  4991. CfgFileInfo += "[PortSet]" + "\r\n";
  4992. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  4993. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  4994. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4995. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4996. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  4997. CfgFileInfo += "\r\n";
  4998. CfgFileInfo += "[Option]" + "\r\n";
  4999. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5000. CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
  5001. CfgFileInfo += "\r\n";
  5002. CfgFileInfo += "[ServerSet]" + "\r\n";
  5003. CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
  5004. CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
  5005. CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
  5006. CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
  5007. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5008. CfgFileInfo += "\r\n";
  5009. CfgFileInfo += "[MacInfo]" + "\r\n";
  5010. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5011. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5012. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5013. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5014. CfgFileInfo += "\r\n";
  5015. CfgFileInfo += "[LogAddress]" + "\r\n";
  5016. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5017. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5018. CfgFileInfo += "\r\n";
  5019. CfgFileInfo += "[MotorType]" + "\r\n";
  5020. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5021. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5022. CfgFileInfo += "\r\n";
  5023. CfgFileInfo += "[CheckValue]" + "\r\n";
  5024. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5025. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5026. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5027. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5028. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5029. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5030. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5031. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5032. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5033. CfgFileInfo += "\r\n";
  5034. CfgFileInfo += "[MosCalK]" + "\r\n";
  5035. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5036. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5037. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5038. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5039. CfgFileInfo += "\r\n";
  5040. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5041. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5042. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5043. CfgFileInfo += "\r\n";
  5044. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5045. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5046. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5047. }
  5048. /// <summary>
  5049. /// 配置状态更新,点击时保存
  5050. /// </summary>
  5051. private void ConfigFileSave_Click(object sender, EventArgs e)
  5052. {
  5053. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5054. }
  5055. /// <summary>
  5056. /// 文本框修改结束,回车保存
  5057. /// </summary>
  5058. /// <param name="sender"></param>
  5059. /// <param name="e"></param>
  5060. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5061. {
  5062. if (e.KeyCode == Keys.Enter)
  5063. {
  5064. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5065. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5066. }
  5067. }
  5068. /// <summary>
  5069. /// 允许离线使用
  5070. /// </summary>
  5071. /// <param name="sender"></param>
  5072. /// <param name="e"></param>
  5073. private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
  5074. {
  5075. //输入用户名
  5076. EnterForm1.ShowDialog();
  5077. try
  5078. {
  5079. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5080. {
  5081. if (EnterForm1.comboBox_User.Text == "管理员")
  5082. {
  5083. 允许ToolStripMenuItem.Checked = true;
  5084. 不允许ToolStripMenuItem.Checked = false;
  5085. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5086. }
  5087. else
  5088. {
  5089. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5090. 允许ToolStripMenuItem.Checked = false;
  5091. 不允许ToolStripMenuItem.Checked = true;
  5092. }
  5093. }
  5094. else
  5095. {
  5096. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5097. 允许ToolStripMenuItem.Checked = false;
  5098. 不允许ToolStripMenuItem.Checked = true;
  5099. }
  5100. }
  5101. catch (Exception)
  5102. {
  5103. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5104. 允许ToolStripMenuItem.Checked = false;
  5105. 不允许ToolStripMenuItem.Checked = true;
  5106. }
  5107. }
  5108. /// <summary>
  5109. /// 不允许离线使用
  5110. /// </summary>
  5111. /// <param name="sender"></param>
  5112. /// <param name="e"></param>
  5113. private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
  5114. {
  5115. 允许ToolStripMenuItem.Checked = false;
  5116. 不允许ToolStripMenuItem.Checked = true;
  5117. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5118. }
  5119. /// <summary>
  5120. /// 弹出扫码按钮
  5121. /// </summary>
  5122. /// <param name="sender"></param>
  5123. /// <param name="e"></param>
  5124. private void button_ScanCode_Click(object sender, EventArgs e)
  5125. {
  5126. Scan scan_form = new Scan();
  5127. scan_form.ShowDialog();
  5128. do
  5129. {
  5130. if (scan_form.textBox_Scan.Text == string.Empty)
  5131. {
  5132. timer_1s.Enabled = false;
  5133. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5134. timer_1s.Enabled = true;
  5135. break;
  5136. }
  5137. string ScanInfo = scan_form.textBox_Scan.Text;
  5138. string regexInfo = "";
  5139. string[] InfoList = { "" };
  5140. try
  5141. {
  5142. if (中置电机ToolStripMenuItem.Checked == true)
  5143. {
  5144. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5145. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5146. }
  5147. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5148. {
  5149. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5150. string Model = InfoList[0];
  5151. string Spec = InfoList[1];
  5152. string Sn = InfoList[2];
  5153. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5154. InfoList[1] = Sn;
  5155. }
  5156. }
  5157. catch (Exception)
  5158. {
  5159. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5160. return;
  5161. }
  5162. if (InfoList.Length >= 2)
  5163. {
  5164. //写入型号
  5165. textBox_FacModeName.Text = InfoList[0];
  5166. string Mode = textBox_FacModeName.Text;
  5167. var ModeArray = new byte[16];
  5168. for (ushort i = 0; i < Mode.Length; i++)
  5169. {
  5170. ModeArray[i] = (byte)Mode[i];
  5171. }
  5172. if (Mode.Length < 16)
  5173. {
  5174. ModeArray[Mode.Length] = (byte)'.';
  5175. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5176. {
  5177. ModeArray[Mode.Length + 1 + i] = 0x20;
  5178. }
  5179. }
  5180. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5181. //写入SN
  5182. textBox_FacModeNum.Text = InfoList[1];
  5183. string SN = textBox_FacModeNum.Text;
  5184. var SNArray = new byte[16];
  5185. for (ushort i = 0; i < SN.Length; i++)
  5186. {
  5187. SNArray[i] = (byte)SN[i];
  5188. }
  5189. if (SN.Length < 16)
  5190. {
  5191. SNArray[SN.Length] = (byte)'.';
  5192. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5193. {
  5194. SNArray[SN.Length + 1 + i] = 0x20;
  5195. }
  5196. }
  5197. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5198. }
  5199. else
  5200. {
  5201. timer_1s.Enabled = false;
  5202. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5203. timer_1s.Enabled = true;
  5204. break;
  5205. }
  5206. } while (false);
  5207. scan_form.Dispose();
  5208. }
  5209. private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
  5210. {
  5211. //输入用户名
  5212. EnterForm1.ShowDialog();
  5213. try
  5214. {
  5215. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5216. {
  5217. if (EnterForm1.comboBox_User.Text == "管理员")
  5218. {
  5219. IP地址ToolStripMenuItem.Visible = true;
  5220. 端口ToolStripMenuItem.Visible = true;
  5221. 用户名ToolStripMenuItem.Visible = true;
  5222. 密码ToolStripMenuItem.Visible = true;
  5223. 存储路径ToolStripMenuItem.Visible = true;
  5224. }
  5225. else
  5226. {
  5227. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5228. IP地址ToolStripMenuItem.Visible = false;
  5229. 端口ToolStripMenuItem.Visible = false;
  5230. 用户名ToolStripMenuItem.Visible = false;
  5231. 密码ToolStripMenuItem.Visible = false;
  5232. 存储路径ToolStripMenuItem.Visible = false;
  5233. }
  5234. }
  5235. else
  5236. {
  5237. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5238. IP地址ToolStripMenuItem.Visible = false;
  5239. 端口ToolStripMenuItem.Visible = false;
  5240. 用户名ToolStripMenuItem.Visible = false;
  5241. 密码ToolStripMenuItem.Visible = false;
  5242. 存储路径ToolStripMenuItem.Visible = false;
  5243. }
  5244. }
  5245. catch (Exception)
  5246. {
  5247. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5248. IP地址ToolStripMenuItem.Visible = false;
  5249. 端口ToolStripMenuItem.Visible = false;
  5250. 用户名ToolStripMenuItem.Visible = false;
  5251. 密码ToolStripMenuItem.Visible = false;
  5252. 存储路径ToolStripMenuItem.Visible = false;
  5253. }
  5254. }
  5255. private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
  5256. {
  5257. //输入用户名
  5258. EnterForm1.ShowDialog();
  5259. try
  5260. {
  5261. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5262. {
  5263. if (EnterForm1.comboBox_User.Text == "管理员")
  5264. {
  5265. 生产商ToolStripMenuItem.Visible = true;
  5266. 生产地ToolStripMenuItem.Visible = true;
  5267. 生产日期ToolStripMenuItem.Visible = true;
  5268. 产品标识ToolStripMenuItem.Visible = true;
  5269. }
  5270. else
  5271. {
  5272. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5273. 生产商ToolStripMenuItem.Visible = false;
  5274. 生产地ToolStripMenuItem.Visible = false;
  5275. 生产日期ToolStripMenuItem.Visible = false;
  5276. 产品标识ToolStripMenuItem.Visible = false;
  5277. }
  5278. }
  5279. else
  5280. {
  5281. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5282. 生产商ToolStripMenuItem.Visible = false;
  5283. 生产地ToolStripMenuItem.Visible = false;
  5284. 生产日期ToolStripMenuItem.Visible = false;
  5285. 产品标识ToolStripMenuItem.Visible = false;
  5286. }
  5287. }
  5288. catch (Exception)
  5289. {
  5290. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5291. 生产商ToolStripMenuItem.Visible = false;
  5292. 生产地ToolStripMenuItem.Visible = false;
  5293. 生产日期ToolStripMenuItem.Visible = false;
  5294. 产品标识ToolStripMenuItem.Visible = false;
  5295. }
  5296. }
  5297. /// <summary>
  5298. /// 切换电机类型
  5299. /// </summary>
  5300. /// <param name="sender"></param>
  5301. /// <param name="e"></param>
  5302. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5303. {
  5304. 中置电机ToolStripMenuItem.Checked = true;
  5305. 轮毂电机ToolStripMenuItem.Checked = false;
  5306. toolStripTextBox_MACPD.Text = "MM_MC1";
  5307. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5308. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5309. }
  5310. /// <summary>
  5311. /// 切换电机类型
  5312. /// </summary>
  5313. /// <param name="sender"></param>
  5314. /// <param name="e"></param>
  5315. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5316. {
  5317. 中置电机ToolStripMenuItem.Checked = false;
  5318. 轮毂电机ToolStripMenuItem.Checked = true;
  5319. toolStripTextBox_MACPD.Text = "GF_250_1";
  5320. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5321. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5322. }
  5323. /// <summary>
  5324. /// 获取配置文件日期
  5325. /// </summary>
  5326. /// <param name="DisAll"></param>
  5327. private void GetDateList(bool DisAll)
  5328. {
  5329. string[] DateList = { "" };
  5330. //从服务器更新日期列表
  5331. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5332. {
  5333. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5334. }
  5335. //从本地更新日期列表
  5336. else
  5337. {
  5338. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5339. }
  5340. comboBox_FacModeCfgDate.Items.Clear();
  5341. comboBox_CheckModeCfgDate.Items.Clear();
  5342. //日期列表加载
  5343. if (DisAll == true)
  5344. {
  5345. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5346. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5347. comboBox_FacModeCfgDate.Items.Add("---");
  5348. comboBox_CheckModeCfgDate.Items.Add("---");
  5349. foreach (var file in DateList)
  5350. {
  5351. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5352. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5353. }
  5354. }
  5355. else
  5356. {
  5357. if (DateList.Length > 10)
  5358. {
  5359. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5360. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5361. comboBox_FacModeCfgDate.Items.Add("---");
  5362. comboBox_CheckModeCfgDate.Items.Add("---");
  5363. }
  5364. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5365. {
  5366. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5367. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5368. }
  5369. }
  5370. }
  5371. /// <summary>
  5372. /// 获取配置文件列表
  5373. /// </summary>
  5374. /// <param name="date"></param>
  5375. private void GetFileListFrom(string date)
  5376. {
  5377. string[] FileList = { "" };
  5378. //从服务器更新文件列表
  5379. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5380. {
  5381. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5382. }
  5383. else
  5384. {
  5385. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5386. }
  5387. comboBox_CheckModeCfgFile.Items.Clear();
  5388. comboBox_FacModeCfgFile.Items.Clear();
  5389. foreach (var file in FileList)
  5390. {
  5391. if (file.Contains(".ttcfg"))
  5392. {
  5393. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5394. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5395. }
  5396. }
  5397. }
  5398. /// <summary>
  5399. /// 检验模式选择文件日期
  5400. /// </summary>
  5401. /// <param name="sender"></param>
  5402. /// <param name="e"></param>
  5403. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5404. {
  5405. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5406. {
  5407. GetDateList(true);
  5408. }
  5409. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5410. {
  5411. GetDateList(false);
  5412. }
  5413. else
  5414. {
  5415. comboBox_CheckModeCfgFile.Text = "";
  5416. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5417. }
  5418. }
  5419. /// <summary>
  5420. /// 配置模式选择文件日期
  5421. /// </summary>
  5422. /// <param name="sender"></param>
  5423. /// <param name="e"></param>
  5424. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5425. {
  5426. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5427. {
  5428. GetDateList(true);
  5429. }
  5430. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5431. {
  5432. GetDateList(false);
  5433. }
  5434. else
  5435. {
  5436. comboBox_FacModeCfgFile.Text = "";
  5437. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5438. }
  5439. }
  5440. /// <summary>
  5441. /// 选中量产模式
  5442. /// </summary>
  5443. /// <param name="sender"></param>
  5444. /// <param name="e"></param>
  5445. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5446. {
  5447. //更新生产配置文件目录
  5448. GetDateList(false);
  5449. }
  5450. /// <summary>
  5451. /// 量产测试结束
  5452. /// </summary>
  5453. /// <param name=""></param>
  5454. private void FacMode_Stop(bool OK_Flag)
  5455. {
  5456. //打开开始按钮
  5457. button__FacMode_Start.Enabled = true;
  5458. //系统关机
  5459. var Code = new byte[32];//发送的指令数据
  5460. Code[0] = 0xF0;
  5461. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5462. //关闭串口
  5463. //mySerialProcess.SerialClose(false);
  5464. //路径设置
  5465. string LocalSavePath = "";
  5466. string ServerSavePath = "";
  5467. if (OK_Flag)
  5468. {
  5469. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5470. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5471. }
  5472. else
  5473. {
  5474. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5475. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5476. }
  5477. if (Directory.Exists(LocalSavePath) == false)
  5478. {
  5479. Directory.CreateDirectory(LocalSavePath);
  5480. }
  5481. //保存和上传
  5482. string LogSavePath = "";
  5483. string LogSaveFileName = "";
  5484. string ProductInfo = textBox_FacModeScan.Text;
  5485. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5486. if (Directory.Exists(LogSavePath) == false)
  5487. {
  5488. Directory.CreateDirectory(LogSavePath);
  5489. }
  5490. //测试页面
  5491. Double scaleX = PrimaryScreen.ScaleX;
  5492. Double scaleY = PrimaryScreen.ScaleY;
  5493. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5494. Graphics g = Graphics.FromImage(bit);
  5495. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5496. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5497. bit.Save(LogSaveFileName);
  5498. //上传测试页面到服务器
  5499. if (myFtp.IsNetConnected == true)
  5500. {
  5501. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5502. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5503. {
  5504. myFtp.MakeDir(ServerSavePath + DateNow);
  5505. }
  5506. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5507. {
  5508. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5509. }
  5510. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5511. if (result == true)
  5512. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5513. }
  5514. else
  5515. {
  5516. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5517. }
  5518. //测试记录
  5519. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5520. string file_str = "";
  5521. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5522. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5523. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5524. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5525. file_str += Local_HdInformation;
  5526. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5527. //上传测试记录到服务器
  5528. if (myFtp.IsNetConnected == true)
  5529. {
  5530. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5531. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5532. {
  5533. myFtp.MakeDir(ServerSavePath + DateNow);
  5534. }
  5535. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5536. {
  5537. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5538. }
  5539. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5540. if (result == true)
  5541. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5542. }
  5543. else
  5544. {
  5545. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5546. }
  5547. //扫码框清空
  5548. textBox_FacModeScan.Text = "";
  5549. }
  5550. /// <summary>
  5551. /// 量产测试开始
  5552. /// </summary>
  5553. /// <param name="sender"></param>
  5554. /// <param name="e"></param>
  5555. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5556. {
  5557. //关闭测试项目编辑
  5558. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5559. foreach (Control c in groupBox2.Controls)
  5560. {
  5561. if (c is CheckBox)
  5562. c.Enabled = false;
  5563. }
  5564. WriteLockStatus = true;
  5565. //检查配置文件
  5566. if (comboBox_FacModeCfgFile.Text == "")
  5567. {
  5568. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5569. return;
  5570. }
  5571. //开始测试
  5572. TestStart();
  5573. }
  5574. /// <summary>
  5575. /// 测试子函数
  5576. /// </summary>
  5577. private void TestStart()
  5578. {
  5579. //初始化标签
  5580. FacModelLabelInit();
  5581. richTextBox_FacModeLog.Clear();
  5582. //按钮禁止操作
  5583. button__FacMode_Start.Enabled = false;
  5584. //记录配置文件
  5585. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5586. //检查打标信息格式
  5587. label_FacModeStatus.Text = "检查扫码信息";
  5588. Delay_ms(500);
  5589. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5590. if (textBox_FacModeScan.Text == string.Empty)
  5591. {
  5592. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5593. button__FacMode_Start.Enabled = true;
  5594. return;
  5595. }
  5596. try
  5597. {
  5598. if (中置电机ToolStripMenuItem.Checked == true)
  5599. {
  5600. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5601. {
  5602. label_FacModeStatus.Text = "存在故障!";
  5603. label_FacModeResult.BackColor = Color.Red;
  5604. label_FacModeResult.Text = "标签格式错误";
  5605. button__FacMode_Start.Enabled = true;
  5606. return;
  5607. }
  5608. }
  5609. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5610. {
  5611. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5612. {
  5613. label_FacModeStatus.Text = "存在故障!";
  5614. label_FacModeResult.BackColor = Color.Red;
  5615. label_FacModeResult.Text = "标签格式错误";
  5616. button__FacMode_Start.Enabled = true;
  5617. return;
  5618. }
  5619. }
  5620. }
  5621. catch (System.Exception)
  5622. {
  5623. label_FacModeStatus.Text = "存在故障!";
  5624. label_FacModeResult.BackColor = Color.Red;
  5625. label_FacModeResult.Text = "标签格式错误";
  5626. button__FacMode_Start.Enabled = true;
  5627. return;
  5628. }
  5629. //打开串口
  5630. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5631. if (!mySerialProcess.mySerial.IsOpen)
  5632. {
  5633. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5634. //按钮禁止操作
  5635. button__FacMode_Start.Enabled = true;
  5636. return;
  5637. }
  5638. //流水号计数
  5639. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5640. serial += 1;
  5641. label_FacModeSerial.Text = serial.ToString();
  5642. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5643. //创建线程,执行测试任务
  5644. Thread th = new Thread(FacModeTest_Task);
  5645. th.Start();
  5646. }
  5647. /// <summary>
  5648. /// 执行一次测试任务
  5649. /// </summary>
  5650. private void FacModeTest_Task()
  5651. {
  5652. //开始测试
  5653. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5654. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5655. //变量定义
  5656. var Code = new byte[255];//发送的指令数据
  5657. label_FacModeStatus.Text = "开始测试";
  5658. BootInfo = "";
  5659. Delay_ms(500);
  5660. label_FacModeStatus.Text = "系统开机";
  5661. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5662. if (uARTToolStripMenuItem.Checked)
  5663. {
  5664. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5665. Code[0] = (byte)'R';
  5666. Code[1] = (byte)'E';
  5667. Code[2] = (byte)'S';
  5668. Code[3] = (byte)'E';
  5669. Code[4] = (byte)'T';
  5670. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5671. Delay_ms(500);
  5672. }
  5673. //发送开机指令
  5674. //确保测试前先关机,发送关机指令再发送开机指令
  5675. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5676. Code[0] = 0xF0;
  5677. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5678. Delay_ms(1500);
  5679. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5680. Code[0] = 0xF1;
  5681. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5682. ACK_WaitCnt = 0;
  5683. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5684. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5685. //检查BOOT版本
  5686. if (BootInfo != string.Empty)
  5687. {
  5688. label_FacModeBootVer.BackColor = Color.Green;
  5689. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5690. Delay_ms(500);
  5691. }
  5692. else
  5693. {
  5694. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5695. label_FacModeStatus.Text = "存在故障!";
  5696. label_FacModeResult.BackColor = Color.Red;
  5697. label_FacModeResult.Text = "测试异常";
  5698. Delay_ms(500);
  5699. //存储异常并上传
  5700. FacMode_Stop(false);
  5701. return;
  5702. }
  5703. //系统清除
  5704. if (checkBox_FacModeSysClear.Checked)
  5705. {
  5706. do
  5707. {
  5708. #if false
  5709. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5710. {
  5711. Code[0] = 0x00;//5S协议
  5712. Code[1] = 0x00;
  5713. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5714. Delay_ms(500);
  5715. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5716. Delay_ms(500);
  5717. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5718. }
  5719. #endif
  5720. //发送系统清除指令
  5721. label_FacModeStatus.Text = "系统清除";
  5722. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5723. Code[0] = (byte)'C';
  5724. Code[1] = (byte)'L';
  5725. Code[2] = (byte)'E';
  5726. Code[3] = (byte)'A';
  5727. Code[4] = (byte)'R';
  5728. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5729. WriteACK = false;
  5730. WriteCnt = 0;
  5731. ACK_WaitCnt = 0;
  5732. while (ACK_WaitCnt <= 6); //3s
  5733. //等待系统清除完成指令
  5734. if (WriteACK == true)
  5735. {
  5736. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5737. label_FacModeSysClear.BackColor = Color.Green;
  5738. }
  5739. else
  5740. {
  5741. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5742. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5743. ACK_WaitCnt = 0;
  5744. while (ACK_WaitCnt <= 6) ; //3s
  5745. //等待系统清除完成指令
  5746. if (WriteACK == true)
  5747. {
  5748. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5749. label_FacModeSysClear.BackColor = Color.Green;
  5750. }
  5751. else
  5752. {
  5753. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5754. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5755. ACK_WaitCnt = 0;
  5756. while (ACK_WaitCnt <= 6) ; //3s
  5757. //等待系统清除完成指令
  5758. if (WriteACK == true)
  5759. {
  5760. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5761. label_FacModeSysClear.BackColor = Color.Green;
  5762. }
  5763. else
  5764. {
  5765. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5766. label_FacModeStatus.Text = "存在故障!";
  5767. label_FacModeResult.BackColor = Color.Red;
  5768. label_FacModeResult.Text = "测试异常";
  5769. Delay_ms(500);
  5770. //存储异常并上传
  5771. FacMode_Stop(false);
  5772. return;
  5773. }
  5774. }
  5775. }
  5776. BootInfo = "";
  5777. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5778. if (uARTToolStripMenuItem.Checked)
  5779. {
  5780. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5781. Code[0] = (byte)'R';
  5782. Code[1] = (byte)'E';
  5783. Code[2] = (byte)'S';
  5784. Code[3] = (byte)'E';
  5785. Code[4] = (byte)'T';
  5786. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5787. Delay_ms(500);
  5788. }
  5789. //系统重新开机
  5790. label_FacModeStatus.Text = "重新开机";
  5791. //确保测试前先关机,发送关机指令再发送开机指令
  5792. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  5793. Code[0] = 0xF0;
  5794. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5795. Delay_ms(1500);
  5796. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  5797. Code[0] = 0xF1;
  5798. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5799. ACK_WaitCnt = 0;
  5800. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5801. while (ACK_WaitCnt <= 20); //10s
  5802. //获取Boot版本信息
  5803. if (BootInfo != string.Empty)
  5804. {
  5805. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5806. Delay_ms(500);
  5807. }
  5808. else
  5809. {
  5810. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5811. label_FacModeStatus.Text = "存在故障!";
  5812. label_FacModeResult.BackColor = Color.Red;
  5813. label_FacModeResult.Text = "测试异常";
  5814. Delay_ms(500);
  5815. //存储异常并上传
  5816. FacMode_Stop(false);
  5817. return;
  5818. }
  5819. } while (false);
  5820. }
  5821. else
  5822. {
  5823. label_FacModeSysClear.BackColor = Color.Yellow;
  5824. label_FacModeStatus.Text = "跳过系统清除!";
  5825. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5826. Delay_ms(500);
  5827. }
  5828. #if false
  5829. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5830. {
  5831. Code[0] = 0x00;//5S协议
  5832. Code[1] = 0x00;
  5833. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5834. Delay_ms(500);
  5835. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5836. Delay_ms(500);
  5837. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5838. }
  5839. #endif
  5840. //检查是否有故障
  5841. if (textBox_ErrorCode.Text.Contains("H"))
  5842. {
  5843. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5844. label_FacModeStatus.Text = "电机存在故障!";
  5845. label_FacModeResult.BackColor = Color.Red;
  5846. label_FacModeResult.Text = "测试异常";
  5847. Delay_ms(500);
  5848. //存储异常并上传
  5849. FacMode_Stop(false);
  5850. return;
  5851. }
  5852. //MOS内阻校准
  5853. if (checkBox_FacMode_MosCal.Checked)
  5854. {
  5855. label_FacModeStatus.Text = "MOS内阻校准";
  5856. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  5857. Delay_ms(500);
  5858. //提示进行负载切换
  5859. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  5860. {
  5861. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  5862. label_FacModeStatus.Text = "存在故障!";
  5863. label_FacModeResult.BackColor = Color.Red;
  5864. label_FacModeResult.Text = "测试异常";
  5865. Delay_ms(500);
  5866. //存储异常并上传
  5867. FacMode_Stop(false);
  5868. return;
  5869. }
  5870. //确认后发送校准指令
  5871. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  5872. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  5873. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  5874. ushort uwDataTemp = 0;
  5875. uwDataTemp = Convert.ToUInt16(K[0]);
  5876. Code[2] = (byte)(uwDataTemp & 0xFF);
  5877. Code[3] = (byte)(uwDataTemp >> 8);
  5878. uwDataTemp = Convert.ToUInt16(K[1]);
  5879. Code[4] = (byte)(uwDataTemp & 0xFF);
  5880. Code[5] = (byte)(uwDataTemp >> 8);
  5881. uwDataTemp = Convert.ToUInt16(K[2]);
  5882. Code[6] = (byte)(uwDataTemp & 0xFF);
  5883. Code[7] = (byte)(uwDataTemp >> 8);
  5884. uwDataTemp = Convert.ToUInt16(K[3]);
  5885. Code[8] = (byte)(uwDataTemp & 0xFF);
  5886. Code[9] = (byte)(uwDataTemp >> 8);
  5887. uwDataTemp = Convert.ToUInt16(K[4]);
  5888. Code[10] = (byte)(uwDataTemp & 0xFF);
  5889. Code[11] = (byte)(uwDataTemp >> 8);
  5890. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5891. WriteACK = false;
  5892. WriteCnt = 0;
  5893. ACK_WaitCnt = 0;
  5894. while (ACK_WaitCnt <= 6) ; //3s
  5895. if (WriteACK == true)
  5896. {
  5897. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5898. }
  5899. else
  5900. {
  5901. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  5902. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5903. ACK_WaitCnt = 0;
  5904. while (ACK_WaitCnt <= 6) ; //3s
  5905. if (WriteACK == true)
  5906. {
  5907. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5908. }
  5909. else
  5910. {
  5911. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  5912. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5913. ACK_WaitCnt = 0;
  5914. while (ACK_WaitCnt <= 6) ; //3s
  5915. if (WriteACK == true)
  5916. {
  5917. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5918. }
  5919. else
  5920. {
  5921. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  5922. label_FacModeStatus.Text = "存在故障!";
  5923. label_FacModeResult.BackColor = Color.Red;
  5924. label_FacModeResult.Text = "测试异常";
  5925. Delay_ms(500);
  5926. //存储异常并上传
  5927. FacMode_Stop(false);
  5928. return;
  5929. }
  5930. }
  5931. }
  5932. #if false
  5933. //因控制器复位需发送指令重新进入5S协议
  5934. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5935. {
  5936. Code[0] = 0x00;//5S协议
  5937. Code[1] = 0x00;
  5938. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5939. Delay_ms(500);
  5940. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5941. Delay_ms(500);
  5942. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5943. }
  5944. #endif
  5945. //读取显示校准返回数据
  5946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  5947. foreach (Control c in groupBox21.Controls)
  5948. {
  5949. if (c is TextBox)
  5950. c.Text = "";
  5951. }
  5952. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5953. ACK_WaitCnt = 0;
  5954. while (ACK_WaitCnt <= 2) ; //1s
  5955. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5956. {
  5957. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  5958. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5959. ACK_WaitCnt = 0;
  5960. while (ACK_WaitCnt <= 2) ; //1s
  5961. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5962. {
  5963. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  5964. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5965. ACK_WaitCnt = 0;
  5966. while (ACK_WaitCnt <= 2) ; //1s
  5967. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5968. {
  5969. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  5970. label_FacModeStatus.Text = "存在故障!";
  5971. label_FacModeResult.BackColor = Color.Red;
  5972. label_FacModeResult.Text = "测试异常";
  5973. Delay_ms(500);
  5974. //存储异常并上传
  5975. FacMode_Stop(false);
  5976. return;
  5977. }
  5978. }
  5979. }
  5980. else
  5981. {
  5982. 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");
  5983. }
  5984. //与校准返回数据对比
  5985. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  5986. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  5987. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  5988. 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])) &&
  5989. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  5990. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  5991. )
  5992. {
  5993. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  5994. label_FacModeMosCal.BackColor = Color.Green;
  5995. //提示切换负载
  5996. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5997. }
  5998. else
  5999. {
  6000. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6001. label_FacModeStatus.Text = "存在故障!";
  6002. label_FacModeResult.BackColor = Color.Red;
  6003. label_FacModeResult.Text = "测试异常";
  6004. Delay_ms(500);
  6005. //存储异常并上传
  6006. FacMode_Stop(false);
  6007. //提示切换负载
  6008. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6009. return;
  6010. }
  6011. }
  6012. else
  6013. {
  6014. label_FacModeMosCal.BackColor = Color.Yellow;
  6015. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6016. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6017. Delay_ms(500);
  6018. }
  6019. //参数写入
  6020. if (checkBox_FacModeCfgWrite.Checked)
  6021. {
  6022. label_FacModeStatus.Text = "参数写入";
  6023. //写入产品型号和SN
  6024. do
  6025. {
  6026. //根据扫码信息获取型号和SN
  6027. string ScanInfo = textBox_FacModeScan.Text;
  6028. string regexInfo = "";
  6029. string[] InfoList = { "" };
  6030. try
  6031. {
  6032. if (中置电机ToolStripMenuItem.Checked == true)
  6033. {
  6034. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6035. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6036. }
  6037. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6038. {
  6039. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6040. string Model = InfoList[0];
  6041. string Spec = InfoList[1];
  6042. string Sn = InfoList[2];
  6043. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6044. InfoList[1] = Sn;
  6045. }
  6046. }
  6047. catch
  6048. {
  6049. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6050. label_FacModeStatus.Text = "存在故障!";
  6051. label_FacModeResult.BackColor = Color.Red;
  6052. label_FacModeResult.Text = "标签格式错误";
  6053. Delay_ms(500);
  6054. //存储异常并上传
  6055. FacMode_Stop(false);
  6056. return;
  6057. }
  6058. if (InfoList.Length >= 2)
  6059. {
  6060. //检查配置文件是否与打标信息一致
  6061. //...
  6062. //写入型号
  6063. label_FacModeStatus.Text = "写入型号";
  6064. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6065. textBox_FacModeName.Text = InfoList[0];
  6066. string Mode = textBox_FacModeName.Text;
  6067. var ModeArray = new byte[16];
  6068. for (ushort i = 0; i < Mode.Length; i++)
  6069. {
  6070. ModeArray[i] = (byte)Mode[i];
  6071. }
  6072. if (Mode.Length < 16)
  6073. {
  6074. ModeArray[Mode.Length] = (byte)'.';
  6075. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6076. {
  6077. ModeArray[Mode.Length + 1 + i] = 0x20;
  6078. }
  6079. }
  6080. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6081. WriteACK = false;
  6082. WriteCnt = 0;
  6083. ACK_WaitCnt = 0;
  6084. while (ACK_WaitCnt <= 2); //1s
  6085. if (WriteACK == true)
  6086. {
  6087. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6088. }
  6089. else
  6090. {
  6091. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6092. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6093. ACK_WaitCnt = 0;
  6094. while (ACK_WaitCnt <= 2) ; //1s
  6095. if (WriteACK == true)
  6096. {
  6097. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6098. }
  6099. else
  6100. {
  6101. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6102. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6103. ACK_WaitCnt = 0;
  6104. while (ACK_WaitCnt <= 2) ; //1s
  6105. if (WriteACK == true)
  6106. {
  6107. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6108. }
  6109. else
  6110. {
  6111. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6112. label_FacModeStatus.Text = "存在故障!";
  6113. label_FacModeResult.BackColor = Color.Red;
  6114. label_FacModeResult.Text = "测试异常";
  6115. Delay_ms(500);
  6116. //存储异常并上传
  6117. FacMode_Stop(false);
  6118. return;
  6119. }
  6120. }
  6121. }
  6122. //写入SN
  6123. label_FacModeStatus.Text = "写入SN";
  6124. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6125. textBox_FacModeNum.Text = InfoList[1];
  6126. string SN = textBox_FacModeNum.Text;
  6127. var SNArray = new byte[16];
  6128. for (ushort i = 0; i < SN.Length; i++)
  6129. {
  6130. SNArray[i] = (byte)SN[i];
  6131. }
  6132. if (SN.Length < 16)
  6133. {
  6134. SNArray[SN.Length] = (byte)'.';
  6135. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6136. {
  6137. SNArray[SN.Length + 1 + i] = 0x20;
  6138. }
  6139. }
  6140. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6141. WriteACK = false;
  6142. WriteCnt = 0;
  6143. ACK_WaitCnt = 0;
  6144. while (ACK_WaitCnt <= 2); //1s
  6145. if (WriteACK == true)
  6146. {
  6147. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6148. }
  6149. else
  6150. {
  6151. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6152. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6153. ACK_WaitCnt = 0;
  6154. while (ACK_WaitCnt <= 2) ; //1s
  6155. if (WriteACK == true)
  6156. {
  6157. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6158. }
  6159. else
  6160. {
  6161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6162. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6163. ACK_WaitCnt = 0;
  6164. while (ACK_WaitCnt <= 2) ; //1s
  6165. if (WriteACK == true)
  6166. {
  6167. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6168. }
  6169. else
  6170. {
  6171. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6172. label_FacModeStatus.Text = "存在故障!";
  6173. label_FacModeResult.BackColor = Color.Red;
  6174. label_FacModeResult.Text = "测试异常";
  6175. Delay_ms(500);
  6176. //存储异常并上传
  6177. FacMode_Stop(false);
  6178. return;
  6179. }
  6180. }
  6181. }
  6182. }
  6183. else
  6184. {
  6185. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6186. return;
  6187. }
  6188. } while (false);
  6189. //写入配置文件
  6190. do
  6191. {
  6192. label_FacModeStatus.Text = "写入配置文件";
  6193. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6194. //配置文件
  6195. List<byte[]> CmdList = new List<byte[]>();
  6196. //从服务器下载文件
  6197. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6198. {
  6199. string SelectFile = "";
  6200. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6201. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6202. {
  6203. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6204. }
  6205. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6206. //打开文件
  6207. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6208. CmdList.Clear();
  6209. while (streamReader.Peek() != -1)
  6210. {
  6211. string fileLineInfo = streamReader.ReadLine();
  6212. if (fileLineInfo.IndexOf("[") != -1)
  6213. {
  6214. continue;
  6215. }
  6216. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6217. }
  6218. streamReader.Close();
  6219. }
  6220. //加载本地文件
  6221. else
  6222. {
  6223. string SelectFile = "";
  6224. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6225. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6226. CmdList.Clear();
  6227. while (streamReader.Peek() != -1)
  6228. {
  6229. string fileLineInfo = streamReader.ReadLine();
  6230. if (fileLineInfo.IndexOf("[") != -1)
  6231. {
  6232. continue;
  6233. }
  6234. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6235. }
  6236. streamReader.Close();
  6237. }
  6238. int CmdNum = CmdList.Count(); //指令个数
  6239. Delay_ms(500);
  6240. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6241. Delay_ms(500);
  6242. //开始写入
  6243. WriteCnt = 0;
  6244. for (int i = 0; i < CmdList.Count; i++)
  6245. {
  6246. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6247. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6248. WriteACK = false;
  6249. ACK_WaitCnt = 0;
  6250. while (ACK_WaitCnt <= 2) ; //1s
  6251. if (WriteACK == true)
  6252. {
  6253. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6254. }
  6255. else
  6256. {
  6257. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6258. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6259. WriteACK = false;
  6260. ACK_WaitCnt = 0;
  6261. while (ACK_WaitCnt <= 2) ; //1s
  6262. if (WriteACK == true)
  6263. {
  6264. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6265. }
  6266. else
  6267. {
  6268. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6269. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6270. WriteACK = false;
  6271. ACK_WaitCnt = 0;
  6272. while (ACK_WaitCnt <= 2) ; //1s
  6273. if (WriteACK == true)
  6274. {
  6275. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6276. }
  6277. else
  6278. {
  6279. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6280. label_FacModeStatus.Text = "存在故障!";
  6281. label_FacModeResult.BackColor = Color.Red;
  6282. label_FacModeResult.Text = "测试异常";
  6283. Delay_ms(500);
  6284. //存储异常并上传
  6285. FacMode_Stop(false);
  6286. return;
  6287. }
  6288. }
  6289. }
  6290. }
  6291. //写入完成
  6292. label_FacMode_CfgWrite.BackColor = Color.Green;
  6293. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6294. Delay_ms(500);
  6295. } while (false);
  6296. }
  6297. else
  6298. {
  6299. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6300. label_FacModeStatus.Text = "跳过参数写入!";
  6301. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6302. Delay_ms(500);
  6303. }
  6304. //BMS通讯
  6305. if (checkBox_FacModeBMS.Checked)
  6306. {
  6307. if (label_FacModeBMS.BackColor == Color.Red)
  6308. {
  6309. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6310. label_FacModeStatus.Text = "存在故障!";
  6311. label_FacModeResult.BackColor = Color.Red;
  6312. label_FacModeResult.Text = "测试异常";
  6313. Delay_ms(500);
  6314. //存储异常并上传
  6315. FacMode_Stop(false);
  6316. return;
  6317. }
  6318. }
  6319. else
  6320. {
  6321. label_FacModeBMS.BackColor = Color.Yellow;
  6322. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6323. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6324. Delay_ms(500);
  6325. }
  6326. //基础功能检测
  6327. if (checkBox_FacBaseFucTest.Checked)
  6328. {
  6329. label_FacModeStatus.Text = "基础功能检测";
  6330. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6331. //确认负载位置
  6332. if (checkBox_FacMode_MosCal.Checked)
  6333. {
  6334. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6335. {
  6336. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6337. }
  6338. else
  6339. {
  6340. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6341. label_FacModeStatus.Text = "存在故障!";
  6342. label_FacModeResult.BackColor = Color.Red;
  6343. label_FacModeResult.Text = "测试异常";
  6344. Delay_ms(500);
  6345. //存储异常并上传
  6346. FacMode_Stop(false);
  6347. return;
  6348. }
  6349. }
  6350. //发送指令进入配置模式
  6351. do
  6352. {
  6353. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6354. Code[0] = 0x01;
  6355. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6356. WriteACK = false;
  6357. WriteCnt = 0;
  6358. ACK_WaitCnt = 0;
  6359. while (ACK_WaitCnt <= 2); //1s
  6360. if (textBox_RunInfo_Vol.Text != "---")
  6361. {
  6362. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6363. }
  6364. else
  6365. {
  6366. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6367. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6368. ACK_WaitCnt = 0;
  6369. while (ACK_WaitCnt <= 2) ; //1s
  6370. if (textBox_RunInfo_Vol.Text != "---")
  6371. {
  6372. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6373. }
  6374. else
  6375. {
  6376. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6377. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6378. ACK_WaitCnt = 0;
  6379. while (ACK_WaitCnt <= 2) ; //1s
  6380. if (textBox_RunInfo_Vol.Text != "---")
  6381. {
  6382. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6383. }
  6384. else
  6385. {
  6386. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6387. label_FacModeStatus.Text = "存在故障!";
  6388. label_FacModeResult.BackColor = Color.Red;
  6389. label_FacModeResult.Text = "测试异常";
  6390. Delay_ms(500);
  6391. //存储异常并上传
  6392. FacMode_Stop(false);
  6393. return;
  6394. }
  6395. }
  6396. }
  6397. } while (false);
  6398. //发送指令启动电机
  6399. do
  6400. {
  6401. #if false //通过运行模式3启动电机
  6402. //发送指令读取调试信息
  6403. richTextBox_DebugParam.Clear();
  6404. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6405. WriteACK = false;
  6406. WriteCnt = 0;
  6407. ACK_WaitCnt = 0;
  6408. while (ACK_WaitCnt <= 2); //1s
  6409. //获取调试信息
  6410. string DebugDefaultInfo = "";
  6411. if (richTextBox_DebugParam.Text == string.Empty)
  6412. {
  6413. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6414. label_FacModeStatus.Text = "存在故障!";
  6415. label_FacModeResult.BackColor = Color.Red;
  6416. label_FacModeResult.Text = "测试异常";
  6417. Delay_ms(500);
  6418. //存储异常并上传
  6419. FacMode_Stop(false);
  6420. return;
  6421. }
  6422. else
  6423. {
  6424. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6425. }
  6426. //设置模式
  6427. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6428. strDataTemp[0] = "整体运行模式=3";
  6429. //发送数据
  6430. Code[0] = 0;
  6431. Code[1] = 0;
  6432. for (int i = 0; i < strDataTemp.Length; i++)
  6433. {
  6434. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6435. Code[2 * i + 2] = (byte)uwDataTemp;
  6436. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6437. }
  6438. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6439. label_FacModeStatus.Text = "启动电机";
  6440. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6441. #else //通过Walk模式启动电机
  6442. //设置转速100%
  6443. var Data = new byte[1];
  6444. Data[0] = (byte)100;
  6445. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6446. Delay_ms(500);
  6447. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6448. Delay_ms(500);
  6449. //启动电机进入WALK模式
  6450. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6451. Code[0] = 0x22;
  6452. Code[1] = 0xF0;
  6453. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6454. WriteACK = false;
  6455. WriteCnt = 0;
  6456. ACK_WaitCnt = 0;
  6457. while (ACK_WaitCnt <= 2) ; //1s
  6458. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6459. {
  6460. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6461. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6462. ACK_WaitCnt = 0;
  6463. while (ACK_WaitCnt <= 2) ; //1s
  6464. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6465. {
  6466. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6467. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6468. ACK_WaitCnt = 0;
  6469. while (ACK_WaitCnt <= 2) ; //1s
  6470. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6471. {
  6472. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6473. label_FacModeStatus.Text = "存在故障!";
  6474. label_FacModeResult.BackColor = Color.Red;
  6475. label_FacModeResult.Text = "测试异常";
  6476. Delay_ms(500);
  6477. //存储异常并上传
  6478. FacMode_Stop(false);
  6479. return;
  6480. }
  6481. }
  6482. }
  6483. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6484. #endif
  6485. Delay_ms(3000);
  6486. } while (false);
  6487. //判断车速
  6488. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6489. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6490. {
  6491. label_FacModeSpeed.BackColor = Color.Green;
  6492. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6493. }
  6494. else
  6495. {
  6496. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6497. label_FacModeStatus.Text = "存在故障!";
  6498. label_FacModeResult.BackColor = Color.Red;
  6499. label_FacModeResult.Text = "测试异常";
  6500. Delay_ms(500);
  6501. //存储异常并上传
  6502. FacMode_Stop(false);
  6503. return;
  6504. }
  6505. //判断电压
  6506. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6507. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6508. {
  6509. label_FacModeVolTest.BackColor = Color.Green;
  6510. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6511. }
  6512. else
  6513. {
  6514. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\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. //判断电流
  6524. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6525. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6526. {
  6527. label_FacModeCurrentTest.BackColor = Color.Green;
  6528. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6529. }
  6530. else
  6531. {
  6532. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6533. label_FacModeStatus.Text = "存在故障!";
  6534. label_FacModeResult.BackColor = Color.Red;
  6535. label_FacModeResult.Text = "测试异常";
  6536. Delay_ms(500);
  6537. //存储异常并上传
  6538. FacMode_Stop(false);
  6539. return;
  6540. }
  6541. //判断温度
  6542. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6543. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6544. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6545. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6546. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6547. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6548. {
  6549. label_FacModeNTC.BackColor = Color.Green;
  6550. 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");
  6551. }
  6552. else
  6553. {
  6554. 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");
  6555. label_FacModeStatus.Text = "存在故障!";
  6556. label_FacModeResult.BackColor = Color.Red;
  6557. label_FacModeResult.Text = "测试异常";
  6558. Delay_ms(500);
  6559. //存储异常并上传
  6560. FacMode_Stop(false);
  6561. return;
  6562. }
  6563. //判断转速
  6564. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6565. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6566. {
  6567. label_FacModeMotorSpeed.BackColor = Color.Green;
  6568. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6569. }
  6570. else
  6571. {
  6572. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6573. label_FacModeStatus.Text = "存在故障!";
  6574. label_FacModeResult.BackColor = Color.Red;
  6575. label_FacModeResult.Text = "测试异常";
  6576. Delay_ms(500);
  6577. //存储异常并上传
  6578. FacMode_Stop(false);
  6579. return;
  6580. }
  6581. //发送指令停止电机
  6582. do
  6583. {
  6584. //设置转速0%
  6585. var Data = new byte[1];
  6586. Data[0] = (byte)0;
  6587. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6588. Delay_ms(500);
  6589. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6590. Delay_ms(500);
  6591. #if false //通过修改调试模式停止电机
  6592. //获取调试信息
  6593. string DebugDefaultInfo = "";
  6594. if (richTextBox_DebugParam.Text == string.Empty)
  6595. {
  6596. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6597. label_FacModeStatus.Text = "存在故障!";
  6598. label_FacModeResult.BackColor = Color.Red;
  6599. label_FacModeResult.Text = "测试异常";
  6600. Delay_ms(500);
  6601. //存储异常并上传
  6602. FacMode_Stop(false);
  6603. return;
  6604. }
  6605. else
  6606. {
  6607. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6608. }
  6609. //设置模式
  6610. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6611. //发送数据
  6612. Code[0] = 0;
  6613. Code[1] = 0;
  6614. for (int i = 0; i < strDataTemp.Length; i++)
  6615. {
  6616. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6617. Code[2 * i + 2] = (byte)uwDataTemp;
  6618. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6619. }
  6620. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6621. label_FacModeStatus.Text = "停止电机";
  6622. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6623. #else //通过调整档位停止电机
  6624. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6625. Code[0] = 0x00;
  6626. Code[1] = 0xF0;
  6627. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6628. WriteACK = false;
  6629. WriteCnt = 0;
  6630. ACK_WaitCnt = 0;
  6631. while (ACK_WaitCnt <= 2) ; //1s
  6632. if (textBox_RunInfo_GearSt.Text != "OFF")
  6633. {
  6634. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  6635. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6636. ACK_WaitCnt = 0;
  6637. while (ACK_WaitCnt <= 2) ; //1s
  6638. if (textBox_RunInfo_GearSt.Text != "OFF")
  6639. {
  6640. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  6641. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6642. ACK_WaitCnt = 0;
  6643. while (ACK_WaitCnt <= 2) ; //1s
  6644. if (textBox_RunInfo_GearSt.Text != "OFF")
  6645. {
  6646. }
  6647. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6648. label_FacModeStatus.Text = "存在故障!";
  6649. label_FacModeResult.BackColor = Color.Red;
  6650. label_FacModeResult.Text = "测试异常";
  6651. Delay_ms(500);
  6652. //存储异常并上传
  6653. FacMode_Stop(false);
  6654. return;
  6655. }
  6656. }
  6657. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6658. #endif
  6659. Delay_ms(2000);
  6660. } while (false);
  6661. }
  6662. else
  6663. {
  6664. label_FacModeSpeed.BackColor = Color.Yellow;
  6665. label_FacModeVolTest.BackColor = Color.Yellow;
  6666. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6667. label_FacModeNTC.BackColor = Color.Yellow;
  6668. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6669. label_FacModeStatus.Text = "跳过基础功能检测!";
  6670. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6671. Delay_ms(500);
  6672. }
  6673. //力矩检测
  6674. if (checkBox_FacTor.Checked)
  6675. {
  6676. label_FacModeStatus.Text = "力矩传感器检测!";
  6677. //发送指令进入配置模式
  6678. do
  6679. {
  6680. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6681. {
  6682. break;
  6683. }
  6684. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6685. Code[0] = 0x01;
  6686. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6687. WriteACK = false;
  6688. WriteCnt = 0;
  6689. ACK_WaitCnt = 0;
  6690. while (ACK_WaitCnt <= 2) ; //1s
  6691. if (textBox_RunInfo_Vol.Text != "---")
  6692. {
  6693. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6694. Delay_ms(500);
  6695. }
  6696. else
  6697. {
  6698. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6699. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6700. ACK_WaitCnt = 0;
  6701. while (ACK_WaitCnt <= 2) ; //1s
  6702. if (textBox_RunInfo_Vol.Text != "---")
  6703. {
  6704. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6705. Delay_ms(500);
  6706. }
  6707. else
  6708. {
  6709. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6710. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6711. ACK_WaitCnt = 0;
  6712. while (ACK_WaitCnt <= 2) ; //1s
  6713. if (textBox_RunInfo_Vol.Text != "---")
  6714. {
  6715. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6716. Delay_ms(500);
  6717. }
  6718. else
  6719. {
  6720. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6721. label_FacModeStatus.Text = "存在故障!";
  6722. label_FacModeResult.BackColor = Color.Red;
  6723. label_FacModeResult.Text = "测试异常";
  6724. Delay_ms(500);
  6725. //存储异常并上传
  6726. FacMode_Stop(false);
  6727. return;
  6728. }
  6729. }
  6730. }
  6731. } while (false);
  6732. ushort Max = 0, Torque = 0;
  6733. //提示输入力矩信号
  6734. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  6735. ACK_WaitCnt = 0;
  6736. while (ACK_WaitCnt <= 20) //10s
  6737. {
  6738. //获取力矩值
  6739. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  6740. if (Torque > Max)
  6741. Max = Torque;
  6742. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  6743. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  6744. (ACK_WaitCnt >= 6))
  6745. {
  6746. label_FacModeTq.BackColor = Color.Green;
  6747. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6748. break;
  6749. }
  6750. }
  6751. if (ACK_WaitCnt >= 20)
  6752. {
  6753. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6754. label_FacModeStatus.Text = "存在故障!";
  6755. label_FacModeResult.BackColor = Color.Red;
  6756. label_FacModeResult.Text = "测试异常";
  6757. Delay_ms(500);
  6758. //存储异常并上传
  6759. FacMode_Stop(false);
  6760. return;
  6761. }
  6762. }
  6763. else
  6764. {
  6765. label_FacModeTq.BackColor = Color.Yellow;
  6766. label_FacModeStatus.Text = "跳过力矩检测!";
  6767. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  6768. Delay_ms(500);
  6769. }
  6770. //踏频检测
  6771. if (checkBox_FacCad.Checked)
  6772. {
  6773. label_FacModeStatus.Text = "踏频传感器检测!";
  6774. //发送指令进入配置模式
  6775. do
  6776. {
  6777. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6778. {
  6779. break;
  6780. }
  6781. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6782. Code[0] = 0x01;
  6783. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6784. WriteACK = false;
  6785. WriteCnt = 0;
  6786. ACK_WaitCnt = 0;
  6787. while (ACK_WaitCnt <= 2) ; //1s
  6788. if (textBox_RunInfo_Vol.Text != "---")
  6789. {
  6790. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6791. Delay_ms(500);
  6792. }
  6793. else
  6794. {
  6795. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6796. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6797. ACK_WaitCnt = 0;
  6798. while (ACK_WaitCnt <= 2) ; //1s
  6799. if (textBox_RunInfo_Vol.Text != "---")
  6800. {
  6801. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6802. Delay_ms(500);
  6803. }
  6804. else
  6805. {
  6806. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6807. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6808. ACK_WaitCnt = 0;
  6809. while (ACK_WaitCnt <= 2) ; //1s
  6810. if (textBox_RunInfo_Vol.Text != "---")
  6811. {
  6812. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6813. Delay_ms(500);
  6814. }
  6815. else
  6816. {
  6817. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6818. label_FacModeStatus.Text = "存在故障!";
  6819. label_FacModeResult.BackColor = Color.Red;
  6820. label_FacModeResult.Text = "测试异常";
  6821. Delay_ms(500);
  6822. //存储异常并上传
  6823. FacMode_Stop(false);
  6824. return;
  6825. }
  6826. }
  6827. }
  6828. } while (false);
  6829. ushort Max = 0, Cadence = 0;
  6830. //提示输入踏频信号
  6831. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  6832. ACK_WaitCnt = 0;
  6833. while (ACK_WaitCnt <= 20) //10s
  6834. {
  6835. //获取踏频
  6836. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  6837. if (Cadence > Max)
  6838. Max = Cadence;
  6839. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  6840. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  6841. (ACK_WaitCnt >= 6))
  6842. {
  6843. label_FacModeCad.BackColor = Color.Green;
  6844. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6845. break;
  6846. }
  6847. }
  6848. if (ACK_WaitCnt >= 20)
  6849. {
  6850. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6851. label_FacModeStatus.Text = "存在故障!";
  6852. label_FacModeResult.BackColor = Color.Red;
  6853. label_FacModeResult.Text = "测试异常";
  6854. Delay_ms(500);
  6855. //存储异常并上传
  6856. FacMode_Stop(false);
  6857. return;
  6858. }
  6859. }
  6860. else
  6861. {
  6862. label_FacModeCad.BackColor = Color.Yellow;
  6863. label_FacModeStatus.Text = "跳过踏频检测!";
  6864. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  6865. Delay_ms(500);
  6866. }
  6867. //转把检测
  6868. if (checkBox_FacThrrotleTest.Checked)
  6869. {
  6870. label_FacModeStatus.Text = "转把检测";
  6871. //发送指令进入配置模式
  6872. do
  6873. {
  6874. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6875. {
  6876. break;
  6877. }
  6878. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6879. Code[0] = 0x01;
  6880. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6881. WriteACK = false;
  6882. WriteCnt = 0;
  6883. ACK_WaitCnt = 0;
  6884. while (ACK_WaitCnt <= 2) ; //1s
  6885. if (textBox_RunInfo_Vol.Text != "---")
  6886. {
  6887. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6888. Delay_ms(500);
  6889. }
  6890. else
  6891. {
  6892. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6893. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6894. ACK_WaitCnt = 0;
  6895. while (ACK_WaitCnt <= 2) ; //1s
  6896. if (textBox_RunInfo_Vol.Text != "---")
  6897. {
  6898. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6899. Delay_ms(500);
  6900. }
  6901. else
  6902. {
  6903. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6904. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6905. ACK_WaitCnt = 0;
  6906. while (ACK_WaitCnt <= 2) ; //1s
  6907. if (textBox_RunInfo_Vol.Text != "---")
  6908. {
  6909. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6910. Delay_ms(500);
  6911. }
  6912. else
  6913. {
  6914. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6915. label_FacModeStatus.Text = "存在故障!";
  6916. label_FacModeResult.BackColor = Color.Red;
  6917. label_FacModeResult.Text = "测试异常";
  6918. Delay_ms(500);
  6919. //存储异常并上传
  6920. FacMode_Stop(false);
  6921. return;
  6922. }
  6923. }
  6924. }
  6925. } while (false);
  6926. //进入TURBO档
  6927. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  6928. Code[0] = 0x04;
  6929. Code[1] = 0xF0;
  6930. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6931. WriteACK = false;
  6932. WriteCnt = 0;
  6933. ACK_WaitCnt = 0;
  6934. while (ACK_WaitCnt <= 2) ; //1s
  6935. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6936. {
  6937. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  6938. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6939. ACK_WaitCnt = 0;
  6940. while (ACK_WaitCnt <= 2) ; //1s
  6941. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6942. {
  6943. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  6944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6945. ACK_WaitCnt = 0;
  6946. while (ACK_WaitCnt <= 2) ; //1s
  6947. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6948. {
  6949. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  6950. label_FacModeStatus.Text = "存在故障!";
  6951. label_FacModeResult.BackColor = Color.Red;
  6952. label_FacModeResult.Text = "测试异常";
  6953. Delay_ms(500);
  6954. //存储异常并上传
  6955. FacMode_Stop(false);
  6956. return;
  6957. }
  6958. }
  6959. }
  6960. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  6961. ACK_WaitCnt = 0;
  6962. while (ACK_WaitCnt <= 20)
  6963. {
  6964. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  6965. {
  6966. label_FacModeGas.BackColor = Color.Green;
  6967. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  6968. break;
  6969. }
  6970. }
  6971. if (ACK_WaitCnt >= 20) //转把超时
  6972. {
  6973. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  6974. label_FacModeStatus.Text = "存在故障!";
  6975. label_FacModeResult.BackColor = Color.Red;
  6976. label_FacModeResult.Text = "测试异常";
  6977. Delay_ms(500);
  6978. //存储异常并上传
  6979. FacMode_Stop(false);
  6980. return;
  6981. }
  6982. }
  6983. else
  6984. {
  6985. label_FacModeGas.BackColor = Color.Yellow;
  6986. label_FacModeStatus.Text = "跳过转把检测!";
  6987. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  6988. Delay_ms(500);
  6989. }
  6990. //刹车检测
  6991. if (checkBox_FacBreakTest.Checked)
  6992. {
  6993. label_FacModeStatus.Text = "刹把检测";
  6994. //发送指令进入配置模式
  6995. do
  6996. {
  6997. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6998. {
  6999. break;
  7000. }
  7001. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7002. Code[0] = 0x01;
  7003. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7004. WriteACK = false;
  7005. WriteCnt = 0;
  7006. ACK_WaitCnt = 0;
  7007. while (ACK_WaitCnt <= 2) ; //1s
  7008. if (textBox_RunInfo_Vol.Text != "---")
  7009. {
  7010. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7011. Delay_ms(500);
  7012. }
  7013. else
  7014. {
  7015. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7016. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7017. ACK_WaitCnt = 0;
  7018. while (ACK_WaitCnt <= 2) ; //1s
  7019. if (textBox_RunInfo_Vol.Text != "---")
  7020. {
  7021. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7022. Delay_ms(500);
  7023. }
  7024. else
  7025. {
  7026. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7027. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7028. ACK_WaitCnt = 0;
  7029. while (ACK_WaitCnt <= 2) ; //1s
  7030. if (textBox_RunInfo_Vol.Text != "---")
  7031. {
  7032. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7033. Delay_ms(500);
  7034. }
  7035. else
  7036. {
  7037. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7038. label_FacModeStatus.Text = "存在故障!";
  7039. label_FacModeResult.BackColor = Color.Red;
  7040. label_FacModeResult.Text = "测试异常";
  7041. Delay_ms(500);
  7042. //存储异常并上传
  7043. FacMode_Stop(false);
  7044. return;
  7045. }
  7046. }
  7047. }
  7048. } while (false);
  7049. //设置转速100%
  7050. var Data = new byte[1];
  7051. Data[0] = (byte)100;
  7052. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7053. Delay_ms(500);
  7054. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7055. Delay_ms(500);
  7056. //启动电机进入WALK模式
  7057. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7058. Code[0] = 0x22;
  7059. Code[1] = 0xF0;
  7060. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7061. WriteACK = false;
  7062. WriteCnt = 0;
  7063. ACK_WaitCnt = 0;
  7064. while (ACK_WaitCnt <= 2) ; //1s
  7065. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7066. {
  7067. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7068. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7069. ACK_WaitCnt = 0;
  7070. while (ACK_WaitCnt <= 2) ; //1s
  7071. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7072. {
  7073. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7074. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7075. ACK_WaitCnt = 0;
  7076. while (ACK_WaitCnt <= 2) ; //1s
  7077. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7078. {
  7079. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7080. label_FacModeStatus.Text = "存在故障!";
  7081. label_FacModeResult.BackColor = Color.Red;
  7082. label_FacModeResult.Text = "测试异常";
  7083. Delay_ms(500);
  7084. //存储异常并上传
  7085. FacMode_Stop(false);
  7086. return;
  7087. }
  7088. }
  7089. }
  7090. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7091. ACK_WaitCnt = 0;
  7092. while (ACK_WaitCnt <= 20)
  7093. {
  7094. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7095. {
  7096. label_FacModeBreak.BackColor = Color.Green;
  7097. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7098. break;
  7099. }
  7100. }
  7101. if (ACK_WaitCnt >= 20) //剎把超时
  7102. {
  7103. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
  7104. label_FacModeStatus.Text = "存在故障!";
  7105. label_FacModeResult.BackColor = Color.Red;
  7106. label_FacModeResult.Text = "测试异常";
  7107. Delay_ms(500);
  7108. //存储异常并上传
  7109. FacMode_Stop(false);
  7110. return;
  7111. }
  7112. //停止电机
  7113. Code[0] = 0x00;
  7114. Code[1] = 0xF0;
  7115. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7116. WriteACK = false;
  7117. WriteCnt = 0;
  7118. ACK_WaitCnt = 0;
  7119. while (ACK_WaitCnt <= 2) ; //1s
  7120. if (textBox_RunInfo_GearSt.Text != "OFF")
  7121. {
  7122. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7123. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7124. ACK_WaitCnt = 0;
  7125. while (ACK_WaitCnt <= 2) ; //1s
  7126. if (textBox_RunInfo_GearSt.Text != "OFF")
  7127. {
  7128. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7129. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7130. ACK_WaitCnt = 0;
  7131. while (ACK_WaitCnt <= 2) ; //1s
  7132. if (textBox_RunInfo_GearSt.Text != "OFF")
  7133. {
  7134. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7135. label_FacModeStatus.Text = "存在故障!";
  7136. label_FacModeResult.BackColor = Color.Red;
  7137. label_FacModeResult.Text = "测试异常";
  7138. Delay_ms(500);
  7139. //存储异常并上传
  7140. FacMode_Stop(false);
  7141. return;
  7142. }
  7143. }
  7144. }
  7145. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7146. Delay_ms(500);
  7147. }
  7148. else
  7149. {
  7150. label_FacModeBreak.BackColor = Color.Yellow;
  7151. label_FacModeStatus.Text = "跳过刹车检测!";
  7152. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7153. Delay_ms(500);
  7154. }
  7155. //前后灯检测
  7156. if (checkBox_FacLightTest.Checked)
  7157. {
  7158. //前后灯检测
  7159. label_FacModeStatus.Text = "前后灯检测";
  7160. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7161. //发送指令打开车灯
  7162. Code[0] = 0x00;
  7163. Code[1] = 0xF1;
  7164. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7165. WriteACK = false;
  7166. WriteCnt = 0;
  7167. ACK_WaitCnt = 0;
  7168. while (ACK_WaitCnt <= 2) ; //1s
  7169. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7170. {
  7171. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7172. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7173. ACK_WaitCnt = 0;
  7174. while (ACK_WaitCnt <= 2); //1s
  7175. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7176. {
  7177. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7178. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7179. ACK_WaitCnt = 0;
  7180. while (ACK_WaitCnt <= 2) ; //1s
  7181. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7182. {
  7183. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7184. label_FacModeStatus.Text = "存在故障!";
  7185. label_FacModeResult.BackColor = Color.Red;
  7186. label_FacModeResult.Text = "测试异常";
  7187. Delay_ms(500);
  7188. //存储异常并上传
  7189. FacMode_Stop(false);
  7190. return;
  7191. }
  7192. }
  7193. }
  7194. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7195. Delay_ms(500);
  7196. //提示检查灯压是否正确
  7197. if (MessageBox.Show("前后灯是否正常?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7198. {
  7199. label_FacModeLightF.BackColor = Color.Green;
  7200. label_FacModeLightB.BackColor = Color.Green;
  7201. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7202. Delay_ms(500);
  7203. }
  7204. else
  7205. {
  7206. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7207. label_FacModeStatus.Text = "存在故障!";
  7208. label_FacModeResult.BackColor = Color.Red;
  7209. label_FacModeResult.Text = "测试异常";
  7210. Delay_ms(500);
  7211. //存储异常并上传
  7212. FacMode_Stop(false);
  7213. return;
  7214. }
  7215. //发送指令关闭车灯
  7216. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7217. Code[0] = 0x00;
  7218. Code[1] = 0xF0;
  7219. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7220. WriteACK = false;
  7221. WriteCnt = 0;
  7222. ACK_WaitCnt = 0;
  7223. while (ACK_WaitCnt <= 2) ; //1s
  7224. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7225. {
  7226. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7227. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7228. ACK_WaitCnt = 0;
  7229. while (ACK_WaitCnt <= 2) ; //1s
  7230. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7231. {
  7232. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7233. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7234. ACK_WaitCnt = 0;
  7235. while (ACK_WaitCnt <= 2) ; //1s
  7236. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7237. {
  7238. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7239. label_FacModeStatus.Text = "存在故障!";
  7240. label_FacModeResult.BackColor = Color.Red;
  7241. label_FacModeResult.Text = "测试异常";
  7242. Delay_ms(500);
  7243. //存储异常并上传
  7244. FacMode_Stop(false);
  7245. return;
  7246. }
  7247. }
  7248. }
  7249. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7250. Delay_ms(500);
  7251. }
  7252. else
  7253. {
  7254. label_FacModeLightF.BackColor = Color.Yellow;
  7255. label_FacModeLightB.BackColor = Color.Yellow;
  7256. label_FacModeStatus.Text = "跳过前后灯检测!";
  7257. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7258. Delay_ms(500);
  7259. }
  7260. //软件版本检测
  7261. do
  7262. {
  7263. label_FacModeStatus.Text = "软件版本确认";
  7264. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7265. //发送指令读取版本
  7266. Class_Motor_Ver.Mode = "---";
  7267. Class_Motor_Ver.SN = "---";
  7268. Class_Motor_Ver.HW = "---";
  7269. Class_Motor_Ver.FW = "---";
  7270. Class_Motor_Ver.Special = "---";
  7271. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7272. ACK_WaitCnt = 0;
  7273. while (ACK_WaitCnt <= 2) ; //1s
  7274. if (Class_Motor_Ver.Mode == "---")
  7275. {
  7276. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7277. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7278. ACK_WaitCnt = 0;
  7279. while (ACK_WaitCnt <= 2) ; //1s
  7280. if (Class_Motor_Ver.Mode == "---")
  7281. {
  7282. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7283. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7284. ACK_WaitCnt = 0;
  7285. while (ACK_WaitCnt <= 2) ; //1s
  7286. if (Class_Motor_Ver.Mode == "---")
  7287. {
  7288. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7289. label_FacModeStatus.Text = "存在故障!";
  7290. label_FacModeResult.BackColor = Color.Red;
  7291. label_FacModeResult.Text = "测试异常";
  7292. Delay_ms(500);
  7293. //存储异常并上传
  7294. FacMode_Stop(false);
  7295. return;
  7296. }
  7297. }
  7298. }
  7299. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7300. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7301. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7302. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7303. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7304. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7305. //判断版本是否正确
  7306. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7307. string VerRead = "";
  7308. try
  7309. {
  7310. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7311. }
  7312. catch (System.Exception)
  7313. {
  7314. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7315. label_FacModeStatus.Text = "存在故障!";
  7316. label_FacModeResult.BackColor = Color.Red;
  7317. label_FacModeResult.Text = "测试异常";
  7318. Delay_ms(500);
  7319. //存储异常并上传
  7320. FacMode_Stop(false);
  7321. return;
  7322. }
  7323. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7324. {
  7325. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7326. label_FacModeStatus.Text = "存在故障!";
  7327. label_FacModeResult.BackColor = Color.Red;
  7328. label_FacModeResult.Text = "测试异常";
  7329. Delay_ms(500);
  7330. //存储异常并上传
  7331. FacMode_Stop(false);
  7332. return;
  7333. }
  7334. label_FacModeFWVersion.BackColor = Color.Green;
  7335. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7336. Delay_ms(500);
  7337. } while (false);
  7338. //测试合格
  7339. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7340. label_FacModeStatus.Text = "测试结束!";
  7341. label_FacModeResult.BackColor = Color.Green;
  7342. label_FacModeResult.Text = "测试合格";
  7343. Delay_ms(500);
  7344. //存储并上传
  7345. FacMode_Stop(true);
  7346. return;
  7347. }
  7348. private void FacModelLabelInit()
  7349. {
  7350. //测试状态标签
  7351. label_FacModeResult.BackColor = Color.Yellow;
  7352. label_FacModeResult.Text = "测试中";
  7353. //测试过程标签
  7354. label_FacModeStatus.Text = "测试就绪";
  7355. //测试结果标签
  7356. foreach (Control c in groupBox28.Controls)
  7357. {
  7358. if (c is Label)
  7359. {
  7360. if (c.Text == string.Empty)
  7361. c.BackColor = Color.Red;
  7362. }
  7363. }
  7364. }
  7365. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7366. {
  7367. //更新生产配置文件目录
  7368. GetDateList(false);
  7369. }
  7370. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7371. {
  7372. //更新生产配置文件目录
  7373. GetDateList(false);
  7374. }
  7375. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7376. {
  7377. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7378. richTextBox_FacModeLog.ScrollToCaret();
  7379. }
  7380. /// <summary>
  7381. /// 参数检验测试停止
  7382. /// </summary>
  7383. /// <param name="OK_Flag"></param>
  7384. private void CheckMode_Stop(bool OK_Flag)
  7385. {
  7386. //打开开始按钮
  7387. button_CheckModeStart.Enabled = true;
  7388. //系统关机
  7389. var Code = new byte[32];//发送的指令数据
  7390. Code[0] = 0xF0;
  7391. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7392. //关闭串口
  7393. //mySerialProcess.SerialClose(false);
  7394. //路径设置
  7395. string LocalSavePath = "";
  7396. string ServerSavePath = "";
  7397. if (OK_Flag)
  7398. {
  7399. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7400. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7401. }
  7402. else
  7403. {
  7404. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  7405. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  7406. }
  7407. if (Directory.Exists(LocalSavePath) == false)
  7408. {
  7409. Directory.CreateDirectory(LocalSavePath);
  7410. }
  7411. //保存和上传
  7412. string LogSavePath = "";
  7413. string LogSaveFileName = "";
  7414. string ProductInfo = textBox_CheckModeScan.Text;
  7415. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  7416. if (Directory.Exists(LogSavePath) == false)
  7417. {
  7418. Directory.CreateDirectory(LogSavePath);
  7419. }
  7420. //测试页面
  7421. Double scaleX = PrimaryScreen.ScaleX;
  7422. Double scaleY = PrimaryScreen.ScaleY;
  7423. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  7424. Graphics g = Graphics.FromImage(bit);
  7425. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  7426. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  7427. bit.Save(LogSaveFileName);
  7428. //上传测试页面到服务器
  7429. if (myFtp.IsNetConnected == true)
  7430. {
  7431. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7432. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7433. {
  7434. myFtp.MakeDir(ServerSavePath + DateNow);
  7435. }
  7436. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7437. {
  7438. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7439. }
  7440. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7441. if (result == true)
  7442. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7443. }
  7444. //测试记录
  7445. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7446. string file_str = "";
  7447. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7448. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7449. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7450. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7451. file_str += Local_HdInformation;
  7452. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7453. //上传测试记录到服务器
  7454. if (myFtp.IsNetConnected == true)
  7455. {
  7456. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7457. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7458. {
  7459. myFtp.MakeDir(ServerSavePath + DateNow);
  7460. }
  7461. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7462. {
  7463. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7464. }
  7465. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7466. if (result == true)
  7467. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7468. }
  7469. //扫码框清空
  7470. textBox_CheckModeScan.Text = "";
  7471. }
  7472. /// <summary>
  7473. /// 参数检验开始
  7474. /// </summary>
  7475. /// <param name="sender"></param>
  7476. /// <param name="e"></param>
  7477. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7478. {
  7479. //测试项目关闭编辑
  7480. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7481. foreach (Control c in groupBox29.Controls)
  7482. {
  7483. if (c is CheckBox)
  7484. c.Enabled = false;
  7485. }
  7486. ReadLockStatus = true;
  7487. //检查配置文件
  7488. if (comboBox_CheckModeCfgFile.Text == "")
  7489. {
  7490. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7491. return;
  7492. }
  7493. //开始测试
  7494. CheckTestStart();
  7495. }
  7496. /// <summary>
  7497. /// 参数检验测试子函数
  7498. /// </summary>
  7499. private void CheckTestStart()
  7500. {
  7501. //初始化标签
  7502. CheckModeLabelInit();
  7503. richTextBox_CheckModeLog.Clear();
  7504. //按钮禁止操作
  7505. button_CheckModeStart.Enabled = false;
  7506. //记录配置文件
  7507. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7508. //检查打标信息
  7509. label_CheckModeStatus.Text = "检查扫码信息";
  7510. Delay_ms(500);
  7511. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7512. if (textBox_CheckModeScan.Text == string.Empty)
  7513. {
  7514. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7515. button__FacMode_Start.Enabled = false;
  7516. return;
  7517. }
  7518. try
  7519. {
  7520. if (中置电机ToolStripMenuItem.Checked == true)
  7521. {
  7522. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7523. {
  7524. label_CheckModeStatus.Text = "存在故障!";
  7525. label_CheckModeResult.BackColor = Color.Red;
  7526. label_CheckModeResult.Text = "标签格式错误";
  7527. button_CheckModeStart.Enabled = true;
  7528. return;
  7529. }
  7530. }
  7531. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7532. {
  7533. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  7534. {
  7535. label_CheckModeStatus.Text = "存在故障!";
  7536. label_CheckModeResult.BackColor = Color.Red;
  7537. label_CheckModeResult.Text = "标签格式错误";
  7538. button_CheckModeStart.Enabled = true;
  7539. return;
  7540. }
  7541. }
  7542. }
  7543. catch (System.Exception)
  7544. {
  7545. label_CheckModeStatus.Text = "存在故障!";
  7546. label_CheckModeResult.BackColor = Color.Red;
  7547. label_CheckModeResult.Text = "标签格式错误";
  7548. button_CheckModeStart.Enabled = true;
  7549. return;
  7550. }
  7551. //打开串口
  7552. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  7553. if (!mySerialProcess.mySerial.IsOpen)
  7554. {
  7555. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7556. button__FacMode_Start.Enabled = false;
  7557. return;
  7558. }
  7559. //流水号计数
  7560. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  7561. serial += 1;
  7562. label_CheckModeSerial.Text = serial.ToString();
  7563. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  7564. //创建线程,执行测试任务
  7565. Thread th = new Thread(CheckModeTest_Task);
  7566. th.Start();
  7567. }
  7568. /// <summary>
  7569. /// 执行一次测试任务
  7570. /// </summary>
  7571. private void CheckModeTest_Task()
  7572. {
  7573. //开始测试
  7574. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  7575. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  7576. //变量定义
  7577. var Code = new byte[255];//发送的指令数据
  7578. ushort DataTemp;
  7579. short DataTemp_Int16;
  7580. string ResultPathName = "";
  7581. label_CheckModeStatus.Text = "开始测试";
  7582. BootInfo = "";
  7583. Delay_ms(500);
  7584. label_CheckModeStatus.Text = "系统开机";
  7585. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  7586. if (uARTToolStripMenuItem.Checked)
  7587. {
  7588. Code[0] = (byte)'R';
  7589. Code[1] = (byte)'E';
  7590. Code[2] = (byte)'S';
  7591. Code[3] = (byte)'E';
  7592. Code[4] = (byte)'T';
  7593. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  7594. Delay_ms(500);
  7595. }
  7596. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  7597. //确保测试前先关机,发送关机指令再发送开机指令
  7598. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  7599. Code[0] = 0xF0;
  7600. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7601. Delay_ms(1500);
  7602. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  7603. Code[0] = 0xF1;
  7604. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7605. ACK_WaitCnt = 0;
  7606. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  7607. while (ACK_WaitCnt <= 20) ; //10s
  7608. //检查BOOT版本
  7609. if (BootInfo != string.Empty)
  7610. {
  7611. label_CheckModeBoot.BackColor = Color.Green;
  7612. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  7613. Delay_ms(500);
  7614. }
  7615. else
  7616. {
  7617. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  7618. label_CheckModeStatus.Text = "存在故障!";
  7619. label_CheckModeResult.BackColor = Color.Red;
  7620. label_CheckModeResult.Text = "测试异常";
  7621. Delay_ms(500);
  7622. //存储异常并上传
  7623. CheckMode_Stop(false);
  7624. return;
  7625. }
  7626. #if false
  7627. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7628. {
  7629. Code[0] = 0x00;//5S协议
  7630. Code[1] = 0x00;
  7631. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7632. Delay_ms(500);
  7633. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7634. Delay_ms(500);
  7635. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  7636. }
  7637. #endif
  7638. //发送指令读取版本信息
  7639. do
  7640. {
  7641. label_CheckModeStatus.Text = "读取版本信息";
  7642. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7643. //发送指令读取版本
  7644. Class_Motor_Ver.Mode = "---";
  7645. Class_Motor_Ver.SN = "---";
  7646. Class_Motor_Ver.HW = "---";
  7647. Class_Motor_Ver.FW = "---";
  7648. Class_Motor_Ver.Special = "---";
  7649. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7650. ACK_WaitCnt = 0;
  7651. while (ACK_WaitCnt <= 2) ; //1s
  7652. if (Class_Motor_Ver.Mode == "---")
  7653. {
  7654. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7655. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7656. ACK_WaitCnt = 0;
  7657. while (ACK_WaitCnt <= 2) ; //1s
  7658. if (Class_Motor_Ver.Mode == "---")
  7659. {
  7660. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7661. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7662. ACK_WaitCnt = 0;
  7663. while (ACK_WaitCnt <= 2) ; //1s
  7664. if (Class_Motor_Ver.Mode == "---")
  7665. {
  7666. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  7667. label_CheckModeStatus.Text = "存在故障!";
  7668. label_CheckModeResult.BackColor = Color.Red;
  7669. label_CheckModeResult.Text = "测试异常";
  7670. Delay_ms(500);
  7671. //存储异常并上传
  7672. CheckMode_Stop(false);
  7673. return;
  7674. }
  7675. }
  7676. }
  7677. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7678. Delay_ms(500);
  7679. } while (false);
  7680. //软件版本检查
  7681. if (checkBox_CheckModeFWVer.Checked)
  7682. {
  7683. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7684. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7685. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7686. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7687. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7688. //判断版本是否正确
  7689. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  7690. string VerRead = "";
  7691. try
  7692. {
  7693. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7694. }
  7695. catch (System.Exception)
  7696. {
  7697. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7698. label_CheckModeStatus.Text = "存在故障!";
  7699. label_CheckModeResult.BackColor = Color.Red;
  7700. label_CheckModeResult.Text = "测试异常";
  7701. Delay_ms(500);
  7702. //存储异常并上传
  7703. CheckMode_Stop(false);
  7704. return;
  7705. }
  7706. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7707. {
  7708. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7709. label_CheckModeStatus.Text = "存在故障!";
  7710. label_CheckModeResult.BackColor = Color.Red;
  7711. label_CheckModeResult.Text = "测试异常";
  7712. Delay_ms(500);
  7713. //存储异常并上传
  7714. CheckMode_Stop(false);
  7715. return;
  7716. }
  7717. label_CheckModeFWVer.BackColor = Color.Green;
  7718. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7719. Delay_ms(500);
  7720. }
  7721. else
  7722. {
  7723. label_CheckModeFWVer.BackColor = Color.Yellow;
  7724. label_CheckModeStatus.Text = "跳过软件版本查询";
  7725. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  7726. Delay_ms(500);
  7727. }
  7728. //打标信息核对
  7729. if (checkBox_CheckModeSN.Checked)
  7730. {
  7731. label_CheckModeStatus.Text = "核对打标信息";
  7732. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  7733. //根据扫码信息获取型号和SN
  7734. string ScanInfo = textBox_CheckModeScan.Text;
  7735. string regexInfo = "";
  7736. string[] InfoList = { "" };
  7737. try
  7738. {
  7739. if (中置电机ToolStripMenuItem.Checked == true)
  7740. {
  7741. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  7742. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  7743. }
  7744. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7745. {
  7746. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7747. string Model = InfoList[0];
  7748. string Spec = InfoList[1];
  7749. string Sn = InfoList[2];
  7750. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  7751. InfoList[1] = Sn;
  7752. }
  7753. }
  7754. catch
  7755. {
  7756. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  7757. label_FacModeStatus.Text = "存在故障!";
  7758. label_FacModeResult.BackColor = Color.Red;
  7759. label_FacModeResult.Text = "标签格式错误";
  7760. Delay_ms(500);
  7761. //存储异常并上传
  7762. CheckMode_Stop(false);
  7763. return;
  7764. }
  7765. //核对型号
  7766. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  7767. {
  7768. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  7769. label_CheckModeStatus.Text = "存在故障!";
  7770. label_CheckModeResult.BackColor = Color.Red;
  7771. label_CheckModeResult.Text = "测试异常";
  7772. Delay_ms(500);
  7773. //存储异常并上传
  7774. CheckMode_Stop(false);
  7775. return;
  7776. }
  7777. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  7778. Delay_ms(500);
  7779. //核对SN
  7780. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  7781. {
  7782. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  7783. label_CheckModeStatus.Text = "存在故障!";
  7784. label_CheckModeResult.BackColor = Color.Red;
  7785. label_CheckModeResult.Text = "测试异常";
  7786. Delay_ms(500);
  7787. //存储异常并上传
  7788. CheckMode_Stop(false);
  7789. return;
  7790. }
  7791. label_CheckModeSN.BackColor = Color.Green;
  7792. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  7793. Delay_ms(500);
  7794. }
  7795. else
  7796. {
  7797. label_CheckModeSN.BackColor = Color.Yellow;
  7798. label_CheckModeStatus.Text = "跳过打标信息确认";
  7799. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  7800. Delay_ms(500);
  7801. }
  7802. //参数检验
  7803. if (checkBox_CheckModeCfg.Checked)
  7804. {
  7805. //读取配置文件信息
  7806. label_CheckModeStatus.Text = "参数检查";
  7807. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  7808. //配置文件
  7809. List<byte[]> CmdList = new List<byte[]>();
  7810. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  7811. //从服务器下载文件
  7812. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  7813. {
  7814. string SelectFile = "";
  7815. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  7816. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  7817. {
  7818. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  7819. }
  7820. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  7821. //打开文件
  7822. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  7823. ConfigCmd.Clear();
  7824. while (streamReader.Peek() != -1)
  7825. {
  7826. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  7827. if (fileLineInfo.Contains("["))
  7828. {
  7829. if (fileLineInfo.Contains("助力参数"))
  7830. {
  7831. fileLineInfo = streamReader.ReadLine();
  7832. }
  7833. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  7834. }
  7835. }
  7836. streamReader.Close();
  7837. }
  7838. //从本地加载文件
  7839. else
  7840. {
  7841. string SelectFile = "";
  7842. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  7843. //打开文件
  7844. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  7845. ConfigCmd.Clear();
  7846. while (streamReader.Peek() != -1)
  7847. {
  7848. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  7849. if (fileLineInfo.Contains("["))
  7850. {
  7851. if (fileLineInfo.Contains("助力参数"))
  7852. {
  7853. fileLineInfo = streamReader.ReadLine();
  7854. }
  7855. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  7856. }
  7857. }
  7858. streamReader.Close();
  7859. }
  7860. int CmdNum = ConfigCmd.Count(); //指令个数
  7861. Delay_ms(500);
  7862. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  7863. Delay_ms(500);
  7864. //逐条读取比较
  7865. try
  7866. {
  7867. foreach (string key in ConfigCmd.Keys)
  7868. {
  7869. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  7870. CmdRevStrTemp = "";
  7871. if (key.Contains("曲线"))
  7872. {
  7873. byte LineNum = 0;
  7874. var code = new byte[4];
  7875. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  7876. if (LineNum <= 5)
  7877. {
  7878. code[0] = (byte)(LineNum & 0xFF);
  7879. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7880. code[2] = (byte)(LineNum & 0xFF);
  7881. code[3] = (byte)((LineNum >> 8) & 0xFF);
  7882. }
  7883. else
  7884. {
  7885. code[0] = (byte)(LineNum & 0xFF);
  7886. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7887. code[2] = (byte)(5 & 0xFF);
  7888. code[3] = (byte)((5 >> 8) & 0xFF);
  7889. }
  7890. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  7891. }
  7892. else
  7893. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  7894. Delay_ms(500);
  7895. if (CmdRevStrTemp == string.Empty)
  7896. {
  7897. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  7898. if (key.Contains("曲线"))
  7899. {
  7900. byte LineNum = 0;
  7901. var code = new byte[4];
  7902. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  7903. if (LineNum <= 5)
  7904. {
  7905. code[0] = (byte)(LineNum & 0xFF);
  7906. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7907. code[2] = (byte)(LineNum & 0xFF);
  7908. code[3] = (byte)((LineNum >> 8) & 0xFF);
  7909. }
  7910. else
  7911. {
  7912. code[0] = (byte)(LineNum & 0xFF);
  7913. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7914. code[2] = (byte)(5 & 0xFF);
  7915. code[3] = (byte)((5 >> 8) & 0xFF);
  7916. }
  7917. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  7918. }
  7919. else
  7920. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  7921. Delay_ms(500);
  7922. if (CmdRevStrTemp == string.Empty)
  7923. {
  7924. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  7925. if (key.Contains("曲线"))
  7926. {
  7927. byte LineNum = 0;
  7928. var code = new byte[4];
  7929. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  7930. if (LineNum <= 5)
  7931. {
  7932. code[0] = (byte)(LineNum & 0xFF);
  7933. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7934. code[2] = (byte)(LineNum & 0xFF);
  7935. code[3] = (byte)((LineNum >> 8) & 0xFF);
  7936. }
  7937. else
  7938. {
  7939. code[0] = (byte)(LineNum & 0xFF);
  7940. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7941. code[2] = (byte)(5 & 0xFF);
  7942. code[3] = (byte)((5 >> 8) & 0xFF);
  7943. }
  7944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  7945. }
  7946. else
  7947. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  7948. Delay_ms(500);
  7949. if (CmdRevStrTemp == string.Empty)
  7950. {
  7951. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  7952. label_CheckModeStatus.Text = "存在故障!";
  7953. label_CheckModeResult.BackColor = Color.Red;
  7954. label_CheckModeResult.Text = "测试异常";
  7955. Delay_ms(500);
  7956. //存储异常并上传
  7957. CheckMode_Stop(false);
  7958. return;
  7959. }
  7960. }
  7961. }
  7962. //比较当前指令,读取的配置文件和返回数据比较
  7963. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  7964. string ParamRead = "";
  7965. if (string.Compare(key, "[其它传感器参数]") == 0)
  7966. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //该指令包含力矩参数
  7967. else
  7968. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim();
  7969. if (ParamWrite.Contains(ParamRead))
  7970. {
  7971. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  7972. continue;
  7973. }
  7974. else
  7975. {
  7976. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  7977. label_CheckModeStatus.Text = "存在故障!";
  7978. label_CheckModeResult.BackColor = Color.Red;
  7979. label_CheckModeResult.Text = "测试异常";
  7980. Delay_ms(500);
  7981. //存储异常并上传
  7982. CheckMode_Stop(false);
  7983. return;
  7984. }
  7985. }
  7986. }
  7987. catch (System.Exception)
  7988. {
  7989. timer_1s.Enabled = false;
  7990. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7991. timer_1s.Enabled = true;
  7992. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  7993. }
  7994. }
  7995. else
  7996. {
  7997. label_CheckModeCfg.BackColor = Color.Yellow;
  7998. label_CheckModeStatus.Text = "跳过参数检验";
  7999. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8000. Delay_ms(500);
  8001. }
  8002. label_CheckModeCfg.BackColor = Color.Green;
  8003. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8004. Delay_ms(500);
  8005. //读取力矩传感器
  8006. do
  8007. {
  8008. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8009. //发送指令读取力矩传感器标定数据
  8010. CmdRevStrTemp = "";
  8011. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8012. ACK_WaitCnt = 0;
  8013. while (ACK_WaitCnt <= 2) ; //1s
  8014. if (CmdRevStrTemp == "---")
  8015. {
  8016. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8017. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8018. ACK_WaitCnt = 0;
  8019. while (ACK_WaitCnt <= 2) ; //1s
  8020. if (CmdRevStrTemp == "---")
  8021. {
  8022. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8023. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8024. ACK_WaitCnt = 0;
  8025. while (ACK_WaitCnt <= 2) ; //1s
  8026. if (CmdRevStrTemp == "---")
  8027. {
  8028. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8029. label_CheckModeStatus.Text = "存在故障!";
  8030. label_CheckModeResult.BackColor = Color.Red;
  8031. label_CheckModeResult.Text = "测试异常";
  8032. Delay_ms(500);
  8033. //存储异常并上传
  8034. CheckMode_Stop(false);
  8035. return;
  8036. }
  8037. }
  8038. }
  8039. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8040. //取力矩传感器数据
  8041. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8042. ushort MaxTorque;
  8043. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8044. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8045. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8046. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8047. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8048. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8049. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8050. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8051. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8052. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8053. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8054. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8055. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8056. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8057. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8058. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8059. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8060. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8061. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8062. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8063. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8064. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8065. //传感器标定检验
  8066. if (checkBox_CheckModeTorque.Checked)
  8067. {
  8068. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8069. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8070. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8071. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8072. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8073. //与设置值比较
  8074. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8075. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8076. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8077. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8078. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8079. )
  8080. {
  8081. label_CheckModeTorque.BackColor = Color.Green;
  8082. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8083. Delay_ms(500);
  8084. }
  8085. else
  8086. {
  8087. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8088. label_CheckModeStatus.Text = "存在故障!";
  8089. label_CheckModeResult.BackColor = Color.Red;
  8090. label_CheckModeResult.Text = "测试异常";
  8091. Delay_ms(500);
  8092. //存储异常并上传
  8093. CheckMode_Stop(false);
  8094. return;
  8095. }
  8096. }
  8097. else
  8098. {
  8099. label_CheckModeTorque.BackColor = Color.Yellow;
  8100. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8101. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8102. Delay_ms(500);
  8103. }
  8104. } while (false);
  8105. //读取MOS内阻校准参数
  8106. do
  8107. {
  8108. if (checkBox_CheckModeMos.Checked)
  8109. {
  8110. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8111. //读取显示校准返回数据
  8112. foreach (Control c in groupBox21.Controls)
  8113. {
  8114. if (c is TextBox)
  8115. c.Text = "";
  8116. }
  8117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8118. ACK_WaitCnt = 0;
  8119. while (ACK_WaitCnt <= 2) ; //1s
  8120. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8121. {
  8122. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8123. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8124. ACK_WaitCnt = 0;
  8125. while (ACK_WaitCnt <= 2) ; //1s
  8126. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8127. {
  8128. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8129. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8130. ACK_WaitCnt = 0;
  8131. while (ACK_WaitCnt <= 2) ; //1s
  8132. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8133. {
  8134. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8135. label_CheckModeStatus.Text = "存在故障!";
  8136. label_CheckModeResult.BackColor = Color.Red;
  8137. label_CheckModeResult.Text = "测试异常";
  8138. Delay_ms(500);
  8139. //存储异常并上传
  8140. CheckMode_Stop(false);
  8141. return;
  8142. }
  8143. }
  8144. }
  8145. else
  8146. {
  8147. 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");
  8148. }
  8149. //与校准返回数据对比
  8150. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8151. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8152. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8153. 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])) &&
  8154. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8155. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8156. )
  8157. {
  8158. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8159. label_CheckModeMos.BackColor = Color.Green;
  8160. }
  8161. else
  8162. {
  8163. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8164. label_CheckModeStatus.Text = "存在故障!";
  8165. label_CheckModeResult.BackColor = Color.Red;
  8166. label_CheckModeResult.Text = "测试异常";
  8167. Delay_ms(500);
  8168. //存储异常并上传
  8169. CheckMode_Stop(false);
  8170. return;
  8171. }
  8172. }
  8173. else
  8174. {
  8175. label_CheckModeMos.BackColor = Color.Yellow;
  8176. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8177. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8178. Delay_ms(500);
  8179. }
  8180. } while (false);
  8181. //测试合格
  8182. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8183. label_CheckModeStatus.Text = "测试结束!";
  8184. label_CheckModeResult.BackColor = Color.Green;
  8185. label_CheckModeResult.Text = "测试合格";
  8186. Delay_ms(500);
  8187. //存储并上传
  8188. CheckMode_Stop(true);
  8189. return;
  8190. }
  8191. private void CheckModeLabelInit()
  8192. {
  8193. //测试状态标签
  8194. label_CheckModeResult.BackColor = Color.Yellow;
  8195. label_CheckModeResult.Text = "测试中";
  8196. //测试过程标签
  8197. label_CheckModeStatus.Text = "测试就绪";
  8198. //测试结果标签
  8199. foreach (Control c in groupBox31.Controls)
  8200. {
  8201. if (c is Label)
  8202. {
  8203. if (c.Text == string.Empty)
  8204. c.BackColor = Color.Red;
  8205. }
  8206. }
  8207. }
  8208. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8209. {
  8210. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8211. }
  8212. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8213. {
  8214. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8215. }
  8216. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8217. {
  8218. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8219. UInt32 hour = Time / 3600;
  8220. UInt32 min = (Time % 3600) / 60;
  8221. UInt32 s = (Time % 60);
  8222. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8223. }
  8224. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8225. {
  8226. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8227. richTextBox_CheckModeLog.ScrollToCaret();
  8228. }
  8229. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8230. {
  8231. TorqueParamsForm.ShowDialog();
  8232. }
  8233. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8234. {
  8235. if (e.KeyCode == Keys.Enter)
  8236. CheckTestStart();
  8237. }
  8238. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8239. {
  8240. if (e.KeyCode == Keys.Enter)
  8241. TestStart();
  8242. }
  8243. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8244. {
  8245. if (numericUpDown_SpeedAdj.Value <= 10)
  8246. numericUpDown_SpeedAdj.Value = 0;
  8247. else
  8248. numericUpDown_SpeedAdj.Value -= 10;
  8249. }
  8250. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  8251. {
  8252. if (numericUpDown_SpeedAdj.Value >= 90)
  8253. numericUpDown_SpeedAdj.Value = 100;
  8254. else
  8255. numericUpDown_SpeedAdj.Value += 10;
  8256. }
  8257. private void button_SpeedDec1_Click(object sender, EventArgs e)
  8258. {
  8259. if (numericUpDown_SpeedAdj.Value <= 1)
  8260. numericUpDown_SpeedAdj.Value = 0;
  8261. else
  8262. numericUpDown_SpeedAdj.Value -= 1;
  8263. }
  8264. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  8265. {
  8266. if(numericUpDown_SpeedAdj.Value >= 99)
  8267. numericUpDown_SpeedAdj.Value = 100;
  8268. else
  8269. numericUpDown_SpeedAdj.Value += 1;
  8270. }
  8271. bool WriteLockStatus = true;
  8272. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  8273. {
  8274. if (WriteLockStatus == true)
  8275. {
  8276. EnterForm1.ShowDialog();
  8277. try
  8278. {
  8279. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8280. {
  8281. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8282. {
  8283. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8284. foreach (Control c in groupBox2.Controls)
  8285. {
  8286. if (c is CheckBox)
  8287. c.Enabled = true;
  8288. }
  8289. WriteLockStatus = !WriteLockStatus;
  8290. }
  8291. else
  8292. {
  8293. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8294. }
  8295. }
  8296. else
  8297. {
  8298. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8299. }
  8300. }
  8301. catch (Exception)
  8302. {
  8303. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8304. }
  8305. }
  8306. else
  8307. {
  8308. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8309. foreach (Control c in groupBox2.Controls)
  8310. {
  8311. if (c is CheckBox)
  8312. c.Enabled = false;
  8313. }
  8314. WriteLockStatus = !WriteLockStatus;
  8315. }
  8316. }
  8317. bool ReadLockStatus = true;
  8318. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  8319. {
  8320. if (ReadLockStatus == true)
  8321. {
  8322. EnterForm1.ShowDialog();
  8323. try
  8324. {
  8325. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8326. {
  8327. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8328. {
  8329. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8330. foreach (Control c in groupBox29.Controls)
  8331. {
  8332. if (c is CheckBox)
  8333. c.Enabled = true;
  8334. }
  8335. ReadLockStatus = !ReadLockStatus;
  8336. }
  8337. else
  8338. {
  8339. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8340. }
  8341. }
  8342. else
  8343. {
  8344. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8345. }
  8346. }
  8347. catch (Exception)
  8348. {
  8349. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8350. }
  8351. }
  8352. else
  8353. {
  8354. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8355. foreach (Control c in groupBox29.Controls)
  8356. {
  8357. if (c is CheckBox)
  8358. c.Enabled = false;
  8359. }
  8360. ReadLockStatus = !ReadLockStatus;
  8361. }
  8362. }
  8363. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  8364. {
  8365. System.Diagnostics.Process.Start("osk.exe");
  8366. }
  8367. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  8368. {
  8369. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  8370. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  8371. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  8372. }
  8373. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  8374. {
  8375. comboBox_FacModeCfgDate.SelectedIndex = -1;
  8376. comboBox_FacModeCfgFile.SelectedIndex = -1;
  8377. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  8378. }
  8379. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  8380. {
  8381. VersionForm.ShowDialog();
  8382. }
  8383. private void button_MOS_Cal_Click(object sender, EventArgs e)
  8384. {
  8385. textBox_MOS_R1.Text = "";
  8386. textBox_MOS_R2.Text = "";
  8387. textBox_MOS_R3.Text = "";
  8388. try
  8389. {
  8390. var Code = new byte[18];
  8391. for (int i = 0; i < 18; i++)
  8392. Code[i] = 0;
  8393. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8394. ushort uwDataTemp = 0;
  8395. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8396. Code[2] = (byte)(uwDataTemp & 0xFF);
  8397. Code[3] = (byte)(uwDataTemp >> 8);
  8398. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8399. Code[4] = (byte)(uwDataTemp & 0xFF);
  8400. Code[5] = (byte)(uwDataTemp >> 8);
  8401. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8402. Code[6] = (byte)(uwDataTemp & 0xFF);
  8403. Code[7] = (byte)(uwDataTemp >> 8);
  8404. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8405. Code[8] = (byte)(uwDataTemp & 0xFF);
  8406. Code[9] = (byte)(uwDataTemp >> 8);
  8407. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8408. Code[10] = (byte)(uwDataTemp & 0xFF);
  8409. Code[11] = (byte)(uwDataTemp >> 8);
  8410. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  8411. }
  8412. catch (Exception)
  8413. {
  8414. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8415. }
  8416. }
  8417. private void button_MOS_Read_Click(object sender, EventArgs e)
  8418. {
  8419. foreach (Control c in groupBox21.Controls)
  8420. {
  8421. if (c is TextBox)
  8422. c.Text = "";
  8423. }
  8424. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8425. }
  8426. private void button_MOS_Write_Click(object sender, EventArgs e)
  8427. {
  8428. try
  8429. {
  8430. var Code = new byte[34];
  8431. for (int i = 0; i < 34; i++)
  8432. Code[i] = 0;
  8433. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8434. ushort uwDataTemp = 0;
  8435. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  8436. Code[2] = (byte)(uwDataTemp & 0xFF);
  8437. Code[3] = (byte)(uwDataTemp >> 8);
  8438. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  8439. Code[4] = (byte)(uwDataTemp & 0xFF);
  8440. Code[5] = (byte)(uwDataTemp >> 8);
  8441. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  8442. Code[6] = (byte)(uwDataTemp & 0xFF);
  8443. Code[7] = (byte)(uwDataTemp >> 8);
  8444. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8445. Code[8] = (byte)(uwDataTemp & 0xFF);
  8446. Code[9] = (byte)(uwDataTemp >> 8);
  8447. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8448. Code[10] = (byte)(uwDataTemp & 0xFF);
  8449. Code[11] = (byte)(uwDataTemp >> 8);
  8450. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8451. Code[12] = (byte)(uwDataTemp & 0xFF);
  8452. Code[13] = (byte)(uwDataTemp >> 8);
  8453. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8454. Code[14] = (byte)(uwDataTemp & 0xFF);
  8455. Code[15] = (byte)(uwDataTemp >> 8);
  8456. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8457. Code[16] = (byte)(uwDataTemp & 0xFF);
  8458. Code[17] = (byte)(uwDataTemp >> 8);
  8459. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  8460. }
  8461. catch (Exception)
  8462. {
  8463. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8464. }
  8465. }
  8466. /// <summary>
  8467. /// 测试模式点击文本框自动全选
  8468. /// </summary>
  8469. /// <param name="sender"></param>
  8470. /// <param name="e"></param>
  8471. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  8472. {
  8473. textBox_FacModeScan.SelectAll();
  8474. }
  8475. /// <summary>
  8476. /// 检验模式点击文本框自动全选
  8477. /// </summary>
  8478. /// <param name="sender"></param>
  8479. /// <param name="e"></param>
  8480. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  8481. {
  8482. textBox_CheckModeScan.SelectAll();
  8483. }
  8484. /// <summary>
  8485. /// 鼠标放置显示连接服务器信息
  8486. /// </summary>
  8487. /// <param name="sender"></param>
  8488. /// <param name="e"></param>
  8489. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  8490. {
  8491. // 创建the ToolTip
  8492. ToolTip toolTip1 = new ToolTip();
  8493. // 设置显示样式
  8494. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  8495. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  8496. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  8497. toolTip1.ShowAlways = true;//是否显示提示框
  8498. if (myFtp.IsNetConnected)
  8499. {
  8500. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + toolStripTextBox_ServerIP.Text);//设置故障内容显示
  8501. }
  8502. else
  8503. {
  8504. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  8505. }
  8506. }
  8507. /// <summary>
  8508. /// UART协议类型修改
  8509. /// </summary>
  8510. /// <param name="sender"></param>
  8511. /// <param name="e"></param>
  8512. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  8513. {
  8514. var Code = new byte[2];
  8515. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  8516. Code[1] = 0x00;
  8517. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8518. }
  8519. /// <summary>
  8520. /// 显示本机信息
  8521. /// </summary>
  8522. /// <param name="sender"></param>
  8523. /// <param name="e"></param>
  8524. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  8525. {
  8526. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  8527. }
  8528. /// <summary>
  8529. /// 量产模式删除当前选中文件
  8530. /// </summary>
  8531. /// <param name="sender"></param>
  8532. /// <param name="e"></param>
  8533. private void label112_DoubleClick(object sender, EventArgs e)
  8534. {
  8535. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8536. {
  8537. EnterForm1.ShowDialog();
  8538. try
  8539. {
  8540. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8541. {
  8542. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8543. {
  8544. try
  8545. {
  8546. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  8547. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  8548. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  8549. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8550. }
  8551. catch (Exception)
  8552. {
  8553. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8554. }
  8555. }
  8556. else
  8557. {
  8558. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8559. }
  8560. }
  8561. }
  8562. catch (Exception)
  8563. {
  8564. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8565. }
  8566. }
  8567. }
  8568. /// <summary>
  8569. /// 检验模式删除当前选中文件
  8570. /// </summary>
  8571. /// <param name="sender"></param>
  8572. /// <param name="e"></param>
  8573. private void label138_DoubleClick(object sender, EventArgs e)
  8574. {
  8575. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8576. {
  8577. EnterForm1.ShowDialog();
  8578. try
  8579. {
  8580. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8581. {
  8582. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8583. {
  8584. try
  8585. {
  8586. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  8587. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  8588. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  8589. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8590. }
  8591. catch (Exception)
  8592. {
  8593. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8594. }
  8595. }
  8596. else
  8597. {
  8598. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8599. }
  8600. }
  8601. }
  8602. catch (Exception)
  8603. {
  8604. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8605. }
  8606. }
  8607. }
  8608. /// <summary>
  8609. /// 读取整车信息2
  8610. /// </summary>
  8611. /// <param name="sender"></param>
  8612. /// <param name="e"></param>
  8613. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  8614. {
  8615. richTextBox_BikeParam2.Clear();
  8616. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  8617. }
  8618. /// <summary>
  8619. /// 写入整车信息2
  8620. /// </summary>
  8621. /// <param name="sender"></param>
  8622. /// <param name="e"></param>
  8623. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  8624. {
  8625. var ConfigParam = new byte[34];
  8626. for (int i = 0; i < 34; i++)
  8627. ConfigParam[i] = 0;
  8628. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8629. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8630. try
  8631. {
  8632. for (int i = 0; i < strDataTemp.Length; i++)
  8633. {
  8634. short wDataTemp = 0;
  8635. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8636. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8637. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  8638. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  8639. }
  8640. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  8641. }
  8642. catch (Exception)
  8643. {
  8644. timer_1s.Enabled = false;
  8645. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8646. timer_1s.Enabled = true;
  8647. }
  8648. }
  8649. /// <summary>
  8650. /// 读取用户骑行参数
  8651. /// </summary>
  8652. /// <param name="sender"></param>
  8653. /// <param name="e"></param>
  8654. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  8655. {
  8656. richTextBox_UsrRidesParam.Clear();
  8657. if (checkBox_UserRideParam_OBC.Checked)
  8658. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  8659. else
  8660. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  8661. }
  8662. /// <summary>
  8663. /// 写入用户骑行参数
  8664. /// </summary>
  8665. /// <param name="sender"></param>
  8666. /// <param name="e"></param>
  8667. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  8668. {
  8669. var ConfigParam = new byte[34];
  8670. for (int i = 0; i < 34; i++)
  8671. ConfigParam[i] = 0;
  8672. if (checkBox_UserRideParam_OBC.Checked)
  8673. {
  8674. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8675. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8676. try
  8677. {
  8678. for (int i = 0; i < strDataTemp.Length; i++)
  8679. {
  8680. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  8681. }
  8682. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  8683. }
  8684. catch (Exception)
  8685. {
  8686. timer_1s.Enabled = false;
  8687. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8688. timer_1s.Enabled = true;
  8689. }
  8690. }
  8691. else
  8692. {
  8693. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8694. try
  8695. {
  8696. for (int i = 0; i < strDataTemp.Length; i++)
  8697. {
  8698. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  8699. }
  8700. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  8701. }
  8702. catch (Exception)
  8703. {
  8704. timer_1s.Enabled = false;
  8705. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8706. timer_1s.Enabled = true;
  8707. }
  8708. }
  8709. }
  8710. /// <summary>
  8711. /// 读取产品标签
  8712. /// </summary>
  8713. /// <param name="sender"></param>
  8714. /// <param name="e"></param>
  8715. private void button_ReadTag_Click(object sender, EventArgs e)
  8716. {
  8717. textBox_TagInfo.Text = "---";
  8718. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  8719. }
  8720. /// <summary>
  8721. /// 写入产品标签
  8722. /// </summary>
  8723. /// <param name="sender"></param>
  8724. /// <param name="e"></param>
  8725. private void button_WriteTag_Click(object sender, EventArgs e)
  8726. {
  8727. string User = textBox_TagInfo.Text;
  8728. var UserArray = new byte[32];
  8729. for (ushort i = 0; i < User.Length; i++)
  8730. {
  8731. UserArray[i] = (byte)User[i];
  8732. }
  8733. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  8734. }
  8735. /// <summary>
  8736. /// 上位机读取骑行历史
  8737. /// </summary>
  8738. /// <param name="sender"></param>
  8739. /// <param name="e"></param>
  8740. private void button_ReadRideLog_Click(object sender, EventArgs e)
  8741. {
  8742. textBox_ODO_KM.Text = "---";
  8743. textBox_ODO_TIME.Text = "---";
  8744. textBox_TRIP_KM.Text = "---";
  8745. textBox_TRIP_TIME.Text = "---";
  8746. textBox_OBC_TRIP_KM.Text = "";
  8747. textBox_OBC_TRIP_TIME.Text = "";
  8748. textBox_OBC_ODO_KM.Text = "";
  8749. textBox_OBC_ODO_TIME.Text = "";
  8750. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  8751. }
  8752. /// <summary>
  8753. /// 上位机写入骑行历史
  8754. /// </summary>
  8755. /// <param name="sender"></param>
  8756. /// <param name="e"></param>
  8757. private void button_WriteRideLog_Click(object sender, EventArgs e)
  8758. {
  8759. UInt32 Data;
  8760. var UserArray = new byte[16];
  8761. try
  8762. {
  8763. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  8764. UserArray[0] = (byte)(Data & 0xFF);
  8765. UserArray[1] = (byte)(Data >> 8);
  8766. UserArray[2] = (byte)(Data >> 16);
  8767. UserArray[3] = (byte)(Data >> 24);
  8768. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  8769. UserArray[4] = (byte)(Data & 0xFF);
  8770. UserArray[5] = (byte)(Data >> 8);
  8771. UserArray[6] = (byte)(Data >> 16);
  8772. UserArray[7] = (byte)(Data >> 24);
  8773. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  8774. UserArray[8] = (byte)(Data & 0xFF);
  8775. UserArray[9] = (byte)(Data >> 8);
  8776. UserArray[10] = (byte)(Data >> 16);
  8777. UserArray[11] = (byte)(Data >> 24);
  8778. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  8779. UserArray[12] = (byte)(Data & 0xFF);
  8780. UserArray[13] = (byte)(Data >> 8);
  8781. UserArray[14] = (byte)(Data >> 16);
  8782. UserArray[15] = (byte)(Data >> 24);
  8783. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  8784. }
  8785. catch (Exception ex)
  8786. {
  8787. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8788. }
  8789. }
  8790. /// <summary>
  8791. /// 获取删除配置文件日期列表
  8792. /// </summary>
  8793. /// <param name="sender"></param>
  8794. /// <param name="e"></param>
  8795. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  8796. {
  8797. string[] DateList = { "" };
  8798. //网络断开时直接退出
  8799. if (!myFtp.IsNetConnected)
  8800. return;
  8801. //从服务器更新日期列表
  8802. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  8803. toolStripTextBox_DelCfgFile.Items.Clear();
  8804. //日期列表加载,显示最近30条
  8805. if (DateList.Length > 30)
  8806. {
  8807. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  8808. toolStripTextBox_DelCfgFile.Items.Add("-----");
  8809. }
  8810. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  8811. {
  8812. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  8813. }
  8814. }
  8815. /// <summary>
  8816. /// 删除指定配置文件
  8817. /// </summary>
  8818. /// <param name="sender"></param>
  8819. /// <param name="e"></param>
  8820. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  8821. {
  8822. //提示输入文件名
  8823. Scan scan_form = new Scan();
  8824. scan_form.ShowDialog();
  8825. do
  8826. {
  8827. if (scan_form.textBox_Scan.Text == string.Empty)
  8828. {
  8829. timer_1s.Enabled = false;
  8830. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8831. timer_1s.Enabled = true;
  8832. break;
  8833. }
  8834. string DelFile = scan_form.textBox_Scan.Text;
  8835. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8836. {
  8837. EnterForm1.ShowDialog();
  8838. try
  8839. {
  8840. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8841. {
  8842. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8843. {
  8844. try
  8845. {
  8846. if (DelFile.Contains("."))
  8847. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  8848. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  8849. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  8850. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  8851. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8852. }
  8853. catch (Exception)
  8854. {
  8855. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8856. }
  8857. }
  8858. else
  8859. {
  8860. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8861. }
  8862. }
  8863. }
  8864. catch (Exception)
  8865. {
  8866. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8867. }
  8868. }
  8869. } while (false);
  8870. }
  8871. /// <summary>
  8872. /// 获取删除样机测试记录日期列表
  8873. /// </summary>
  8874. /// <param name="sender"></param>
  8875. /// <param name="e"></param>
  8876. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  8877. {
  8878. string[] DateList = { "" };
  8879. //网络断开时直接退出
  8880. if (!myFtp.IsNetConnected)
  8881. return;
  8882. //从服务器更新日期列表
  8883. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  8884. toolStripTextBox_DelLogFile.Items.Clear();
  8885. //日期列表加载,显示最近30天
  8886. if (DateList.Length > 30)
  8887. {
  8888. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  8889. toolStripTextBox_DelLogFile.Items.Add("-----");
  8890. }
  8891. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  8892. {
  8893. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  8894. }
  8895. }
  8896. /// <summary>
  8897. /// 删除指定的样机测试记录
  8898. /// </summary>
  8899. /// <param name="sender"></param>
  8900. /// <param name="e"></param>
  8901. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  8902. {
  8903. //提示输入文件名
  8904. Scan scan_form = new Scan();
  8905. scan_form.ShowDialog();
  8906. do
  8907. {
  8908. if (scan_form.textBox_Scan.Text == string.Empty)
  8909. {
  8910. timer_1s.Enabled = false;
  8911. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8912. timer_1s.Enabled = true;
  8913. break;
  8914. }
  8915. string DelFile = scan_form.textBox_Scan.Text;
  8916. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8917. {
  8918. EnterForm1.ShowDialog();
  8919. try
  8920. {
  8921. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8922. {
  8923. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8924. {
  8925. try
  8926. {
  8927. //删除指定目录下面所有文件和文件夹
  8928. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  8929. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  8930. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8931. }
  8932. catch (Exception)
  8933. {
  8934. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8935. }
  8936. }
  8937. else
  8938. {
  8939. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8940. }
  8941. }
  8942. }
  8943. catch (Exception)
  8944. {
  8945. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8946. }
  8947. }
  8948. } while (false);
  8949. }
  8950. /// <summary>
  8951. /// CAN协议选择
  8952. /// </summary>
  8953. /// <param name="sender"></param>
  8954. /// <param name="e"></param>
  8955. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  8956. {
  8957. cANToolStripMenuItem.Checked= true;
  8958. uARTToolStripMenuItem.Checked = false;
  8959. UART协议ToolStripMenuItem.Visible = false;
  8960. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8961. }
  8962. /// <summary>
  8963. /// UART协议选择
  8964. /// </summary>
  8965. /// <param name="sender"></param>
  8966. /// <param name="e"></param>
  8967. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  8968. {
  8969. cANToolStripMenuItem.Checked = false;
  8970. uARTToolStripMenuItem.Checked = true;
  8971. UART协议ToolStripMenuItem.Visible = true;
  8972. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8973. }
  8974. /// <summary>
  8975. /// 清除流水号
  8976. /// </summary>
  8977. /// <param name="sender"></param>
  8978. /// <param name="e"></param>
  8979. private void label131_DoubleClick(object sender, EventArgs e)
  8980. {
  8981. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8982. {
  8983. label_FacModeSerial.Text = "0";
  8984. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  8985. }
  8986. }
  8987. /// <summary>
  8988. /// 清除流水号
  8989. /// </summary>
  8990. /// <param name="sender"></param>
  8991. /// <param name="e"></param>
  8992. private void label135_DoubleClick(object sender, EventArgs e)
  8993. {
  8994. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8995. {
  8996. label_CheckModeSerial.Text = "0";
  8997. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  8998. }
  8999. }
  9000. /// <summary>
  9001. /// 打开自动更新
  9002. /// </summary>
  9003. /// <param name="sender"></param>
  9004. /// <param name="e"></param>
  9005. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9006. {
  9007. 打开ToolStripMenuItem.Checked = true;
  9008. 关闭ToolStripMenuItem.Checked = false;
  9009. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9010. }
  9011. /// <summary>
  9012. /// 关闭自动更新
  9013. /// </summary>
  9014. /// <param name="sender"></param>
  9015. /// <param name="e"></param>
  9016. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9017. {
  9018. 打开ToolStripMenuItem.Checked = false;
  9019. 关闭ToolStripMenuItem.Checked = true;
  9020. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9021. }
  9022. /// <summary>
  9023. /// 显示完整配置文件
  9024. /// </summary>
  9025. /// <param name="sender"></param>
  9026. /// <param name="e"></param>
  9027. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9028. {
  9029. // 创建the ToolTip
  9030. ToolTip toolTip1 = new ToolTip();
  9031. // 设置显示样式
  9032. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9033. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9034. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9035. toolTip1.ShowAlways = true;//是否显示提示框
  9036. // 设置伴随的对象.
  9037. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9038. }
  9039. /// <summary>
  9040. /// 显示完整配置文件
  9041. /// </summary>
  9042. /// <param name="sender"></param>
  9043. /// <param name="e"></param>
  9044. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9045. {
  9046. // 创建the ToolTip
  9047. ToolTip toolTip1 = new ToolTip();
  9048. // 设置显示样式
  9049. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9050. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9051. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9052. toolTip1.ShowAlways = true;//是否显示提示框
  9053. // 设置伴随的对象.
  9054. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9055. }
  9056. /// <summary>
  9057. /// 手动发送指令
  9058. /// </summary>
  9059. /// <param name="sender"></param>
  9060. /// <param name="e"></param>
  9061. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9062. {
  9063. //提示
  9064. MessageBoxTimeOut.Show("按照16进制填写,相邻字节用空格隔开\r\n依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9065. Scan scan_form = new Scan();
  9066. scan_form.ShowDialog();
  9067. //发送写入的指令,填写ID、类型、命令字、数据
  9068. do
  9069. {
  9070. if (scan_form.textBox_Scan.Text == string.Empty)
  9071. {
  9072. timer_1s.Enabled = false;
  9073. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9074. timer_1s.Enabled = true;
  9075. break;
  9076. }
  9077. //输入文本转换为字节流
  9078. var InputData = new byte[256];
  9079. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9080. //ID
  9081. ushort ID;
  9082. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9083. //Mode
  9084. byte Mode;
  9085. Mode = InputData[2];
  9086. //Cmd
  9087. ushort Cmd;
  9088. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9089. //Data
  9090. var Data = new byte[Cmd & 0x00FF];
  9091. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9092. Data[i] = InputData[5 + i];
  9093. //发送数据
  9094. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9095. } while (false);
  9096. }
  9097. /// <summary>
  9098. /// 打开或关闭指令窗口
  9099. /// </summary>
  9100. /// <param name="sender"></param>
  9101. /// <param name="e"></param>
  9102. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  9103. {
  9104. if (指令调试ToolStripMenuItem.Checked == false)
  9105. {
  9106. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  9107. {
  9108. DebugForm.debug1 = new DebugForm();
  9109. DebugForm.debug1.Show();
  9110. this.DebugWindowIsOpen = true;
  9111. }
  9112. else
  9113. {
  9114. DebugForm.debug1.Activate();
  9115. this.DebugWindowIsOpen = true;
  9116. }
  9117. 指令调试ToolStripMenuItem.Checked = true;
  9118. }
  9119. else
  9120. {
  9121. if (this.DebugWindowIsOpen == true)
  9122. {
  9123. DebugForm.debug1.Close();
  9124. this.DebugWindowIsOpen = false;
  9125. this.DebugDataDisplayEnable = false;
  9126. }
  9127. 指令调试ToolStripMenuItem.Checked = false;
  9128. }
  9129. }
  9130. }
  9131. }