mainForm.cs 354 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805
  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.RegularExpressions;
  14. using System.Threading;
  15. using System.Web;
  16. using System.Windows.Forms;
  17. using System.Xml.Linq;
  18. //using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  19. namespace Welling_Motor_Debug_Tool
  20. {
  21. public partial class mainForm : Form
  22. {
  23. #region 变量定义
  24. //版本号
  25. public static string Version = "2.1.7";
  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. #endregion
  75. #region 故障日志结构体定义
  76. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  77. [StructLayout(LayoutKind.Sequential)]
  78. public struct MC_ErrorLogSaveInfo_Struct_t
  79. {
  80. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  81. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  82. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  83. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  84. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  85. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  86. //电机运行信息,占用空间32bytes
  87. [StructLayout(LayoutKind.Sequential)]
  88. public struct MC_RunInfo_Struct_t
  89. {
  90. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  91. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  92. public ushort Power; //电功率 1W,地址偏移4
  93. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  94. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  95. public byte Cadence; //踏频 1rpm,地址偏移10
  96. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  97. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  98. public byte GearSt; //助力档位,地址偏移13
  99. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  100. public byte SOC; //剩余电量 1%,地址偏移15
  101. public ushort RemainDistance; //续航里程 1km,地址偏移16
  102. public ushort Torque_AD; //力矩寄存器,地址偏移18
  103. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  104. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  105. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  106. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  107. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  108. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  109. public UInt32 RS; //预留 4bytes
  110. };
  111. [MarshalAs(UnmanagedType.Struct)]
  112. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  113. //控制变量
  114. public Int16 IqCurrent; //Pu, 地址偏移 48
  115. public Int16 IqVoltage; //Pu, 地址偏移 50
  116. public Int16 IdCurrent; //Pu, 地址偏移 52
  117. public Int16 IdVoltage; //Pu, 地址偏移 54
  118. //状态机
  119. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  120. //预留
  121. public UInt16 RS1;
  122. public UInt16 RS2;
  123. public UInt16 RS3;
  124. };
  125. #endregion
  126. #region 屏幕缩放比例获取
  127. public class PrimaryScreen
  128. {
  129. #region Win32 API
  130. [DllImport("user32.dll")]
  131. static extern IntPtr GetDC(IntPtr ptr);
  132. [DllImport("gdi32.dll")]
  133. static extern int GetDeviceCaps(
  134. IntPtr hdc, // handle to DC
  135. int nIndex // index of capability
  136. );
  137. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  138. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  139. #endregion
  140. #region DeviceCaps常量
  141. const int HORZRES = 8;
  142. const int VERTRES = 10;
  143. const int LOGPIXELSX = 88;
  144. const int LOGPIXELSY = 90;
  145. const int DESKTOPVERTRES = 117;
  146. const int DESKTOPHORZRES = 118;
  147. #endregion
  148. #region 属性
  149. /// <summary>
  150. /// 获取屏幕分辨率当前物理大小
  151. /// </summary>
  152. public static Size WorkingArea
  153. {
  154. get
  155. {
  156. IntPtr hdc = GetDC(IntPtr.Zero);
  157. Size size = new Size();
  158. size.Width = GetDeviceCaps(hdc, HORZRES);
  159. size.Height = GetDeviceCaps(hdc, VERTRES);
  160. ReleaseDC(IntPtr.Zero, hdc);
  161. return size;
  162. }
  163. }
  164. /// <summary>
  165. /// 当前系统DPI_X 大小 一般为96
  166. /// </summary>
  167. public static int DpiX
  168. {
  169. get
  170. {
  171. IntPtr hdc = GetDC(IntPtr.Zero);
  172. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  173. ReleaseDC(IntPtr.Zero, hdc);
  174. return DpiX;
  175. }
  176. }
  177. /// <summary>
  178. /// 当前系统DPI_Y 大小 一般为96
  179. /// </summary>
  180. public static int DpiY
  181. {
  182. get
  183. {
  184. IntPtr hdc = GetDC(IntPtr.Zero);
  185. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  186. ReleaseDC(IntPtr.Zero, hdc);
  187. return DpiX;
  188. }
  189. }
  190. /// <summary>
  191. /// 获取真实设置的桌面分辨率大小
  192. /// </summary>
  193. public static Size DESKTOP
  194. {
  195. get
  196. {
  197. IntPtr hdc = GetDC(IntPtr.Zero);
  198. Size size = new Size();
  199. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  200. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  201. ReleaseDC(IntPtr.Zero, hdc);
  202. return size;
  203. }
  204. }
  205. /// <summary>
  206. /// 获取宽度缩放百分比
  207. /// </summary>
  208. public static float ScaleX
  209. {
  210. get
  211. {
  212. IntPtr hdc = GetDC(IntPtr.Zero);
  213. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  214. int d = GetDeviceCaps(hdc, HORZRES);
  215. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  216. ReleaseDC(IntPtr.Zero, hdc);
  217. return ScaleX;
  218. }
  219. }
  220. /// <summary>
  221. /// 获取高度缩放百分比
  222. /// </summary>
  223. public static float ScaleY
  224. {
  225. get
  226. {
  227. IntPtr hdc = GetDC(IntPtr.Zero);
  228. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  229. ReleaseDC(IntPtr.Zero, hdc);
  230. return ScaleY;
  231. }
  232. }
  233. #endregion
  234. }
  235. #endregion
  236. public mainForm()
  237. {
  238. InitializeComponent();
  239. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  240. stopwatch.Start();
  241. //端口初始化
  242. mySerialProcess.Init();
  243. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  244. //检查备忘录文件
  245. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  246. {
  247. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  248. }
  249. //检查文件夹
  250. if (!Directory.Exists(localInfo.LocalPath))
  251. {
  252. Directory.CreateDirectory(localInfo.LocalPath);
  253. }
  254. if (!Directory.Exists(localInfo.LocalDataPath))
  255. {
  256. Directory.CreateDirectory(localInfo.LocalDataPath);
  257. }
  258. if (!Directory.Exists(localInfo.ToolsPath))
  259. {
  260. Directory.CreateDirectory(localInfo.ToolsPath);
  261. }
  262. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  263. {
  264. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  265. }
  266. //检查配置文件
  267. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  268. {
  269. //打开文件
  270. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  271. string sLine = "";
  272. ArrayList array_CfgInfo = new ArrayList();
  273. array_CfgInfo.Clear();
  274. while (sLine != null)
  275. {
  276. sLine = objReader.ReadLine();
  277. array_CfgInfo.Add(sLine);
  278. }
  279. objReader.Close();
  280. //解析配置文件
  281. try
  282. {
  283. //Port Set
  284. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  285. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  286. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  287. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  288. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  289. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  290. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  291. //Option
  292. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  293. 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
  294. 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
  295. if (array_CfgInfo[9].ToString().Split(':')[1] == "False")
  296. {
  297. checkBox_OffLineFacMode.Checked = false;
  298. checkBox_OffLineFacMode.Enabled = false;
  299. checkBox_OffLineCheckMode.Checked = false;
  300. checkBox_OffLineCheckMode.Enabled = false;
  301. }
  302. else
  303. {
  304. checkBox_OffLineFacMode.Checked = true;
  305. checkBox_OffLineFacMode.Enabled = true;
  306. checkBox_OffLineCheckMode.Checked = true;
  307. checkBox_OffLineCheckMode.Enabled = true;
  308. }
  309. //Server Set
  310. toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
  311. toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
  312. toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
  313. toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
  314. toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
  315. //MacInfo
  316. toolStripTextBox_MAC.Text = array_CfgInfo[19].ToString().Split(':')[1];
  317. toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
  318. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  319. toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
  320. //Log Address
  321. textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
  322. textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
  323. //电机类型
  324. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[29].ToString().Split(':')[1] == "True");
  325. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  326. //检测阈值
  327. toolStripTextBox_ThVol.Text = array_CfgInfo[33].ToString().Split(':')[1];
  328. toolStripTextBox_ThCur.Text = array_CfgInfo[34].ToString().Split(':')[1];
  329. toolStripTextBox_ThSpeed.Text = array_CfgInfo[35].ToString().Split(':')[1];
  330. toolStripTextBox_ThTor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  331. toolStripTextBox_ThCad.Text = array_CfgInfo[37].ToString().Split(':')[1];
  332. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[38].ToString().Split(':')[1];
  333. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[39].ToString().Split(':')[1];
  334. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[40].ToString().Split(':')[1];
  335. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[41].ToString().Split(':')[1];
  336. }
  337. catch (System.Exception)
  338. {
  339. timer_1s.Enabled = false;
  340. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  341. timer_1s.Enabled = true;
  342. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  343. }
  344. }
  345. else //不存在配置文件,生成文件写入默认值
  346. {
  347. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  348. }
  349. //系统登录
  350. do
  351. {
  352. EnterForm1.ShowDialog();
  353. try
  354. {
  355. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  356. {
  357. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  358. {
  359. //隐藏设置项
  360. 其它配置项ToolStripMenuItem.Visible = false;
  361. 写入存储ToolStripMenuItem.Visible = false;
  362. 离线使用ToolStripMenuItem.Visible = false;
  363. 服务器配置ToolStripMenuItem.Visible = false;
  364. 判断阈值ToolStripMenuItem.Visible = false;
  365. 力矩传感器检验ToolStripMenuItem.Visible = false;
  366. //显示生产信息
  367. 生产信息ToolStripMenuItem.Visible = true;
  368. //显示电机类型,但不可编辑
  369. 电机类型ToolStripMenuItem.Visible = true;
  370. 中置电机ToolStripMenuItem.Enabled = false;
  371. 轮毂电机ToolStripMenuItem.Enabled = false;
  372. //隐藏研发调试界面
  373. tabPage_MotorParam.Parent = null;
  374. tabPage_BikeParam.Parent = null;
  375. tabPage_ControlParam.Parent = null;
  376. tabPage_SensorParam.Parent = null;
  377. tabPage_AssistParam.Parent = null;
  378. tabPage_DebugParam.Parent = null;
  379. tabPage_RecordInfo.Parent = null;
  380. tabPage_OtherInfo.Parent = null;
  381. tabPage_OBC.Parent = null;
  382. tabPage_RAMorFLASH.Parent = null;
  383. tabPage_FactoryMode.Parent = null;
  384. tabPage_DebugInfo.Parent = null;
  385. //显示运行信息
  386. tabPage_RunInfo.Parent = tabControl2;
  387. //根据电机类型修改生产信息和电机类型
  388. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  389. {
  390. 中置电机ToolStripMenuItem.Checked = true;
  391. 轮毂电机ToolStripMenuItem.Checked = false;
  392. toolStripTextBox_MACPD.Text = "MM_MC1";
  393. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  394. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  395. }
  396. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  397. {
  398. 中置电机ToolStripMenuItem.Checked = false;
  399. 轮毂电机ToolStripMenuItem.Checked = true;
  400. toolStripTextBox_MACPD.Text = "GF_250_1";
  401. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  402. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  403. }
  404. //显示对应生产测试界面
  405. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  406. {
  407. tabPage_ProductMode_Write.Parent = tabControl1;
  408. tabPage_ProductMode_Write.Select();
  409. tabPage_ProductMode_Read.Parent = null;
  410. }
  411. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  412. {
  413. tabPage_ProductMode_Read.Parent = tabControl1;
  414. tabPage_ProductMode_Read.Select();
  415. tabPage_ProductMode_Write.Parent = null;
  416. }
  417. //应答指令不提示
  418. ACK_DisFlag = false;
  419. //退出登录
  420. break;
  421. }
  422. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  423. {
  424. //隐藏工作台内容,新建窗口完成配置
  425. groupBox1.Visible = false;
  426. groupBox3.Visible = false;
  427. tabControl2.Visible = false;
  428. //隐藏提示信息
  429. label_StarInfo.Visible = false;
  430. //打开参数配置框
  431. //MessageBox.Show("开发中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  432. GenerateParamsForm.ShowDialog();
  433. System.Environment.Exit(0);
  434. //退出登录
  435. break;
  436. }
  437. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  438. {
  439. //隐藏量产界面
  440. tabPage_ProductMode_Read.Parent = null;
  441. tabPage_ProductMode_Write.Parent = null;
  442. //隐藏配置项
  443. 其它配置项ToolStripMenuItem.Visible = false;
  444. 离线使用ToolStripMenuItem.Visible = false;
  445. 服务器配置ToolStripMenuItem.Visible = false;
  446. 判断阈值ToolStripMenuItem.Visible = false;
  447. 力矩传感器检验ToolStripMenuItem.Visible = false;
  448. //显示生产信息
  449. 生产信息ToolStripMenuItem.Visible = true;
  450. //显示电机类型,但不可编辑
  451. 电机类型ToolStripMenuItem.Visible = true;
  452. 中置电机ToolStripMenuItem.Enabled = true;
  453. 轮毂电机ToolStripMenuItem.Enabled = true;
  454. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  455. {
  456. 中置电机ToolStripMenuItem.Checked = true;
  457. 轮毂电机ToolStripMenuItem.Checked = false;
  458. toolStripTextBox_MACPD.Text = "MM_MC1";
  459. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  460. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  461. }
  462. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  463. {
  464. 中置电机ToolStripMenuItem.Checked = false;
  465. 轮毂电机ToolStripMenuItem.Checked = true;
  466. toolStripTextBox_MACPD.Text = "GF_250_1";
  467. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  468. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  469. }
  470. //退出登录
  471. break;
  472. }
  473. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  474. {
  475. //隐藏设置项
  476. 其它配置项ToolStripMenuItem.Visible = false;
  477. 写入存储ToolStripMenuItem.Visible = false;
  478. 离线使用ToolStripMenuItem.Visible = false;
  479. 服务器配置ToolStripMenuItem.Visible = false;
  480. 判断阈值ToolStripMenuItem.Visible = false;
  481. 力矩传感器检验ToolStripMenuItem.Visible = false;
  482. //显示生产信息
  483. 生产信息ToolStripMenuItem.Visible = true;
  484. //显示电机类型,但不可编辑
  485. 电机类型ToolStripMenuItem.Visible = true;
  486. 中置电机ToolStripMenuItem.Enabled = true;
  487. 轮毂电机ToolStripMenuItem.Enabled = true;
  488. //隐藏研发调试界面
  489. tabPage_MotorParam.Parent = null;
  490. tabPage_BikeParam.Parent = null;
  491. tabPage_ControlParam.Parent = null;
  492. tabPage_SensorParam.Parent = null;
  493. tabPage_AssistParam.Parent = null;
  494. tabPage_DebugParam.Parent = null;
  495. tabPage_RecordInfo.Parent = null;
  496. tabPage_OtherInfo.Parent = null;
  497. tabPage_OBC.Parent = null;
  498. tabPage_RAMorFLASH.Parent = null;
  499. tabPage_FactoryMode.Parent = null;
  500. tabPage_DebugInfo.Parent = null;
  501. //显示运行信息
  502. tabPage_RunInfo.Parent = tabControl2;
  503. //根据电机类型修改生产信息和电机类型
  504. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  505. {
  506. 中置电机ToolStripMenuItem.Checked = true;
  507. 轮毂电机ToolStripMenuItem.Checked = false;
  508. toolStripTextBox_MACPD.Text = "MM_MC1";
  509. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  510. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  511. }
  512. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  513. {
  514. 中置电机ToolStripMenuItem.Checked = false;
  515. 轮毂电机ToolStripMenuItem.Checked = true;
  516. toolStripTextBox_MACPD.Text = "GF_250_1";
  517. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  518. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  519. }
  520. //显示量产测试界面
  521. tabPage_ProductMode_Write.Parent = tabControl1;
  522. tabPage_ProductMode_Write.Select();
  523. tabPage_ProductMode_Read.Parent = null;
  524. //允许离线使用
  525. 允许ToolStripMenuItem.Checked = true;
  526. 不允许ToolStripMenuItem.Checked = false;
  527. checkBox_OffLineFacMode.Checked = true;
  528. checkBox_OffLineFacMode.Enabled = true;
  529. checkBox_OffLineCheckMode.Checked = true;
  530. checkBox_OffLineCheckMode.Enabled = true;
  531. //应答指令不提示
  532. ACK_DisFlag = false;
  533. //退出登录
  534. break;
  535. }
  536. else if (EnterForm1.comboBox_User.Text == "研发调试")
  537. {
  538. //隐藏量产界面
  539. tabPage_ProductMode_Read.Parent = null;
  540. tabPage_ProductMode_Write.Parent = null;
  541. 判断阈值ToolStripMenuItem.Visible = false;
  542. 力矩传感器检验ToolStripMenuItem.Visible = false;
  543. 服务器配置ToolStripMenuItem.Visible = false;
  544. //退出登录
  545. break;
  546. }
  547. else if (EnterForm1.comboBox_User.Text == "管理员")
  548. {
  549. //不隐藏任何界面
  550. //...
  551. //退出登录
  552. break;
  553. }
  554. else
  555. {
  556. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  557. //重新登录
  558. continue;
  559. }
  560. }
  561. else
  562. {
  563. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  564. //重新登录
  565. continue;
  566. }
  567. }
  568. catch (Exception)
  569. {
  570. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  571. System.Environment.Exit(0);
  572. }
  573. } while (true);
  574. //端口自动连接
  575. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  576. {
  577. try
  578. {
  579. PortConnect();
  580. }
  581. catch (System.Exception)
  582. {
  583. timer_1s.Enabled = false;
  584. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  585. timer_1s.Enabled = true;
  586. }
  587. }
  588. //配置网络FTP服务器
  589. myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text);
  590. //创建线程,定时检测网络连接状态
  591. Thread th = new Thread(NetworkCheck);
  592. th.IsBackground = true;
  593. th.Start();
  594. }
  595. /// <summary>
  596. /// 检查网络状态线程
  597. /// </summary>
  598. private void NetworkCheck()
  599. {
  600. //允许离线使用,直接退出
  601. if (允许ToolStripMenuItem.Checked == true) //允许离线使用
  602. {
  603. timer_1s.Enabled = false;
  604. MessageBox.Show("离线使用,不检测网络状态!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  605. timer_1s.Enabled = true;
  606. return;
  607. }
  608. //不允许离线使用,实时监测网络状态
  609. else
  610. {
  611. //初始化第一次连接FTP服务器
  612. bool Result = myFtp.CheckFtp();
  613. if (Result == true)//服务器连接成功
  614. {
  615. myFtp.IsNetConnected = true;
  616. }
  617. else//服务器连接失败
  618. {
  619. myFtp.IsNetConnected = false;
  620. if ((EnterForm1.comboBox_User.Text != "管理员") && (EnterForm1.comboBox_User.Text != "FCT治具测试"))
  621. {
  622. timer_1s.Enabled = false;
  623. MessageBox.Show("网络断开,将自动关闭!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  624. timer_1s.Enabled = true;
  625. this.Close();
  626. }
  627. }
  628. //创建定时器,定时30s检查网络
  629. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  630. timer_CheckNet.Enabled = true;
  631. timer_CheckNet.Interval = 10000;
  632. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  633. timer_CheckNet.Start();
  634. while (true)
  635. {
  636. Thread.Sleep(1);
  637. if (myFtp.IsNetConnected == false)
  638. {
  639. label_Server_ComStatus.Text = "网络已断开";
  640. label_ServerStatus.BackColor = Color.Red;
  641. }
  642. else
  643. {
  644. label_Server_ComStatus.Text = "网络已连接";
  645. label_ServerStatus.BackColor = Color.Green;
  646. }
  647. }
  648. }
  649. }
  650. /// <summary>
  651. /// 线程中定时任务,检查网络状态
  652. /// </summary>
  653. /// <param name="sender"></param>
  654. /// <param name="e"></param>
  655. private void timer_CheckNet_Tick(object sender, EventArgs e)
  656. {
  657. //连接FTP服务器
  658. bool Result = myFtp.CheckFtp();
  659. if (Result == true)//服务器连接成功
  660. {
  661. myFtp.IsNetConnected = true;
  662. //允许使用
  663. groupBox1.Enabled = true;
  664. groupBox3.Enabled = true;
  665. tabControl2.Enabled = true;
  666. }
  667. else//服务器连接失败
  668. {
  669. myFtp.IsNetConnected = false;
  670. if ((EnterForm1.comboBox_User.Text != "管理员") && (EnterForm1.comboBox_User.Text != "FCT治具测试"))
  671. {
  672. timer_1s.Enabled = false;
  673. MessageBox.Show("网络断开, 请检查网络!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  674. timer_1s.Enabled = true;
  675. //禁止使用
  676. groupBox1.Enabled = false;
  677. groupBox3.Enabled = false;
  678. tabControl2.Enabled = false;
  679. }
  680. }
  681. }
  682. #region 非独占性延时函数
  683. public static void Delay_ms(int milliSecond)
  684. {
  685. int start = Environment.TickCount;
  686. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  687. {
  688. Application.DoEvents();
  689. }
  690. }
  691. #endregion
  692. private void MainForm_Load(object sender, System.EventArgs e)
  693. {
  694. //页面初始化
  695. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  696. label_Computername.Text = "用户名:" + System.Environment.UserName;
  697. this.Text += Version;
  698. //下拉控件初始值设定
  699. comboBox_WorkMode.SelectedIndex = 0;
  700. comboBox_GearSt.SelectedIndex = 0;
  701. comboBox_LightSwitch.SelectedIndex = 1;
  702. comboBox_OBC_SetGearST.SelectedIndex = 0;
  703. comboBox_OBC_LightSw.SelectedIndex = 1;
  704. comboBox_AssistTorque.SelectedIndex = 0;
  705. comboBox_AssistCadence.SelectedIndex = 0;
  706. //combobox事件定义
  707. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  708. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  709. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  710. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  711. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  712. //创建线程,定时解析数据
  713. Thread th = new Thread(Task_SerialProcess);
  714. th.IsBackground = true;
  715. th.Start();
  716. }
  717. #region 结构体与字节流相互转换
  718. public static class MyConverter
  719. {
  720. /// <summary>
  721. /// 由结构体转换为byte数组
  722. /// </summary>
  723. public static byte[] StructureToByte<T>(T structure)
  724. {
  725. int size = Marshal.SizeOf(typeof(T));
  726. byte[] buffer = new byte[size];
  727. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  728. try
  729. {
  730. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  731. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  732. }
  733. finally
  734. {
  735. Marshal.FreeHGlobal(bufferIntPtr);
  736. }
  737. return buffer;
  738. }
  739. /// <summary>
  740. /// 由byte数组转换为结构体
  741. /// </summary>
  742. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  743. {
  744. object structure = null;
  745. int size = Marshal.SizeOf(typeof(T));
  746. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  747. try
  748. {
  749. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  750. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  751. }
  752. finally
  753. {
  754. Marshal.FreeHGlobal(allocIntPtr);
  755. }
  756. return (T)structure;
  757. }
  758. }
  759. #endregion
  760. #region 故障日志解析显示
  761. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  762. {
  763. string SaveData = "";
  764. //Log1
  765. if (Log1.Error_Index != 0xFFFF)
  766. {
  767. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  768. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  769. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  770. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  771. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  772. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  773. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  774. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  775. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  776. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  777. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  778. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  779. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  780. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  781. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  782. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  783. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  784. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  785. {
  786. SaveData += "续航:" + "---km" + ", ";
  787. }
  788. else
  789. {
  790. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  791. }
  792. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  793. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  794. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  795. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  796. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  797. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  798. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  799. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  800. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  801. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  802. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  803. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  804. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  805. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  806. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  807. SaveData += "\r\n\r\n";
  808. richTextBox_Record.AppendText(SaveData);
  809. SaveData = "";
  810. }
  811. //Log2
  812. if (Log2.Error_Index != 0xFFFF)
  813. {
  814. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  815. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  816. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  817. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  818. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  819. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  820. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  821. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  822. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  823. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  824. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  825. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  826. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  827. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  828. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  829. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  830. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  831. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  832. {
  833. SaveData += "续航:" + "---km" + ", ";
  834. }
  835. else
  836. {
  837. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  838. }
  839. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  840. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  841. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  842. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  843. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  844. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  845. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  846. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  847. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  848. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  849. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  850. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  851. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  852. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  853. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  854. SaveData += "\r\n\r\n";
  855. richTextBox_Record.AppendText(SaveData);
  856. SaveData = "";
  857. }
  858. }
  859. #endregion
  860. #region 串口数据解析线程
  861. /// <summary>
  862. /// 串口数据解析线程
  863. /// </summary>
  864. private void Task_SerialProcess()
  865. {
  866. //创建定时器,定时读取串口数据
  867. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  868. timer_ReadSerial.Enabled = true;
  869. timer_ReadSerial.Interval = 20;
  870. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  871. timer_ReadSerial.Start();
  872. while (true)
  873. {
  874. Thread.Sleep(1);
  875. };
  876. }
  877. /// <summary>
  878. /// 串口解析定时器
  879. /// </summary>
  880. /// <param name="sender"></param>
  881. /// <param name="e"></param>
  882. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  883. {
  884. //串口解析
  885. Serial_process(mySerialProcess.buffer);
  886. }
  887. #endregion
  888. #region 数据解析
  889. public void Serial_process(List<byte> buffer)
  890. {
  891. byte DataNum = 0; //记录每条命令数据段的长度
  892. ushort PackageID, Cmd;
  893. byte[] Data = new byte[1024];
  894. try
  895. {
  896. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  897. {
  898. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  899. {
  900. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  901. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  902. {
  903. int CmdLen = buffer[5];
  904. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  905. while (CmdLen > 0) //读取命令段
  906. {
  907. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  908. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  909. if (DataNum <= (CmdLen - 2))
  910. {
  911. for (int i = 0; i < DataNum; i++)
  912. {
  913. Data[i] = buffer[i + 8];
  914. }
  915. buffer.RemoveRange(0, CmdLen + 11);
  916. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  917. DataRevToString(Cmd, Data);//指令数据转为字符串
  918. }
  919. }
  920. }
  921. else
  922. {
  923. buffer.RemoveAt(0);//ID不对
  924. }
  925. }
  926. else
  927. {
  928. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  929. }
  930. }
  931. }
  932. catch (Exception)
  933. {
  934. }
  935. }
  936. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  937. {
  938. int DataTemp;
  939. ushort uData16;
  940. unchecked
  941. {
  942. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  943. }
  944. #region 解析发送给CDL的指令
  945. if (ID == 0x7FF)
  946. {
  947. switch (CmdTemp)
  948. {
  949. case 0x1100://
  950. {
  951. unchecked
  952. {
  953. this.Invoke((EventHandler)(delegate
  954. {
  955. //CDL连接成功
  956. mySerialProcess.CDL_Online_Flag = true;
  957. MessageBox.Show("连接成功!", "提示");
  958. groupBox1.Visible = true;
  959. groupBox3.Visible = true;
  960. tabControl2.Visible = true;
  961. label_StarInfo.Visible = false;
  962. }));
  963. }
  964. break;
  965. }
  966. default: break;
  967. }
  968. }
  969. #endregion
  970. #region 解析电机的命令
  971. else if ((ID == 0x715) || (ID == 0x710))
  972. {
  973. switch (CmdTemp)
  974. {
  975. case 0x1020://电机运行信息
  976. {
  977. unchecked
  978. {
  979. this.Invoke((EventHandler)(delegate
  980. {
  981. MC_RunInfo_Refresh = true;
  982. //车速
  983. DataTemp = (int)(Data[1] * 256 + Data[0]);
  984. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  985. //输出转速
  986. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  987. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  988. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  989. Class_MotorSpeed.Data = DataTemp;
  990. //电功率
  991. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  992. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  993. //母线电压
  994. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  995. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  996. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  997. //母线电流
  998. DataTemp = (short)(Data[9] * 256 + Data[8]);
  999. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1000. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1001. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1002. Class_CurrentData.Data = DataTemp;
  1003. //踏频
  1004. DataTemp = (ushort)(Data[10]);
  1005. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1006. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1007. Class_CadenceData.Data = DataTemp;
  1008. //踩踏力矩
  1009. DataTemp = (ushort)(Data[11]);
  1010. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1011. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1012. Class_TorqueData.Data = DataTemp;
  1013. //踩踏方向
  1014. DataTemp = (ushort)(Data[12]);
  1015. if (DataTemp == 0)
  1016. {
  1017. textBox_RunInfo_Dir.Text = "正向";
  1018. }
  1019. else if (DataTemp == 1)
  1020. {
  1021. textBox_RunInfo_Dir.Text = "反向";
  1022. }
  1023. else if (DataTemp == 2)
  1024. {
  1025. textBox_RunInfo_Dir.Text = "停止";
  1026. }
  1027. //助力档位
  1028. DataTemp = (ushort)(Data[13]);
  1029. if (DataTemp == 0x33)
  1030. {
  1031. textBox_RunInfo_GearSt.Text = "SMART";
  1032. //comboBox_GearSt.SelectedIndex = 5;
  1033. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1034. }
  1035. else if (DataTemp == 0x22)
  1036. {
  1037. textBox_RunInfo_GearSt.Text = "WALK";
  1038. //comboBox_GearSt.SelectedIndex = 6;
  1039. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1040. }
  1041. else
  1042. {
  1043. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1044. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1045. //comboBox_GearSt.SelectedIndex = DataTemp;
  1046. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1047. }
  1048. //大灯状态
  1049. DataTemp = (ushort)(Data[14]);
  1050. if (DataTemp == 0xF0)
  1051. {
  1052. textBox_RunInfo_LightSwitch.Text = "OFF";
  1053. //comboBox_LightSwitch.SelectedIndex = 1;
  1054. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1055. }
  1056. else if (DataTemp == 0xF1)
  1057. {
  1058. textBox_RunInfo_LightSwitch.Text = "ON";
  1059. //comboBox_LightSwitch.SelectedIndex = 0;
  1060. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1061. }
  1062. //剩余电量
  1063. DataTemp = (ushort)(Data[15]);
  1064. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1065. //剩余续航里程
  1066. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1067. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1068. {
  1069. textBox_RunInfo_Range.Text = "---";
  1070. }
  1071. else
  1072. {
  1073. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1074. }
  1075. //预留(显示力矩Reg),空2bytes
  1076. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1077. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1078. //平均功耗
  1079. DataTemp = (ushort)(Data[20]);
  1080. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1081. //PCB温度
  1082. DataTemp = (ushort)(Data[21]);
  1083. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1084. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1085. Class_MotorTemp.Data = DataTemp - 40;
  1086. //绕组温度
  1087. DataTemp = (ushort)(Data[22]);
  1088. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1089. //MCU温度
  1090. DataTemp = (ushort)(Data[23]);
  1091. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1092. //单次里程
  1093. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1094. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1095. //单次时间
  1096. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1097. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1098. //数据保存
  1099. RunInfoAutoSave();
  1100. }));
  1101. }
  1102. break;
  1103. }
  1104. case 0x1104://故障码
  1105. {
  1106. unchecked
  1107. {
  1108. this.Invoke((EventHandler)(delegate
  1109. {
  1110. MC_ErrorCode_Refresh = true;
  1111. textBox_ErrorCode.Text =
  1112. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1113. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1114. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1115. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1116. "H";
  1117. }));
  1118. }
  1119. break;
  1120. }
  1121. case 0xA903://反馈指令
  1122. {
  1123. unchecked
  1124. {
  1125. this.Invoke((EventHandler)(delegate
  1126. {
  1127. if (ACK_DisFlag == true)
  1128. {
  1129. timer_1s.Enabled = false;
  1130. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1131. timer_1s.Enabled = true;
  1132. //关机反馈
  1133. PowerOffAckStatus = true;
  1134. }
  1135. //应答标志置位
  1136. WriteACK = true;
  1137. WriteCnt++;
  1138. }));
  1139. }
  1140. break;
  1141. }
  1142. case 0xB226://马达参数
  1143. {
  1144. unchecked
  1145. {
  1146. this.Invoke((EventHandler)(delegate
  1147. {
  1148. richTextBox_MotorParam.Clear();
  1149. for (int i = 0; i < myParams.MotorParma.Count; i++)
  1150. {
  1151. if (i == 6)
  1152. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1153. else
  1154. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1155. }
  1156. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1157. }));
  1158. }
  1159. break;
  1160. }
  1161. case 0xB31A://整车信息
  1162. {
  1163. unchecked
  1164. {
  1165. this.Invoke((EventHandler)(delegate
  1166. {
  1167. richTextBox_BikeParam.Clear();
  1168. for (int i = 0; i < myParams.BikeParma.Count; i++)
  1169. {
  1170. if (i == 9)
  1171. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1172. else
  1173. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1174. //更新前后灯参数
  1175. if (i == 8)
  1176. {
  1177. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1178. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1179. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1180. }
  1181. //更新开关机参数
  1182. else if (i == 11)
  1183. {
  1184. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1185. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1186. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1187. }
  1188. }
  1189. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1190. }));
  1191. }
  1192. break;
  1193. }
  1194. case 0xB420://控制器参数
  1195. {
  1196. unchecked
  1197. {
  1198. this.Invoke((EventHandler)(delegate
  1199. {
  1200. richTextBox_ControlParam.Clear();
  1201. for (int i = 0; i < myParams.ControlParma.Count; i++)
  1202. {
  1203. richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1204. }
  1205. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1206. }));
  1207. }
  1208. break;
  1209. }
  1210. case 0xB528://传感器参数
  1211. {
  1212. unchecked
  1213. {
  1214. this.Invoke((EventHandler)(delegate
  1215. {
  1216. richTextBox_SensorParam.Clear();
  1217. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1218. {
  1219. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1220. }
  1221. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1222. //更新生产模式页面传感器零点和标定值
  1223. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1224. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1225. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1226. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1227. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1228. }));
  1229. }
  1230. break;
  1231. }
  1232. case 0xB64C://助力参数
  1233. {
  1234. unchecked
  1235. {
  1236. this.Invoke((EventHandler)(delegate
  1237. {
  1238. richTextBox_AssistParam.Clear();
  1239. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1240. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1241. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1242. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1243. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1244. {
  1245. if (i < index_1) //数据占用2bytes
  1246. {
  1247. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1248. }
  1249. else if (i <= index_2) //数据占用4bytes
  1250. {
  1251. 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])) + ", ");
  1252. }
  1253. else if (i < index_3) //数据占用2bytes,无符号
  1254. {
  1255. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1256. }
  1257. else if (i <= index_4) //数据占用2bytes,有符号
  1258. {
  1259. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1260. }
  1261. else //数据占用2bytes,无符号
  1262. {
  1263. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1264. }
  1265. }
  1266. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1267. }));
  1268. }
  1269. break;
  1270. }
  1271. case 0xB74C://历史记录
  1272. {
  1273. unchecked
  1274. {
  1275. this.Invoke((EventHandler)(delegate
  1276. {
  1277. richTextBox_Record.Clear();
  1278. for (int i = 0; i < myParams.Record.Count; i++)
  1279. {
  1280. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1281. }
  1282. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1283. }));
  1284. }
  1285. break;
  1286. }
  1287. case 0xB83A://调试参数
  1288. {
  1289. unchecked
  1290. {
  1291. this.Invoke((EventHandler)(delegate
  1292. {
  1293. richTextBox_DebugParam.Clear();
  1294. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1295. {
  1296. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1297. }
  1298. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1299. }));
  1300. }
  1301. break;
  1302. }
  1303. case 0xB904://存储标志
  1304. {
  1305. unchecked
  1306. {
  1307. this.Invoke((EventHandler)(delegate
  1308. {
  1309. ushort Flag = 0;
  1310. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1311. if (Flag == 0)
  1312. {
  1313. radioButton_EE_SaveNo.Checked = true;
  1314. radioButton_EE_SaveYes.Checked = false;
  1315. }
  1316. else
  1317. {
  1318. radioButton_EE_SaveNo.Checked = false;
  1319. radioButton_EE_SaveYes.Checked = true;
  1320. }
  1321. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1322. if (Flag == 0)
  1323. {
  1324. radioButton_SIP_SaveNo.Checked = true;
  1325. radioButton_SIP_SaveYes.Checked = false;
  1326. }
  1327. else
  1328. {
  1329. radioButton_SIP_SaveNo.Checked = false;
  1330. radioButton_SIP_SaveYes.Checked = true;
  1331. }
  1332. }));
  1333. }
  1334. break;
  1335. }
  1336. case 0x1240://电机版本信息
  1337. {
  1338. unchecked
  1339. {
  1340. this.Invoke((EventHandler)(delegate
  1341. {
  1342. //电机型号
  1343. textBox_Model.Text = "";
  1344. textBox_OBC_ReadModel.Text = "";
  1345. textBox_FacModeName.Text = "";
  1346. for (ushort i = 0; i < 16; i++)
  1347. {
  1348. if (Data[i] == 0x2E)
  1349. {
  1350. break;
  1351. }
  1352. textBox_Model.Text += ((char)Data[i]).ToString();
  1353. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1354. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1355. }
  1356. Class_Motor_Ver.Mode = textBox_Model.Text;
  1357. //电机SN
  1358. textBox_SN.Text = "";
  1359. textBox_OBC_ReadSN.Text = "";
  1360. textBox_FacModeNum.Text = "";
  1361. for (ushort i = 0; i < 16; i++)
  1362. {
  1363. if (Data[16 + i] == 0x2E)
  1364. {
  1365. break;
  1366. }
  1367. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1368. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1369. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1370. }
  1371. Class_Motor_Ver.SN = textBox_SN.Text;
  1372. //电机HW
  1373. textBox_HW.Text = "";
  1374. textBox_OBC_ReadHW.Text = "";
  1375. textBox_FacModeHW.Text = "";
  1376. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1377. {
  1378. if (Data[32 + i] == 0x2E)
  1379. {
  1380. break;
  1381. }
  1382. else if (Data[32 + i] == 'r')
  1383. {
  1384. Data[32 + i] = (byte)'.';
  1385. break;
  1386. }
  1387. string strTemp = "";
  1388. strTemp = ((char)Data[32 + i]).ToString();
  1389. textBox_HW.Text += strTemp;
  1390. textBox_OBC_ReadHW.Text += strTemp;
  1391. textBox_FacModeHW.Text += strTemp;
  1392. }
  1393. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1394. {
  1395. if (Data[40 + i] == 0x2E)
  1396. {
  1397. break;
  1398. }
  1399. else if (Data[40 + i] == 'r')
  1400. {
  1401. Data[40 + i] = (byte)'.';
  1402. break;
  1403. }
  1404. string strTemp = "";
  1405. strTemp = ((char)Data[40 + i]).ToString();
  1406. textBox_HW.Text += strTemp;
  1407. textBox_OBC_ReadHW.Text += strTemp;
  1408. textBox_FacModeHW.Text += strTemp;
  1409. }
  1410. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1411. {
  1412. string strTemp = "";
  1413. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1414. textBox_HW.Text += strTemp;
  1415. textBox_OBC_ReadHW.Text += strTemp;
  1416. textBox_FacModeHW.Text += strTemp;
  1417. }
  1418. Class_Motor_Ver.HW = textBox_HW.Text;
  1419. //电机FW
  1420. textBox_FW.Text = "";
  1421. textBox_OBC_ReadFW.Text = "";
  1422. textBox_FacModeFW.Text = "";
  1423. for (ushort i = 0; i < 16; i++)
  1424. {
  1425. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1426. {
  1427. break;
  1428. }
  1429. if (Data[48 + i] == 'r')
  1430. {
  1431. Data[48 + i] = (byte)'.';
  1432. }
  1433. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1434. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1435. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1436. }
  1437. Class_Motor_Ver.FW = textBox_FW.Text;
  1438. }));
  1439. }
  1440. break;
  1441. }
  1442. case 0xA610://自定义1
  1443. {
  1444. unchecked
  1445. {
  1446. this.Invoke((EventHandler)(delegate
  1447. {
  1448. textBox_User1.Text = "";
  1449. for (ushort i = 0; i < 16; i++)
  1450. {
  1451. if (Data[i] == 0x2E)
  1452. {
  1453. break;
  1454. }
  1455. textBox_User1.Text += ((char)Data[i]).ToString();
  1456. }
  1457. }));
  1458. }
  1459. break;
  1460. }
  1461. case 0xA710://自定义2
  1462. {
  1463. unchecked
  1464. {
  1465. this.Invoke((EventHandler)(delegate
  1466. {
  1467. textBox_User2.Text = "";
  1468. for (ushort i = 0; i < 16; i++)
  1469. {
  1470. if (Data[i] == 0x2E)
  1471. {
  1472. break;
  1473. }
  1474. textBox_User2.Text += ((char)Data[i]).ToString();
  1475. }
  1476. }));
  1477. }
  1478. break;
  1479. }
  1480. case 0xA810://自定义1
  1481. {
  1482. unchecked
  1483. {
  1484. this.Invoke((EventHandler)(delegate
  1485. {
  1486. textBox_User3.Text = "";
  1487. for (ushort i = 0; i < 16; i++)
  1488. {
  1489. if (Data[i] == 0x2E)
  1490. {
  1491. break;
  1492. }
  1493. textBox_User3.Text += ((char)Data[i]).ToString();
  1494. }
  1495. }));
  1496. }
  1497. break;
  1498. }
  1499. case 0xA520://生产信息
  1500. {
  1501. unchecked
  1502. {
  1503. this.Invoke((EventHandler)(delegate
  1504. {
  1505. //生产商
  1506. textBox_MAC.Text = "";
  1507. for (ushort i = 0; i < 8; i++)
  1508. {
  1509. if (Data[i] == 0x2E)
  1510. {
  1511. break;
  1512. }
  1513. textBox_MAC.Text += ((char)Data[i]).ToString();
  1514. }
  1515. //生产地
  1516. textBox_MACAdd.Text = "";
  1517. for (ushort i = 0; i < 8; i++)
  1518. {
  1519. if (Data[8 + i] == 0x2E)
  1520. {
  1521. break;
  1522. }
  1523. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1524. }
  1525. //生产日期
  1526. textBox_MACDate.Text = "";
  1527. for (ushort i = 0; i < 8; i++)
  1528. {
  1529. if (Data[16 + i] == 0x2E)
  1530. {
  1531. break;
  1532. }
  1533. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1534. }
  1535. //品牌信息
  1536. textBox_PP.Text = "";
  1537. for (ushort i = 0; i < 8; i++)
  1538. {
  1539. if (Data[24 + i] == 0x2E)
  1540. {
  1541. break;
  1542. }
  1543. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1544. }
  1545. }));
  1546. }
  1547. break;
  1548. }
  1549. case 0xA408://密钥
  1550. {
  1551. unchecked
  1552. {
  1553. this.Invoke((EventHandler)(delegate
  1554. {
  1555. textBox_Key.Text = "";
  1556. for (ushort i = 0; i < 8; i++)
  1557. {
  1558. textBox_Key.Text += ((char)Data[i]).ToString();
  1559. }
  1560. }));
  1561. }
  1562. break;
  1563. }
  1564. case 0xAB09://存储器数据
  1565. case 0xAB0A:
  1566. case 0xAB0B:
  1567. case 0xAB0C:
  1568. {
  1569. unchecked
  1570. {
  1571. this.Invoke((EventHandler)(delegate
  1572. {
  1573. long ByteNum = 0;
  1574. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1575. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1576. {
  1577. for (int i = 0; i < ByteNum; i++)
  1578. {
  1579. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1580. }
  1581. }
  1582. else //根据设置自动转换10进制显示
  1583. {
  1584. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1585. {
  1586. switch (ByteNum)
  1587. {
  1588. case 1:
  1589. {
  1590. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1591. break;
  1592. }
  1593. case 2:
  1594. {
  1595. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1596. break;
  1597. }
  1598. case 3:
  1599. {
  1600. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1601. break;
  1602. }
  1603. case 4:
  1604. {
  1605. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1606. break;
  1607. }
  1608. default:
  1609. {
  1610. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1611. break;
  1612. }
  1613. }
  1614. }
  1615. else //16进制显示
  1616. {
  1617. switch (ByteNum)
  1618. {
  1619. case 1:
  1620. {
  1621. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1622. break;
  1623. }
  1624. case 2:
  1625. {
  1626. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1627. break;
  1628. }
  1629. case 3:
  1630. {
  1631. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1632. break;
  1633. }
  1634. case 4:
  1635. {
  1636. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1637. break;
  1638. }
  1639. default:
  1640. {
  1641. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1642. break;
  1643. }
  1644. }
  1645. }
  1646. }
  1647. }));
  1648. }
  1649. break;
  1650. }
  1651. case 0xAB88://故障日志
  1652. {
  1653. unchecked
  1654. {
  1655. this.Invoke((EventHandler)(delegate
  1656. {
  1657. //电机存储的故障日志,一包128字节包含2条故障日志
  1658. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1659. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1660. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1661. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1662. //数据显示
  1663. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1664. }));
  1665. }
  1666. break;
  1667. }
  1668. case 0x1401://在线检测结果
  1669. {
  1670. unchecked
  1671. {
  1672. this.Invoke((EventHandler)(delegate
  1673. {
  1674. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1675. }));
  1676. }
  1677. break;
  1678. }
  1679. case 0x1510://骑行历史信息
  1680. {
  1681. unchecked
  1682. {
  1683. this.Invoke((EventHandler)(delegate
  1684. {
  1685. long DataTemp32;
  1686. //ODO里程
  1687. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1688. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1689. //ODO时间
  1690. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1691. if (DataTemp32 >= 60 * 100000)
  1692. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1693. else
  1694. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1695. //TRIP里程
  1696. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1697. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1698. //TRIP时间
  1699. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1700. if (DataTemp32 >= 60 * 100000)
  1701. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1702. else
  1703. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1704. }));
  1705. }
  1706. break;
  1707. }
  1708. case 0x1720://客户信息
  1709. {
  1710. unchecked
  1711. {
  1712. this.Invoke((EventHandler)(delegate
  1713. {
  1714. //软件标识
  1715. textBox_SP.Text = "";
  1716. textBox_OBC_ReadSP.Text = "";
  1717. textBox_FacModeSP.Text = "";
  1718. for (ushort i = 0; i < 23; i++)
  1719. {
  1720. if (Data[i] == 'r')
  1721. {
  1722. Data[i] = (byte)'.';
  1723. }
  1724. textBox_SP.Text += ((char)Data[i]).ToString();
  1725. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1726. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1727. }
  1728. //Git提交版本信息
  1729. textBox_FacModeGit.Text = "";
  1730. for (ushort i = 0; i < 9; i++)
  1731. {
  1732. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  1733. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  1734. }
  1735. Class_Motor_Ver.Special = textBox_SP.Text;
  1736. }));
  1737. }
  1738. break;
  1739. }
  1740. case 0xBA20: //调试信息
  1741. {
  1742. unchecked
  1743. {
  1744. this.Invoke((EventHandler)(delegate
  1745. {
  1746. MC_DebugInfo_Refresh = true;
  1747. //系统状态机
  1748. DataTemp = (short)(Data[0]);
  1749. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  1750. //二层状态机
  1751. DataTemp = (short)(Data[1]);
  1752. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  1753. //电机状态机
  1754. DataTemp = (short)(Data[2]);
  1755. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  1756. //助力状态机
  1757. DataTemp = (short)(Data[3]);
  1758. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  1759. //IdRef
  1760. DataTemp = (short)(Data[5] * 256 + Data[4]);
  1761. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  1762. //IqRef
  1763. DataTemp = (short)(Data[7] * 256 + Data[6]);
  1764. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  1765. //UdRef
  1766. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1767. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  1768. //UqRef
  1769. DataTemp = (short)(Data[11] * 256 + Data[10]);
  1770. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  1771. //瞬时力矩
  1772. DataTemp = (short)(Data[13] * 256 + Data[12]);
  1773. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  1774. //时间滤波力矩
  1775. DataTemp = (short)(Data[15] * 256 + Data[14]);
  1776. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  1777. //踏频滤波力矩
  1778. DataTemp = (short)(Data[17] * 256 + Data[16]);
  1779. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  1780. //IdFdb
  1781. DataTemp = (short)(Data[19] * 256 + Data[18]);
  1782. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  1783. //IqFdb
  1784. DataTemp = (short)(Data[21] * 256 + Data[20]);
  1785. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  1786. //助力输出
  1787. DataTemp = (short)(Data[23] * 256 + Data[22]);
  1788. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  1789. //数据保存
  1790. RunInfoAutoSave();
  1791. }));
  1792. }
  1793. break;
  1794. }
  1795. case 0xBC20: //内阻校正信息
  1796. {
  1797. unchecked
  1798. {
  1799. this.Invoke((EventHandler)(delegate
  1800. {
  1801. //内阻1
  1802. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1803. textBox_MOS_R1.Text = Convert.ToString(uData16);
  1804. //内阻2
  1805. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  1806. textBox_MOS_R2.Text = Convert.ToString(uData16);
  1807. //内阻3
  1808. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  1809. textBox_MOS_R3.Text = Convert.ToString(uData16);
  1810. //K1
  1811. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  1812. textBox_MOS_K1.Text = Convert.ToString(uData16);
  1813. //K2
  1814. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  1815. textBox_MOS_K2.Text = Convert.ToString(uData16);
  1816. //K3
  1817. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  1818. textBox_MOS_K3.Text = Convert.ToString(uData16);
  1819. //K4
  1820. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  1821. textBox_MOS_K4.Text = Convert.ToString(uData16);
  1822. //K5
  1823. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  1824. textBox_MOS_K5.Text = Convert.ToString(uData16);
  1825. }));
  1826. }
  1827. break;
  1828. }
  1829. case 0xC109: //Boot版本信息
  1830. {
  1831. BootInfo = "";
  1832. for (ushort i = 0; i < 9; i++)
  1833. {
  1834. BootInfo += ((char)Data[i]).ToString();
  1835. }
  1836. break;
  1837. }
  1838. default:
  1839. {
  1840. break;
  1841. }
  1842. }
  1843. }
  1844. #endregion
  1845. #region 解析BMS广播的命令
  1846. else if (ID == 0x720)
  1847. {
  1848. switch (CmdTemp)
  1849. {
  1850. case 0x1010://BMS运行信息
  1851. {
  1852. unchecked
  1853. {
  1854. this.Invoke((EventHandler)(delegate
  1855. {
  1856. BMS_RunInfo_Refresh = true;
  1857. richTextBox_OBC_BMS_RunInfo.Clear();
  1858. //电压
  1859. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1860. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  1861. //电流
  1862. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  1863. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  1864. //剩余容量
  1865. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  1866. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  1867. //满充容量
  1868. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  1869. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  1870. //电芯温度
  1871. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  1872. //剩余电量
  1873. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  1874. //电池状态
  1875. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  1876. //SOH
  1877. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  1878. //循环次数
  1879. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  1880. }));
  1881. }
  1882. break;
  1883. }
  1884. default: break;
  1885. }
  1886. }
  1887. #endregion
  1888. #region 解析电机发送OBC的命令
  1889. else if (ID == 0x713)
  1890. {
  1891. switch (CmdTemp)
  1892. {
  1893. case 0x5408://电机用户参数
  1894. {
  1895. unchecked
  1896. {
  1897. this.Invoke((EventHandler)(delegate
  1898. {
  1899. richTextBox_OBC_ReadUserInfo.Clear();
  1900. //默认周长
  1901. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  1902. //启动模式
  1903. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  1904. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  1905. //限速
  1906. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  1907. //周长微调
  1908. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  1909. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  1910. //助力方案
  1911. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  1912. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  1913. //关机时间
  1914. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  1915. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  1916. }));
  1917. }
  1918. break;
  1919. }
  1920. case 0x5303://电机应答反馈
  1921. {
  1922. unchecked
  1923. {
  1924. this.Invoke((EventHandler)(delegate
  1925. {
  1926. timer_1s.Enabled = false;
  1927. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1928. timer_1s.Enabled = true;
  1929. }));
  1930. }
  1931. break;
  1932. }
  1933. default: break;
  1934. }
  1935. }
  1936. #endregion
  1937. }
  1938. private void DataRevToString(ushort CmdTemp, byte[] Data)
  1939. {
  1940. CmdRevStrTemp = "";
  1941. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  1942. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  1943. ushort len = (ushort)(CmdTemp & 0x00FF);
  1944. for (int i = 0; i < len ; i++)
  1945. {
  1946. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  1947. }
  1948. }
  1949. #endregion
  1950. /// <summary>
  1951. /// 端口连接或断开
  1952. /// </summary>
  1953. private void PortConnect()
  1954. {
  1955. bool result = false;
  1956. if (连接ToolStripMenuItem.Text == "连接")
  1957. {
  1958. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  1959. if (result)
  1960. {
  1961. toolStripComboBox_ComNum.Enabled = false;
  1962. toolStripComboBox_Baudrate.Enabled = false;
  1963. 刷新ToolStripMenuItem.Enabled = false;
  1964. 连接ToolStripMenuItem.Text = "断开";
  1965. 连接ToolStripMenuItem.Checked = true;
  1966. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  1967. label_PortStatus.BackColor = Color.Green;
  1968. }
  1969. }
  1970. else if (连接ToolStripMenuItem.Text == "断开")
  1971. {
  1972. checkBox_OBC_StartSetGearSt.Checked = false;
  1973. checkBox_OBC_StartReadBMS.Checked = false;
  1974. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1975. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  1976. toolStripComboBox_ComNum.Enabled = true;
  1977. toolStripComboBox_Baudrate.Enabled = true;
  1978. 刷新ToolStripMenuItem.Enabled = true;
  1979. 连接ToolStripMenuItem.Text = "连接";
  1980. 连接ToolStripMenuItem.Checked = false;
  1981. label_COM_Sta.Text = "连接状态:未连接";
  1982. label_PortStatus.BackColor = Color.Red;
  1983. }
  1984. }
  1985. /// <summary>
  1986. /// 端口连接事件
  1987. /// </summary>
  1988. /// <param name="sender"></param>
  1989. /// <param name="e"></param>
  1990. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  1991. {
  1992. PortConnect();
  1993. }
  1994. /// <summary>
  1995. /// 端口号刷新事件
  1996. /// </summary>
  1997. /// <param name="sender"></param>
  1998. /// <param name="e"></param>
  1999. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2000. {
  2001. toolStripComboBox_ComNum.Items.Clear();
  2002. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2003. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2004. }
  2005. /// <summary>
  2006. /// 转速调节事件
  2007. /// </summary>
  2008. /// <param name="sender"></param>
  2009. /// <param name="e"></param>
  2010. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  2011. {
  2012. //生产模式转速设置值更新
  2013. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  2014. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  2015. //设置转速百分比
  2016. var Data = new byte[1];
  2017. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  2018. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  2019. }
  2020. /// <summary>
  2021. /// 存储标志修改事件
  2022. /// </summary>
  2023. /// <param name="sender"></param>
  2024. /// <param name="e"></param>
  2025. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2026. {
  2027. 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
  2028. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2029. }
  2030. /// <summary>
  2031. /// 1s定时器
  2032. /// </summary>
  2033. /// <param name="sender"></param>
  2034. /// <param name="e"></param>
  2035. private void timer_1s_Tick(object sender, EventArgs e)
  2036. {
  2037. //时间更新
  2038. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2039. //MC_Runinfo超时清除
  2040. if (MC_RunInfo_Refresh == false)
  2041. {
  2042. MC_RunInfo_Refresh_Cnt++;
  2043. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2044. {
  2045. MC_RunInfo_Clear();
  2046. MC_RunInfo_Refresh_Cnt = 0;
  2047. }
  2048. }
  2049. else
  2050. {
  2051. MC_RunInfo_Refresh_Cnt = 0;
  2052. }
  2053. MC_RunInfo_Refresh = false;
  2054. //MC_Debuginfo超时清除
  2055. if (MC_DebugInfo_Refresh == false)
  2056. {
  2057. MC_DebugInfo_Refresh_Cnt++;
  2058. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2059. {
  2060. MC_DebugInfo_Clear();
  2061. MC_DebugInfo_Refresh_Cnt = 0;
  2062. }
  2063. }
  2064. else
  2065. {
  2066. MC_DebugInfo_Refresh_Cnt = 0;
  2067. }
  2068. MC_DebugInfo_Refresh = false;
  2069. //BMS_RunInfo超时清除
  2070. if (BMS_RunInfo_Refresh == false)
  2071. {
  2072. BMS_RunInfo_Refresh_Cnt++;
  2073. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2074. {
  2075. richTextBox_OBC_BMS_RunInfo.Clear();
  2076. BMS_RunInfo_Refresh_Cnt = 0;
  2077. }
  2078. }
  2079. else
  2080. {
  2081. BMS_RunInfo_Refresh_Cnt = 0;
  2082. }
  2083. BMS_RunInfo_Refresh = false;
  2084. //故障码超时清除
  2085. if (MC_ErrorCode_Refresh == false)
  2086. {
  2087. MC_ErrorCode_Refresh_Cnt++;
  2088. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2089. {
  2090. textBox_ErrorCode.Text = "---";
  2091. MC_ErrorCode_Refresh_Cnt = 0;
  2092. }
  2093. }
  2094. else
  2095. {
  2096. MC_ErrorCode_Refresh_Cnt = 0;
  2097. }
  2098. MC_ErrorCode_Refresh = false;
  2099. //CDL连接超时
  2100. if (识别通讯盒ToolStripMenuItem.Checked)
  2101. {
  2102. if (mySerialProcess.CDL_Online_Flag == false)
  2103. {
  2104. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2105. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2106. {
  2107. timer_1s.Enabled = false;
  2108. MessageBox.Show("连接失败!", "提示");
  2109. timer_1s.Enabled = true;
  2110. //关闭串口
  2111. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2112. toolStripComboBox_ComNum.Enabled = true;
  2113. toolStripComboBox_Baudrate.Enabled = true;
  2114. 刷新ToolStripMenuItem.Enabled = true;
  2115. 连接ToolStripMenuItem.Text = "连接";
  2116. 连接ToolStripMenuItem.Checked = false;
  2117. label_COM_Sta.Text = "连接状态:未连接";
  2118. label_PortStatus.BackColor = Color.Red;
  2119. }
  2120. }
  2121. }
  2122. //OBC定时发送设置档位
  2123. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2124. {
  2125. var CtrlCode = new byte[2];
  2126. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2127. CtrlCode[0] = 0x33;
  2128. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2129. CtrlCode[0] = 0x22;
  2130. else
  2131. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2132. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2133. CtrlCode[1] = 0xF1;
  2134. else
  2135. CtrlCode[1] = 0xF0;
  2136. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2137. {
  2138. checkBox_OBC_StartSetGearSt.Checked = false;
  2139. }
  2140. }
  2141. //OBC定时发送查询电池
  2142. if (checkBox_OBC_StartReadBMS.Checked == true)
  2143. {
  2144. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2145. {
  2146. checkBox_OBC_StartReadBMS.Checked = false;
  2147. }
  2148. }
  2149. //定时读取存储器
  2150. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2151. {
  2152. var Address = new byte[4];
  2153. UInt32 Address_Begin;
  2154. UInt32 Addres_End;
  2155. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2156. richTextBox_RamFlasgData.Clear();
  2157. do
  2158. {
  2159. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2160. {
  2161. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2162. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2163. continue;
  2164. }
  2165. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2166. {
  2167. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2168. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2169. continue;
  2170. }
  2171. else
  2172. {
  2173. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2174. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2175. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2176. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2177. if (Addres_End < Address_Begin)
  2178. {
  2179. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2180. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2181. continue;
  2182. }
  2183. else
  2184. {
  2185. var SendByte = new byte[8];
  2186. SendByte[0] = (byte)(Address_Begin >> 24);
  2187. SendByte[1] = (byte)(Address_Begin >> 16);
  2188. SendByte[2] = (byte)(Address_Begin >> 8);
  2189. SendByte[3] = (byte)(Address_Begin);
  2190. SendByte[4] = (byte)(Addres_End >> 24);
  2191. SendByte[5] = (byte)(Addres_End >> 16);
  2192. SendByte[6] = (byte)(Addres_End >> 8);
  2193. SendByte[7] = (byte)(Addres_End);
  2194. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2195. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2196. }
  2197. }
  2198. } while (false);
  2199. }
  2200. //写入参数等待计时
  2201. ACK_WaitCnt++;
  2202. }
  2203. /// <summary>
  2204. /// 运行信息清除
  2205. /// </summary>
  2206. private void MC_RunInfo_Clear()
  2207. {
  2208. foreach (Control c in tabPage_RunInfo.Controls)
  2209. {
  2210. if ((c is TextBox))
  2211. {
  2212. if (c.Name != textBox_ErrorCode.ToString())
  2213. c.Text = "---";
  2214. }
  2215. }
  2216. }
  2217. /// <summary>
  2218. /// 调试信息清除
  2219. /// </summary>
  2220. private void MC_DebugInfo_Clear()
  2221. {
  2222. foreach (Control c in tabPage_DebugInfo.Controls)
  2223. {
  2224. if ((c is TextBox))
  2225. {
  2226. if (c.Name != textBox_ErrorCode.ToString())
  2227. c.Text = "---";
  2228. }
  2229. }
  2230. }
  2231. /// <summary>
  2232. /// 读取马达参数
  2233. /// </summary>
  2234. /// <param name="sender"></param>
  2235. /// <param name="e"></param>
  2236. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2237. {
  2238. richTextBox_MotorParam.Clear();
  2239. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2240. }
  2241. /// <summary>
  2242. /// 写入马达参数
  2243. /// </summary>
  2244. /// <param name="sender"></param>
  2245. /// <param name="e"></param>
  2246. private void button_Write_Click(object sender, EventArgs e)
  2247. {
  2248. var ConfigParam = new byte[40];
  2249. for (int i = 0; i < 40; i++)
  2250. ConfigParam[i] = 0;
  2251. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2252. short wDataTemp = 0;
  2253. ushort DataTemp = 0;
  2254. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2255. try
  2256. {
  2257. for (int i = 0; i < strDataTemp.Length; i++)
  2258. {
  2259. if (i == 6)
  2260. {
  2261. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2262. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2263. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2264. }
  2265. else
  2266. {
  2267. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2268. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2269. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2270. }
  2271. }
  2272. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2273. }
  2274. catch (Exception)
  2275. {
  2276. timer_1s.Enabled = false;
  2277. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2278. timer_1s.Enabled = true;
  2279. }
  2280. }
  2281. /// <summary>
  2282. /// 读取整车信息
  2283. /// </summary>
  2284. /// <param name="sender"></param>
  2285. /// <param name="e"></param>
  2286. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2287. {
  2288. richTextBox_BikeParam.Clear();
  2289. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2290. }
  2291. /// <summary>
  2292. /// 写入整车信息
  2293. /// </summary>
  2294. /// <param name="sender"></param>
  2295. /// <param name="e"></param>
  2296. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2297. {
  2298. var ConfigParam = new byte[28];
  2299. for (int i = 0; i < 28; i++)
  2300. ConfigParam[i] = 0;
  2301. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2302. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2303. try
  2304. {
  2305. for (int i = 0; i < strDataTemp.Length; i++)
  2306. {
  2307. short wDataTemp = 0;
  2308. //前后灯参数修改
  2309. if (i == 8)
  2310. {
  2311. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2312. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2313. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2314. }
  2315. //开关机参数
  2316. else if (i == 11)
  2317. {
  2318. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2319. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2320. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2321. }
  2322. else
  2323. {
  2324. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2325. }
  2326. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2327. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2328. }
  2329. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2330. }
  2331. catch (Exception)
  2332. {
  2333. timer_1s.Enabled = false;
  2334. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2335. timer_1s.Enabled = true;
  2336. }
  2337. }
  2338. /// <summary>
  2339. /// 读取控制器参数
  2340. /// </summary>
  2341. /// <param name="sender"></param>
  2342. /// <param name="e"></param>
  2343. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2344. {
  2345. richTextBox_ControlParam.Clear();
  2346. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2347. }
  2348. /// <summary>
  2349. /// 写入控制器参数
  2350. /// </summary>
  2351. /// <param name="sender"></param>
  2352. /// <param name="e"></param>
  2353. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2354. {
  2355. var ConfigParam = new byte[34];
  2356. for (int i = 0; i < 34; i++)
  2357. ConfigParam[i] = 0;
  2358. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2359. ushort uwDataTemp = 0;
  2360. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2361. try
  2362. {
  2363. for (int i = 0; i < strDataTemp.Length; i++)
  2364. {
  2365. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2366. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2367. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2368. }
  2369. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2370. }
  2371. catch (Exception)
  2372. {
  2373. timer_1s.Enabled = false;
  2374. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2375. timer_1s.Enabled = true;
  2376. }
  2377. }
  2378. /// <summary>
  2379. /// 读取助力参数
  2380. /// </summary>
  2381. /// <param name="sender"></param>
  2382. /// <param name="e"></param>
  2383. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2384. {
  2385. var ConfigParam = new byte[4];
  2386. int AssistNum = 0;
  2387. try
  2388. {
  2389. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2390. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2391. ConfigParam[1] = (byte)(AssistNum >> 8);
  2392. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2393. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2394. ConfigParam[3] = (byte)(AssistNum >> 8);
  2395. richTextBox_AssistParam.Clear();
  2396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2397. }
  2398. catch (Exception)
  2399. {
  2400. timer_1s.Enabled = false;
  2401. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2402. timer_1s.Enabled = true;
  2403. }
  2404. }
  2405. /// <summary>
  2406. /// 写入助力参数
  2407. /// </summary>
  2408. /// <param name="sender"></param>
  2409. /// <param name="e"></param>
  2410. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2411. {
  2412. var ConfigParam = new byte[80];
  2413. for (int i = 0; i < 80; i++)
  2414. ConfigParam[i] = 0;
  2415. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2416. long lDataTemp = 0;
  2417. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2418. int index_1 = 0, index_2 = 0;
  2419. try
  2420. {
  2421. for (int i = 0; i < strDataTemp.Length; i++)
  2422. {
  2423. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2424. {
  2425. index_1 = i;
  2426. break;
  2427. }
  2428. }
  2429. for (int i = 0; i < strDataTemp.Length; i++)
  2430. {
  2431. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2432. {
  2433. index_2 = i;
  2434. break;
  2435. }
  2436. }
  2437. for (int i = 0; i < strDataTemp.Length; i++)
  2438. {
  2439. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2440. if (i < index_1)
  2441. {
  2442. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2443. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2444. }
  2445. else if (i <= index_2)
  2446. {
  2447. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2448. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2449. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2450. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2451. }
  2452. else
  2453. {
  2454. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2455. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2456. }
  2457. }
  2458. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2459. }
  2460. catch (Exception)
  2461. {
  2462. timer_1s.Enabled = false;
  2463. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2464. timer_1s.Enabled = true;
  2465. }
  2466. }
  2467. /// <summary>
  2468. /// 读取调试参数
  2469. /// </summary>
  2470. /// <param name="sender"></param>
  2471. /// <param name="e"></param>
  2472. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2473. {
  2474. richTextBox_DebugParam.Clear();
  2475. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2476. }
  2477. /// <summary>
  2478. /// 写入调试参数
  2479. /// </summary>
  2480. /// <param name="sender"></param>
  2481. /// <param name="e"></param>
  2482. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2483. {
  2484. var ConfigParam = new byte[60];
  2485. for (int i = 0; i < 60; i++)
  2486. ConfigParam[i] = 0;
  2487. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2488. ushort uwDataTemp = 0;
  2489. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2490. try
  2491. {
  2492. for (int i = 0; i < strDataTemp.Length; i++)
  2493. {
  2494. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2495. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2496. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2497. }
  2498. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2499. }
  2500. catch (Exception)
  2501. {
  2502. timer_1s.Enabled = false;
  2503. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2504. timer_1s.Enabled = true;
  2505. }
  2506. }
  2507. /// <summary>
  2508. /// 读取历史
  2509. /// </summary>
  2510. /// <param name="sender"></param>
  2511. /// <param name="e"></param>
  2512. private void button_ReadRecord_Click(object sender, EventArgs e)
  2513. {
  2514. richTextBox_Record.Clear();
  2515. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2516. }
  2517. /// <summary>
  2518. /// 读取传感器参数
  2519. /// </summary>
  2520. /// <param name="sender"></param>
  2521. /// <param name="e"></param>
  2522. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2523. {
  2524. richTextBox_SensorParam.Clear();
  2525. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2526. }
  2527. /// <summary>
  2528. /// 写入力矩传感器标定值
  2529. /// </summary>
  2530. /// <param name="sender"></param>
  2531. /// <param name="e"></param>
  2532. private void button_Write_Cal_Click(object sender, EventArgs e)
  2533. {
  2534. var ConfigParam = new byte[4];
  2535. for (int i = 0; i < 4; i++)
  2536. ConfigParam[i] = 0;
  2537. ushort uwDataTemp = 0;
  2538. try
  2539. {
  2540. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2541. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2542. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2543. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2544. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2545. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2546. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2547. }
  2548. catch (Exception)
  2549. {
  2550. timer_1s.Enabled = false;
  2551. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2552. timer_1s.Enabled = true;
  2553. }
  2554. }
  2555. /// <summary>
  2556. /// 写入传感器参数
  2557. /// </summary>
  2558. /// <param name="sender"></param>
  2559. /// <param name="e"></param>
  2560. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2561. {
  2562. var ConfigParam = new byte[14];
  2563. for (int i = 0; i < 14; i++)
  2564. ConfigParam[i] = 0;
  2565. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2566. ushort uwDataTemp = 0;
  2567. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2568. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2569. int index = 0;
  2570. try
  2571. {
  2572. for (int i = 0; i < strDataTemp.Length; i++)
  2573. {
  2574. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2575. {
  2576. index = i;
  2577. break;
  2578. }
  2579. }
  2580. for (int i = 0; i < (strDataTemp.Length - index); i++)
  2581. {
  2582. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  2583. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2584. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2585. }
  2586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  2587. }
  2588. catch (Exception)
  2589. {
  2590. timer_1s.Enabled = false;
  2591. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2592. timer_1s.Enabled = true;
  2593. }
  2594. }
  2595. /// <summary>
  2596. /// 写入型号
  2597. /// </summary>
  2598. /// <param name="sender"></param>
  2599. /// <param name="e"></param>
  2600. private void button_WriteModel_Click(object sender, EventArgs e)
  2601. {
  2602. string Mode = textBox_Model.Text;
  2603. var ModeArray = new byte[16];
  2604. for (ushort i = 0; i < Mode.Length; i++)
  2605. {
  2606. ModeArray[i] = (byte)Mode[i];
  2607. }
  2608. if (Mode.Length < 16)
  2609. {
  2610. ModeArray[Mode.Length] = (byte)'.';
  2611. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2612. {
  2613. ModeArray[Mode.Length + 1 + i] = 0x20;
  2614. }
  2615. }
  2616. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2617. }
  2618. /// <summary>
  2619. /// 写入SN
  2620. /// </summary>
  2621. /// <param name="sender"></param>
  2622. /// <param name="e"></param>
  2623. private void button_WriteSN_Click(object sender, EventArgs e)
  2624. {
  2625. string SN = textBox_SN.Text;
  2626. var SNArray = new byte[16];
  2627. for (ushort i = 0; i < SN.Length; i++)
  2628. {
  2629. SNArray[i] = (byte)SN[i];
  2630. }
  2631. if (SN.Length < 16)
  2632. {
  2633. SNArray[SN.Length] = (byte)'.';
  2634. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2635. {
  2636. SNArray[SN.Length + 1 + i] = 0x20;
  2637. }
  2638. }
  2639. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2640. }
  2641. /// <summary>
  2642. /// 查询版本信息
  2643. /// </summary>
  2644. /// <param name="sender"></param>
  2645. /// <param name="e"></param>
  2646. private void button_ReadVersion_Click(object sender, EventArgs e)
  2647. {
  2648. textBox_Model.Text = "---";
  2649. textBox_SN.Text = "---";
  2650. textBox_HW.Text = "---";
  2651. textBox_FW.Text = "---";
  2652. textBox_SP.Text = "---";
  2653. textBox_OBC_ReadModel.Text = "---";
  2654. textBox_OBC_ReadSN.Text = "---";
  2655. textBox_OBC_ReadHW.Text = "---";
  2656. textBox_OBC_ReadFW.Text = "---";
  2657. textBox_OBC_ReadSP.Text = "---";
  2658. textBox_FacModeName.Text = "---";
  2659. textBox_FacModeNum.Text = "---";
  2660. textBox_FacModeHW.Text = "---";
  2661. textBox_FacModeFW.Text = "---";
  2662. textBox_FacModeSP.Text = "---";
  2663. Class_Motor_Ver.Mode = "---";
  2664. Class_Motor_Ver.SN = "---";
  2665. Class_Motor_Ver.HW = "---";
  2666. Class_Motor_Ver.FW = "---";
  2667. Class_Motor_Ver.Special = "---";
  2668. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2669. }
  2670. /// <summary>
  2671. /// 查询自定义1
  2672. /// </summary>
  2673. /// <param name="sender"></param>
  2674. /// <param name="e"></param>
  2675. private void button_ReadUser1_Click(object sender, EventArgs e)
  2676. {
  2677. textBox_User1.Text = "---";
  2678. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  2679. }
  2680. /// <summary>
  2681. /// 查询自定义2
  2682. /// </summary>
  2683. /// <param name="sender"></param>
  2684. /// <param name="e"></param>
  2685. private void button_ReadUser2_Click(object sender, EventArgs e)
  2686. {
  2687. textBox_User2.Text = "---";
  2688. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  2689. }
  2690. /// <summary>
  2691. /// 查询自定义3
  2692. /// </summary>
  2693. /// <param name="sender"></param>
  2694. /// <param name="e"></param>
  2695. private void button_ReadUser3_Click(object sender, EventArgs e)
  2696. {
  2697. textBox_User3.Text = "---";
  2698. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  2699. }
  2700. /// <summary>
  2701. /// 写入自定义字符串1
  2702. /// </summary>
  2703. /// <param name="sender"></param>
  2704. /// <param name="e"></param>
  2705. private void button_WriteUser1_Click(object sender, EventArgs e)
  2706. {
  2707. string User = textBox_User1.Text;
  2708. var UserArray = new byte[16];
  2709. for (ushort i = 0; i < User.Length; i++)
  2710. {
  2711. UserArray[i] = (byte)User[i];
  2712. }
  2713. if (User.Length < 16)
  2714. {
  2715. UserArray[User.Length] = (byte)'.';
  2716. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2717. {
  2718. UserArray[User.Length + 1 + i] = 0x20;
  2719. }
  2720. }
  2721. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  2722. }
  2723. /// <summary>
  2724. /// 写入自定义字符串2
  2725. /// </summary>
  2726. /// <param name="sender"></param>
  2727. /// <param name="e"></param>
  2728. private void button_WriteUser2_Click(object sender, EventArgs e)
  2729. {
  2730. string User = textBox_User2.Text;
  2731. var UserArray = new byte[16];
  2732. for (ushort i = 0; i < User.Length; i++)
  2733. {
  2734. UserArray[i] = (byte)User[i];
  2735. }
  2736. if (User.Length < 16)
  2737. {
  2738. UserArray[User.Length] = (byte)'.';
  2739. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2740. {
  2741. UserArray[User.Length + 1 + i] = 0x20;
  2742. }
  2743. }
  2744. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  2745. }
  2746. /// <summary>
  2747. /// 写入自定义字符串3
  2748. /// </summary>
  2749. /// <param name="sender"></param>
  2750. /// <param name="e"></param>
  2751. private void button_WriteUser3_Click(object sender, EventArgs e)
  2752. {
  2753. string User = textBox_User3.Text;
  2754. var UserArray = new byte[16];
  2755. for (ushort i = 0; i < User.Length; i++)
  2756. {
  2757. UserArray[i] = (byte)User[i];
  2758. }
  2759. if (User.Length < 16)
  2760. {
  2761. UserArray[User.Length] = (byte)'.';
  2762. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2763. {
  2764. UserArray[User.Length + 1 + i] = 0x20;
  2765. }
  2766. }
  2767. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  2768. }
  2769. /// <summary>
  2770. /// 查询生产信息
  2771. /// </summary>
  2772. /// <param name="sender"></param>
  2773. /// <param name="e"></param>
  2774. private void button_ReadMAC_Click(object sender, EventArgs e)
  2775. {
  2776. textBox_MAC.Text = "---";
  2777. textBox_MACAdd.Text = "---";
  2778. textBox_MACDate.Text = "---";
  2779. textBox_PP.Text = "---";
  2780. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  2781. }
  2782. /// <summary>
  2783. /// 写入生产信息
  2784. /// </summary>
  2785. /// <param name="sender"></param>
  2786. /// <param name="e"></param>
  2787. private void button_WriteMac_Click(object sender, EventArgs e)
  2788. {
  2789. var MACArray = new byte[32];
  2790. //填入生产商
  2791. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  2792. {
  2793. MACArray[i] = (byte)textBox_MAC.Text[i];
  2794. }
  2795. if (textBox_MAC.Text.Length < 8)
  2796. {
  2797. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  2798. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  2799. {
  2800. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  2801. }
  2802. }
  2803. //填入生产地
  2804. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  2805. {
  2806. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  2807. }
  2808. if (textBox_MACAdd.Text.Length < 8)
  2809. {
  2810. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  2811. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  2812. {
  2813. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  2814. }
  2815. }
  2816. //填入生产日期
  2817. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  2818. {
  2819. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  2820. }
  2821. if (textBox_MACDate.Text.Length < 8)
  2822. {
  2823. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  2824. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  2825. {
  2826. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  2827. }
  2828. }
  2829. //填入品牌
  2830. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  2831. {
  2832. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  2833. }
  2834. if (textBox_PP.Text.Length < 8)
  2835. {
  2836. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  2837. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  2838. {
  2839. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  2840. }
  2841. }
  2842. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  2843. }
  2844. /// <summary>
  2845. /// 查询密钥
  2846. /// </summary>
  2847. /// <param name="sender"></param>
  2848. /// <param name="e"></param>
  2849. private void button_ReadKey_Click(object sender, EventArgs e)
  2850. {
  2851. textBox_Key.Text = "---";
  2852. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  2853. }
  2854. /// <summary>
  2855. /// 写入校验密钥
  2856. /// </summary>
  2857. /// <param name="sender"></param>
  2858. /// <param name="e"></param>
  2859. private void button_WriteKey_Click(object sender, EventArgs e)
  2860. {
  2861. string Key = textBox_Key.Text;
  2862. var KeyArray = new byte[8];
  2863. if (Key.Length != 8)
  2864. {
  2865. timer_1s.Enabled = false;
  2866. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2867. timer_1s.Enabled = true;
  2868. return;
  2869. }
  2870. for (ushort i = 0; i < Key.Length; i++)
  2871. {
  2872. KeyArray[i] = (byte)Key[i];
  2873. }
  2874. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  2875. }
  2876. /// <summary>
  2877. /// 查询在线检测结果
  2878. /// </summary>
  2879. /// <param name="sender"></param>
  2880. /// <param name="e"></param>
  2881. private void button_ReadOnLine_Click(object sender, EventArgs e)
  2882. {
  2883. textBox_Online.Text = "---";
  2884. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  2885. }
  2886. /// <summary>
  2887. /// 系统清除
  2888. /// </summary>
  2889. /// <param name="sender"></param>
  2890. /// <param name="e"></param>
  2891. private void button_SystemClear_Click(object sender, EventArgs e)
  2892. {
  2893. var Code = new byte[5];
  2894. Code[0] = (byte)'C';
  2895. Code[1] = (byte)'L';
  2896. Code[2] = (byte)'E';
  2897. Code[3] = (byte)'A';
  2898. Code[4] = (byte)'R';
  2899. timer_1s.Enabled = false;
  2900. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2901. {
  2902. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2903. {
  2904. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2905. {
  2906. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  2907. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2908. }
  2909. }
  2910. }
  2911. timer_1s.Enabled = true;
  2912. }
  2913. /// <summary>
  2914. /// 参数还原
  2915. /// </summary>
  2916. /// <param name="sender"></param>
  2917. /// <param name="e"></param>
  2918. private void button_Recovery_Click(object sender, EventArgs e)
  2919. {
  2920. var Code = new byte[8];
  2921. Code[0] = (byte)'R';
  2922. Code[1] = (byte)'E';
  2923. Code[2] = (byte)'C';
  2924. Code[3] = (byte)'O';
  2925. Code[4] = (byte)'V';
  2926. Code[5] = (byte)'E';
  2927. Code[6] = (byte)'R';
  2928. Code[7] = (byte)'Y';
  2929. timer_1s.Enabled = false;
  2930. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2931. {
  2932. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2933. {
  2934. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2935. {
  2936. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  2937. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2938. }
  2939. }
  2940. }
  2941. timer_1s.Enabled = true;
  2942. }
  2943. /// <summary>
  2944. /// 系统复位
  2945. /// </summary>
  2946. /// <param name="sender"></param>
  2947. /// <param name="e"></param>
  2948. private void button_Reset_Click(object sender, EventArgs e)
  2949. {
  2950. var Code_Off = new byte[5];
  2951. var Code_Reset = new byte[5];
  2952. Code_Off[0] = (byte)'O';
  2953. Code_Off[1] = (byte)'F';
  2954. Code_Off[2] = (byte)'F';
  2955. Code_Off[3] = (byte)'.';
  2956. Code_Off[4] = (byte)'.';
  2957. Code_Reset[0] = (byte)'R';
  2958. Code_Reset[1] = (byte)'E';
  2959. Code_Reset[2] = (byte)'S';
  2960. Code_Reset[3] = (byte)'E';
  2961. Code_Reset[4] = (byte)'T';
  2962. timer_1s.Enabled = false;
  2963. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2964. {
  2965. timer_1s.Enabled = true;
  2966. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  2967. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  2968. PowerOffAckStatus = false;
  2969. Delay_ms(250);
  2970. int TryCnt = 3;
  2971. while ((TryCnt--) >= 0)
  2972. {
  2973. if (!PowerOffAckStatus)
  2974. {
  2975. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  2976. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  2977. PowerOffAckStatus = false;
  2978. Delay_ms(250);
  2979. }
  2980. else break;
  2981. }
  2982. if (PowerOffAckStatus)
  2983. {
  2984. timer_1s.Enabled = false;
  2985. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  2986. timer_1s.Enabled = true;
  2987. }
  2988. else
  2989. {
  2990. timer_1s.Enabled = false;
  2991. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2992. timer_1s.Enabled = true;
  2993. }
  2994. }
  2995. timer_1s.Enabled = true;
  2996. }
  2997. /// <summary>
  2998. /// 记录清除
  2999. /// </summary>
  3000. /// <param name="sender"></param>
  3001. /// <param name="e"></param>
  3002. private void button_ClearLog_Click(object sender, EventArgs e)
  3003. {
  3004. var Code = new byte[9];
  3005. Code[0] = (byte)'L';
  3006. Code[1] = (byte)'O';
  3007. Code[2] = (byte)'G';
  3008. Code[3] = (byte)' ';
  3009. Code[4] = (byte)'C';
  3010. Code[5] = (byte)'L';
  3011. Code[6] = (byte)'E';
  3012. Code[7] = (byte)'A';
  3013. Code[8] = (byte)'R';
  3014. timer_1s.Enabled = false;
  3015. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3016. {
  3017. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3018. {
  3019. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3020. {
  3021. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3022. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3023. }
  3024. }
  3025. }
  3026. timer_1s.Enabled = true;
  3027. }
  3028. /// <summary>
  3029. /// 打开系统计算器
  3030. /// </summary>
  3031. /// <param name="sender"></param>
  3032. /// <param name="e"></param>
  3033. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3034. {
  3035. System.Diagnostics.Process.Start("calc.exe");
  3036. }
  3037. /// <summary>
  3038. ///故障转换和显示
  3039. /// </summary>
  3040. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3041. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3042. "",""};
  3043. private string ErrorInfoDisplay(UInt32 Code)
  3044. {
  3045. string Result = "";
  3046. if (Code == 0)
  3047. {
  3048. Result = "无故障";
  3049. }
  3050. else
  3051. {
  3052. for (int i = 0; i < 32; i++)
  3053. {
  3054. if ((Code & 0x01) == 0x01)
  3055. {
  3056. Result += ErrorInfo[i] + " ";
  3057. }
  3058. Code >>= 1;
  3059. }
  3060. }
  3061. return Result;
  3062. }
  3063. /// <summary>
  3064. /// 鼠标滑过故障码显示具体内容
  3065. /// </summary>
  3066. /// <param name="sender"></param>
  3067. /// <param name="e"></param>
  3068. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3069. {
  3070. // 创建the ToolTip
  3071. ToolTip toolTip1 = new ToolTip();
  3072. // 设置显示样式
  3073. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  3074. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3075. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3076. toolTip1.ShowAlways = true;//是否显示提示框
  3077. // 设置伴随的对象.
  3078. string ErrorCode = this.textBox_ErrorCode.Text;
  3079. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3080. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3081. }
  3082. /// <summary>
  3083. /// 数据记录
  3084. /// </summary>
  3085. private void RunInfoAutoSave()
  3086. {
  3087. if (运行信息记录ToolStripMenuItem.Checked == true)
  3088. {
  3089. if (RunInfoSaveFilename == string.Empty)
  3090. {
  3091. return;
  3092. }
  3093. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3094. foreach (Control c in tabPage_RunInfo.Controls)
  3095. {
  3096. if (c is TextBox)
  3097. {
  3098. SaveData += c.Text + " , ";
  3099. }
  3100. }
  3101. foreach (Control c in tabPage_DebugInfo.Controls)
  3102. {
  3103. if (c is TextBox)
  3104. {
  3105. SaveData += c.Text + " , ";
  3106. }
  3107. }
  3108. SaveData += "\r\n";
  3109. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3110. }
  3111. }
  3112. /// <summary>
  3113. /// 打开或关闭数据记录
  3114. /// </summary>
  3115. /// <param name="sender"></param>
  3116. /// <param name="e"></param>
  3117. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3118. {
  3119. if (运行信息记录ToolStripMenuItem.Checked == false)
  3120. {
  3121. if (mySerialProcess.mySerial.IsOpen == true)
  3122. {
  3123. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3124. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3125. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3126. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3127. timer_1s.Enabled = false;
  3128. MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3129. timer_1s.Enabled = true;
  3130. 运行信息记录ToolStripMenuItem.Checked = true;
  3131. }
  3132. else
  3133. {
  3134. timer_1s.Enabled = false;
  3135. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3136. timer_1s.Enabled = true;
  3137. }
  3138. }
  3139. else
  3140. {
  3141. 运行信息记录ToolStripMenuItem.Checked = false;
  3142. timer_1s.Enabled = false;
  3143. MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3144. timer_1s.Enabled = true;
  3145. }
  3146. }
  3147. /// <summary>
  3148. /// 仪表启动控制档位开关事件
  3149. /// </summary>
  3150. /// <param name="sender"></param>
  3151. /// <param name="e"></param>
  3152. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3153. {
  3154. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3155. {
  3156. //检查串口是否打开
  3157. if (!mySerialProcess.mySerial.IsOpen)
  3158. {
  3159. timer_1s.Enabled = false;
  3160. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3161. timer_1s.Enabled = true;
  3162. checkBox_OBC_StartSetGearSt.Checked = false;
  3163. return;
  3164. }
  3165. //检查是否选择档位和打开车灯
  3166. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3167. {
  3168. timer_1s.Enabled = false;
  3169. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3170. timer_1s.Enabled = true;
  3171. checkBox_OBC_StartSetGearSt.Checked = false;
  3172. return;
  3173. }
  3174. }
  3175. }
  3176. /// <summary>
  3177. /// OBC查询电机用户参数
  3178. /// </summary>
  3179. /// <param name="sender"></param>
  3180. /// <param name="e"></param>
  3181. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3182. {
  3183. richTextBox_OBC_ReadUserInfo.Clear();
  3184. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3185. }
  3186. /// <summary>
  3187. /// OBC设置电机用户参数
  3188. /// </summary>
  3189. /// <param name="sender"></param>
  3190. /// <param name="e"></param>
  3191. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3192. {
  3193. var UserInfoCode = new byte[8];
  3194. for (int i = 0; i < UserInfoCode.Length; i++)
  3195. UserInfoCode[i] = 0;
  3196. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3197. {
  3198. timer_1s.Enabled = false;
  3199. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3200. timer_1s.Enabled = true;
  3201. return;
  3202. }
  3203. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3204. {
  3205. timer_1s.Enabled = false;
  3206. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3207. timer_1s.Enabled = true;
  3208. return;
  3209. }
  3210. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3211. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3212. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3213. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3214. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3215. }
  3216. /// <summary>
  3217. /// OBC查询电机版本信息
  3218. /// </summary>
  3219. /// <param name="sender"></param>
  3220. /// <param name="e"></param>
  3221. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3222. {
  3223. textBox_Model.Text = "---";
  3224. textBox_SN.Text = "---";
  3225. textBox_HW.Text = "---";
  3226. textBox_FW.Text = "---";
  3227. textBox_SP.Text = "---";
  3228. textBox_OBC_ReadModel.Text = "---";
  3229. textBox_OBC_ReadSN.Text = "---";
  3230. textBox_OBC_ReadHW.Text = "---";
  3231. textBox_OBC_ReadFW.Text = "---";
  3232. textBox_OBC_ReadSP.Text = "---";
  3233. textBox_FacModeName.Text = "---";
  3234. textBox_FacModeNum.Text = "---";
  3235. textBox_FacModeHW.Text = "---";
  3236. textBox_FacModeFW.Text = "---";
  3237. textBox_FacModeSP.Text = "---";
  3238. Class_Motor_Ver.Mode = "---";
  3239. Class_Motor_Ver.SN = "---";
  3240. Class_Motor_Ver.HW = "---";
  3241. Class_Motor_Ver.FW = "---";
  3242. Class_Motor_Ver.Special = "---";
  3243. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3244. }
  3245. /// <summary>
  3246. /// OBC读取骑行历史
  3247. /// </summary>
  3248. /// <param name="sender"></param>
  3249. /// <param name="e"></param>
  3250. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3251. {
  3252. textBox_OBC_TRIP_KM.Text = "";
  3253. textBox_OBC_TRIP_TIME.Text = "";
  3254. textBox_OBC_ODO_KM.Text = "";
  3255. textBox_OBC_ODO_TIME.Text = "";
  3256. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3257. }
  3258. /// <summary>
  3259. /// OBC清除TRIP里程
  3260. /// </summary>
  3261. /// <param name="sender"></param>
  3262. /// <param name="e"></param>
  3263. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3264. {
  3265. var Code = new byte[5];
  3266. Code[0] = (byte)'C';
  3267. Code[1] = (byte)'L';
  3268. Code[2] = (byte)'E';
  3269. Code[3] = (byte)'A';
  3270. Code[4] = (byte)'R';
  3271. timer_1s.Enabled = false;
  3272. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3273. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3274. timer_1s.Enabled = true;
  3275. }
  3276. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3277. {
  3278. if (checkBox_OBC_StartReadBMS.Checked == true)
  3279. {
  3280. //检查串口是否打开
  3281. if (!mySerialProcess.mySerial.IsOpen)
  3282. {
  3283. timer_1s.Enabled = false;
  3284. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3285. timer_1s.Enabled = true;
  3286. checkBox_OBC_StartReadBMS.Checked = false;
  3287. return;
  3288. }
  3289. }
  3290. }
  3291. /// <summary>
  3292. /// 写入力矩传感器参数
  3293. /// </summary>
  3294. /// <param name="sender"></param>
  3295. /// <param name="e"></param>
  3296. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3297. {
  3298. var ConfigParam = new byte[46];
  3299. for (int i = 0; i < 14; i++)
  3300. ConfigParam[i] = 0;
  3301. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3302. ushort uwDataTemp = 0;
  3303. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3304. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3305. int index = 0;
  3306. try
  3307. {
  3308. for (int i = 0; i < strDataTemp.Length; i++)
  3309. {
  3310. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3311. {
  3312. index = i;
  3313. break;
  3314. }
  3315. }
  3316. for (int i = 0; i < (index + 1); i++)
  3317. {
  3318. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3319. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3320. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3321. }
  3322. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3323. }
  3324. catch (Exception)
  3325. {
  3326. timer_1s.Enabled = false;
  3327. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3328. timer_1s.Enabled = true;
  3329. }
  3330. }
  3331. /// <summary>
  3332. /// 查询存储标志
  3333. /// </summary>
  3334. /// <param name="sender"></param>
  3335. /// <param name="e"></param>
  3336. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3337. {
  3338. radioButton_EE_SaveYes.Checked = false;
  3339. radioButton_EE_SaveNo.Checked = false;
  3340. radioButton_SIP_SaveYes.Checked = false;
  3341. radioButton_SIP_SaveNo.Checked = false;
  3342. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3343. }
  3344. /// <summary>
  3345. /// 写入存储标志
  3346. /// </summary>
  3347. /// <param name="sender"></param>
  3348. /// <param name="e"></param>
  3349. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3350. {
  3351. var SaveFlag = new byte[6];
  3352. for (int i = 0; i < 6; i++)
  3353. SaveFlag[i] = 0;
  3354. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3355. {
  3356. timer_1s.Enabled = false;
  3357. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3358. timer_1s.Enabled = true;
  3359. return;
  3360. }
  3361. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3362. {
  3363. timer_1s.Enabled = false;
  3364. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3365. timer_1s.Enabled = true;
  3366. return;
  3367. }
  3368. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3369. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3370. SaveFlag[3] = 0;
  3371. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3372. SaveFlag[5] = 0;
  3373. timer_1s.Enabled = false;
  3374. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3375. {
  3376. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3377. }
  3378. timer_1s.Enabled = true;
  3379. }
  3380. /// <summary>
  3381. /// 读取指定地址数据
  3382. /// </summary>
  3383. /// <param name="sender"></param>
  3384. /// <param name="e"></param>
  3385. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3386. {
  3387. var Address = new byte[4];
  3388. UInt32 Address_Begin;
  3389. UInt32 Addres_End;
  3390. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3391. richTextBox_RamFlasgData.Clear();
  3392. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3393. {
  3394. timer_1s.Enabled = false;
  3395. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3396. timer_1s.Enabled = true;
  3397. return;
  3398. }
  3399. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3400. {
  3401. timer_1s.Enabled = false;
  3402. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3403. timer_1s.Enabled = true;
  3404. return;
  3405. }
  3406. else
  3407. {
  3408. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3409. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3410. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3411. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3412. if (Addres_End < Address_Begin)
  3413. {
  3414. timer_1s.Enabled = false;
  3415. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3416. timer_1s.Enabled = true;
  3417. return;
  3418. }
  3419. else
  3420. {
  3421. var SendByte = new byte[8];
  3422. SendByte[0] = (byte)(Address_Begin >> 24);
  3423. SendByte[1] = (byte)(Address_Begin >> 16);
  3424. SendByte[2] = (byte)(Address_Begin >> 8);
  3425. SendByte[3] = (byte)(Address_Begin);
  3426. SendByte[4] = (byte)(Addres_End >> 24);
  3427. SendByte[5] = (byte)(Addres_End >> 16);
  3428. SendByte[6] = (byte)(Addres_End >> 8);
  3429. SendByte[7] = (byte)(Addres_End);
  3430. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3431. }
  3432. }
  3433. }
  3434. /// <summary>
  3435. /// 工作模式选择
  3436. /// </summary>
  3437. /// <param name="sender"></param>
  3438. /// <param name="e"></param>
  3439. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3440. {
  3441. var RunMode = new byte[1];
  3442. if (comboBox_WorkMode.Text == "配置模式")
  3443. RunMode[0] = 0x01;
  3444. else if (comboBox_WorkMode.Text == "调试模式")
  3445. RunMode[0] = 0x02;
  3446. else
  3447. RunMode[0] = 0x00;
  3448. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3449. }
  3450. /// <summary>
  3451. /// 助力档位选择
  3452. /// </summary>
  3453. /// <param name="sender"></param>
  3454. /// <param name="e"></param>
  3455. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3456. {
  3457. var CtrlCode = new byte[2];
  3458. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3459. CtrlCode[0] = 0x33;
  3460. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3461. CtrlCode[0] = 0x22;
  3462. else
  3463. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3464. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3465. CtrlCode[1] = 0xF1;
  3466. else
  3467. CtrlCode[1] = 0xF0;
  3468. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3469. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3470. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3471. }
  3472. /// <summary>
  3473. /// 仪表档位选择
  3474. /// </summary>
  3475. /// <param name="sender"></param>
  3476. /// <param name="e"></param>
  3477. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3478. {
  3479. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3480. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3481. }
  3482. /// <summary>
  3483. /// 生产模式初始化
  3484. /// </summary>
  3485. /// <param name="sender"></param>
  3486. /// <param name="e"></param>
  3487. private void button_FacModeInit_Click(object sender, EventArgs e)
  3488. {
  3489. var Code = new byte[5];
  3490. Code[0] = (byte)'C';
  3491. Code[1] = (byte)'L';
  3492. Code[2] = (byte)'E';
  3493. Code[3] = (byte)'A';
  3494. Code[4] = (byte)'R';
  3495. timer_1s.Enabled = false;
  3496. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3497. {
  3498. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3499. {
  3500. timer_1s.Enabled = true;
  3501. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3502. PowerOffAckStatus = false;
  3503. Delay_ms(250);
  3504. int TryCnt = 3;
  3505. while ((TryCnt--) >= 0)
  3506. {
  3507. if (!PowerOffAckStatus)
  3508. {
  3509. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3510. PowerOffAckStatus = false;
  3511. Delay_ms(250);
  3512. }
  3513. else break;
  3514. }
  3515. if (PowerOffAckStatus)
  3516. {
  3517. timer_1s.Enabled = false;
  3518. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3519. timer_1s.Enabled = true;
  3520. }
  3521. else
  3522. {
  3523. timer_1s.Enabled = false;
  3524. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3525. timer_1s.Enabled = true;
  3526. }
  3527. timer_1s.Enabled = true;
  3528. }
  3529. }
  3530. timer_1s.Enabled = true;
  3531. //清除历史测试记录
  3532. textBox_FacModeSensorADC0.Text = "";
  3533. textBox_FacModeSensorADC1.Text = "";
  3534. textBox_FacModeSensorADC2.Text = "";
  3535. textBox_FacModeSensorADC3.Text = "";
  3536. textBox_FacModeSensorADC4.Text = "";
  3537. LightSwitchStatus = false;
  3538. MotorRunStatus = false;
  3539. trackBar_FacModeMotorSpeedAdj.Value = 5;
  3540. textBox_FacModeName.Text = "";
  3541. textBox_FacModeNum.Text = "";
  3542. textBox_FacModeHW.Text = "";
  3543. textBox_FacModeFW.Text = "";
  3544. }
  3545. /// <summary>
  3546. /// 生产模式读取传感器参数
  3547. /// </summary>
  3548. /// <param name="sender"></param>
  3549. /// <param name="e"></param>
  3550. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3551. {
  3552. richTextBox_SensorParam.Clear();
  3553. textBox_FacModeSensorADC0.Text = "";
  3554. textBox_FacModeSensorADC1.Text = "";
  3555. textBox_FacModeSensorADC2.Text = "";
  3556. textBox_FacModeSensorADC3.Text = "";
  3557. textBox_FacModeSensorADC4.Text = "";
  3558. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3559. }
  3560. /// <summary>
  3561. /// 生产模式传感器标定1
  3562. /// </summary>
  3563. /// <param name="sender"></param>
  3564. /// <param name="e"></param>
  3565. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  3566. {
  3567. var ConfigParam = new byte[4];
  3568. for (int i = 0; i < 4; i++)
  3569. ConfigParam[i] = 0;
  3570. ushort uwDataTemp = 0;
  3571. try
  3572. {
  3573. uwDataTemp = 1;//负载序号
  3574. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3575. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3576. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  3577. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3578. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3579. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3580. Delay_ms(200);
  3581. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3582. }
  3583. catch (Exception)
  3584. {
  3585. timer_1s.Enabled = false;
  3586. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3587. timer_1s.Enabled = true;
  3588. }
  3589. }
  3590. /// <summary>
  3591. /// 生产模式传感器标定2
  3592. /// </summary>
  3593. /// <param name="sender"></param>
  3594. /// <param name="e"></param>
  3595. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  3596. {
  3597. var ConfigParam = new byte[4];
  3598. for (int i = 0; i < 4; i++)
  3599. ConfigParam[i] = 0;
  3600. ushort uwDataTemp = 0;
  3601. try
  3602. {
  3603. uwDataTemp = 2;//负载序号
  3604. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3605. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3606. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  3607. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3608. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3609. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3610. Delay_ms(200);
  3611. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3612. }
  3613. catch (Exception)
  3614. {
  3615. timer_1s.Enabled = false;
  3616. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3617. timer_1s.Enabled = true;
  3618. }
  3619. }
  3620. /// <summary>
  3621. /// 生产模式传感器标定3
  3622. /// </summary>
  3623. /// <param name="sender"></param>
  3624. /// <param name="e"></param>
  3625. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  3626. {
  3627. var ConfigParam = new byte[4];
  3628. for (int i = 0; i < 4; i++)
  3629. ConfigParam[i] = 0;
  3630. ushort uwDataTemp = 0;
  3631. try
  3632. {
  3633. uwDataTemp = 3;//负载序号
  3634. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3635. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3636. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  3637. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3638. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3639. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3640. Delay_ms(200);
  3641. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3642. }
  3643. catch (Exception)
  3644. {
  3645. timer_1s.Enabled = false;
  3646. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3647. timer_1s.Enabled = true;
  3648. }
  3649. }
  3650. /// <summary>
  3651. /// 生产模式传感器标定3
  3652. /// </summary>
  3653. /// <param name="sender"></param>
  3654. /// <param name="e"></param>
  3655. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  3656. {
  3657. var ConfigParam = new byte[4];
  3658. for (int i = 0; i < 4; i++)
  3659. ConfigParam[i] = 0;
  3660. ushort uwDataTemp = 0;
  3661. try
  3662. {
  3663. uwDataTemp = 4;//负载序号
  3664. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3665. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3666. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  3667. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3668. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3669. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3670. Delay_ms(200);
  3671. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3672. }
  3673. catch (Exception)
  3674. {
  3675. timer_1s.Enabled = false;
  3676. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3677. timer_1s.Enabled = true;
  3678. }
  3679. }
  3680. /// <summary>
  3681. /// 生产模式开关灯
  3682. /// </summary>
  3683. /// <param name="sender"></param>
  3684. /// <param name="e"></param>
  3685. bool LightSwitchStatus = false;
  3686. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  3687. {
  3688. var CtrlCode = new byte[2];
  3689. CtrlCode[0] = 0x00;
  3690. if (LightSwitchStatus)
  3691. {
  3692. CtrlCode[1] = 0xF0;
  3693. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  3694. }
  3695. else
  3696. {
  3697. CtrlCode[1] = 0xF1;
  3698. button_FacModeLightSW.BackColor = Color.Yellow;
  3699. }
  3700. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  3701. {
  3702. LightSwitchStatus = !LightSwitchStatus;
  3703. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3704. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3705. }
  3706. }
  3707. /// <summary>
  3708. /// 生产模式电机控制
  3709. /// </summary>
  3710. /// <param name="sender"></param>
  3711. /// <param name="e"></param>
  3712. bool MotorRunStatus = false;
  3713. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  3714. {
  3715. string DebugDefaultInfo = "";
  3716. //获取调试信息
  3717. if (richTextBox_DebugParam.Text == string.Empty)
  3718. {
  3719. richTextBox_DebugParam.Clear();
  3720. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  3721. }
  3722. Delay_ms(200);
  3723. DebugDefaultInfo = richTextBox_DebugParam.Text;
  3724. //获取参数
  3725. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  3726. if (strDataTemp.Length != 29)
  3727. {
  3728. timer_1s.Enabled = false;
  3729. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3730. timer_1s.Enabled = true;
  3731. return;
  3732. }
  3733. //设置参数
  3734. var ConfigParam = new byte[60];
  3735. for (int i = 0; i < 60; i++)
  3736. ConfigParam[i] = 0;
  3737. ConfigParam[0] = 0x00;
  3738. ushort uwDataTemp = 0;
  3739. if (!MotorRunStatus) //停止状态
  3740. {
  3741. //设置速度环
  3742. strDataTemp[0] = "整体运行模式=3";
  3743. //发送数据
  3744. try
  3745. {
  3746. for (int i = 0; i < strDataTemp.Length; i++)
  3747. {
  3748. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3749. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3750. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3751. }
  3752. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  3753. return;
  3754. }
  3755. catch (Exception)
  3756. {
  3757. timer_1s.Enabled = false;
  3758. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3759. timer_1s.Enabled = true;
  3760. }
  3761. Delay_ms(200);
  3762. //设置转速百分比100%
  3763. trackBar_FacModeMotorSpeedAdj.Value = 100;
  3764. MotorRunStatus = !MotorRunStatus;
  3765. button_FacModeMotorRun.BackColor = Color.Yellow;
  3766. Delay_ms(200);
  3767. //电机进入配置模式
  3768. var RunMode = new byte[1];
  3769. RunMode[0] = 0x01;
  3770. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3771. }
  3772. else //运转状态
  3773. {
  3774. //设置转速百分比0%
  3775. trackBar_FacModeMotorSpeedAdj.Value = 0;
  3776. MotorRunStatus = !MotorRunStatus;
  3777. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  3778. Delay_ms(200);
  3779. //还原为原始值
  3780. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  3781. try
  3782. {
  3783. for (int i = 0; i < strDataTemp.Length; i++)
  3784. {
  3785. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3786. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3787. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3788. }
  3789. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  3790. return;
  3791. }
  3792. catch (Exception)
  3793. {
  3794. timer_1s.Enabled = false;
  3795. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3796. timer_1s.Enabled = true;
  3797. }
  3798. Delay_ms(200);
  3799. //电机退出配置模式
  3800. var RunMode = new byte[1];
  3801. RunMode[0] = 0x00;
  3802. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3803. }
  3804. }
  3805. /// <summary>
  3806. /// 生产模式转速调节
  3807. /// </summary>
  3808. /// <param name="sender"></param>
  3809. /// <param name="e"></param>
  3810. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  3811. {
  3812. //转速百分比更新
  3813. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  3814. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  3815. }
  3816. /// <summary>
  3817. /// 生产模式写入型号
  3818. /// </summary>
  3819. /// <param name="sender"></param>
  3820. /// <param name="e"></param>
  3821. private void button_FacModeSetName_Click(object sender, EventArgs e)
  3822. {
  3823. string Mode = textBox_FacModeName.Text;
  3824. var ModeArray = new byte[16];
  3825. for (ushort i = 0; i < Mode.Length; i++)
  3826. {
  3827. ModeArray[i] = (byte)Mode[i];
  3828. }
  3829. if (Mode.Length < 16)
  3830. {
  3831. ModeArray[Mode.Length] = (byte)'.';
  3832. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3833. {
  3834. ModeArray[Mode.Length + 1 + i] = 0x20;
  3835. }
  3836. }
  3837. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3838. }
  3839. /// <summary>
  3840. /// 生产模式写入SN
  3841. /// </summary>
  3842. /// <param name="sender"></param>
  3843. /// <param name="e"></param>
  3844. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  3845. {
  3846. string SN = textBox_FacModeNum.Text;
  3847. var SNArray = new byte[16];
  3848. for (ushort i = 0; i < SN.Length; i++)
  3849. {
  3850. SNArray[i] = (byte)SN[i];
  3851. }
  3852. if (SN.Length < 16)
  3853. {
  3854. SNArray[SN.Length] = (byte)'.';
  3855. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3856. {
  3857. SNArray[SN.Length + 1 + i] = 0x20;
  3858. }
  3859. }
  3860. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3861. }
  3862. /// <summary>
  3863. /// 生产模式读取版本信息
  3864. /// </summary>
  3865. /// <param name="sender"></param>
  3866. /// <param name="e"></param>
  3867. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  3868. {
  3869. textBox_Model.Text = "---";
  3870. textBox_SN.Text = "---";
  3871. textBox_HW.Text = "---";
  3872. textBox_FW.Text = "---";
  3873. textBox_SP.Text = "---";
  3874. textBox_OBC_ReadModel.Text = "---";
  3875. textBox_OBC_ReadSN.Text = "---";
  3876. textBox_OBC_ReadHW.Text = "---";
  3877. textBox_OBC_ReadFW.Text = "---";
  3878. textBox_OBC_ReadSP.Text = "---";
  3879. textBox_FacModeName.Text = "---";
  3880. textBox_FacModeNum.Text = "---";
  3881. textBox_FacModeHW.Text = "---";
  3882. textBox_FacModeFW.Text = "---";
  3883. textBox_FacModeSP.Text = "---";
  3884. textBox_FacModeGit.Text = "---";
  3885. Class_Motor_Ver.Mode = "---";
  3886. Class_Motor_Ver.SN = "---";
  3887. Class_Motor_Ver.HW = "---";
  3888. Class_Motor_Ver.FW = "---";
  3889. Class_Motor_Ver.Special = "---";
  3890. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3891. }
  3892. /// <summary>
  3893. /// 生产模式写入生产信息
  3894. /// </summary>
  3895. /// <param name="sender"></param>
  3896. /// <param name="e"></param>
  3897. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  3898. {
  3899. var MACArray = new byte[32];
  3900. string MacDefaultInfo = "";
  3901. string MacAddDefaultInfo = "";
  3902. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  3903. string MacPPDefaultInfo = "";
  3904. do
  3905. {
  3906. //填入生产商
  3907. if (toolStripTextBox_MAC.Text == string.Empty)
  3908. {
  3909. break;
  3910. }
  3911. MacDefaultInfo = toolStripTextBox_MAC.Text;
  3912. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  3913. {
  3914. MACArray[i] = (byte)MacDefaultInfo[i];
  3915. }
  3916. if (MacDefaultInfo.Length < 8)
  3917. {
  3918. MACArray[MacDefaultInfo.Length] = (byte)'.';
  3919. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  3920. {
  3921. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  3922. }
  3923. }
  3924. //填入生产地
  3925. if (toolStripTextBoxMACAddr.Text == string.Empty)
  3926. {
  3927. break;
  3928. }
  3929. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  3930. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  3931. {
  3932. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  3933. }
  3934. if (MacAddDefaultInfo.Length < 8)
  3935. {
  3936. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  3937. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  3938. {
  3939. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  3940. }
  3941. }
  3942. //填入生产日期
  3943. if (toolStripTextBox_MACDate.Text == string.Empty)
  3944. {
  3945. break;
  3946. }
  3947. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  3948. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  3949. {
  3950. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  3951. }
  3952. if (MacDateDefaultInfo.Length < 8)
  3953. {
  3954. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  3955. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  3956. {
  3957. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  3958. }
  3959. }
  3960. //填入产品标识
  3961. if (toolStripTextBox_MACPD.Text == string.Empty)
  3962. {
  3963. break;
  3964. }
  3965. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  3966. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  3967. {
  3968. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  3969. }
  3970. if (MacPPDefaultInfo.Length < 8)
  3971. {
  3972. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  3973. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  3974. {
  3975. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  3976. }
  3977. }
  3978. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3979. return;
  3980. } while (false);
  3981. timer_1s.Enabled = false;
  3982. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3983. timer_1s.Enabled = true;
  3984. }
  3985. /// <summary>
  3986. /// 生产模式保存测试页面
  3987. /// </summary>
  3988. /// <param name="sender"></param>
  3989. /// <param name="e"></param>
  3990. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  3991. {
  3992. Button_FacModeSaveResult.Text = "存储中…";
  3993. string[] AssistParams = new string[15];
  3994. do
  3995. {
  3996. //读取一次马达参数
  3997. richTextBox_MotorParam.Clear();
  3998. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  3999. Delay_ms(100);
  4000. //读取一次整车参数
  4001. richTextBox_BikeParam.Clear();
  4002. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4003. Delay_ms(100);
  4004. //读取一次控制参数
  4005. richTextBox_ControlParam.Clear();
  4006. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4007. Delay_ms(100);
  4008. //查询传感器
  4009. richTextBox_SensorParam.Clear();
  4010. textBox_FacModeSensorADC0.Text = "";
  4011. textBox_FacModeSensorADC1.Text = "";
  4012. textBox_FacModeSensorADC2.Text = "";
  4013. textBox_FacModeSensorADC3.Text = "";
  4014. textBox_FacModeSensorADC4.Text = "";
  4015. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4016. Delay_ms(100);
  4017. //读取15次助力参数
  4018. for (int i = 1; i <= 15; i++)
  4019. {
  4020. var ConfigParam = new byte[4];
  4021. richTextBox_AssistParam.Clear();
  4022. ConfigParam[0] = (byte)(i & 0xFF);
  4023. ConfigParam[1] = (byte)(i >> 8);
  4024. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4025. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4026. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4027. Delay_ms(200);
  4028. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4029. }
  4030. //读取一次调试信息
  4031. richTextBox_DebugParam.Clear();
  4032. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4033. Delay_ms(100);
  4034. //读取一次历史信息
  4035. richTextBox_Record.Clear();
  4036. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4037. Delay_ms(100);
  4038. //读取一次电机运行信息
  4039. var CtrlCode = new byte[2];
  4040. CtrlCode[0] = 0x00;
  4041. CtrlCode[1] = 0xF0;
  4042. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4043. Delay_ms(100);
  4044. //读取一次版本信息
  4045. textBox_Model.Text = "---";
  4046. textBox_SN.Text = "---";
  4047. textBox_HW.Text = "---";
  4048. textBox_FW.Text = "---";
  4049. textBox_OBC_ReadModel.Text = "---";
  4050. textBox_OBC_ReadSN.Text = "---";
  4051. textBox_OBC_ReadHW.Text = "---";
  4052. textBox_OBC_ReadFW.Text = "---";
  4053. textBox_FacModeName.Text = "---";
  4054. textBox_FacModeNum.Text = "---";
  4055. textBox_FacModeHW.Text = "---";
  4056. textBox_FacModeFW.Text = "---";
  4057. Class_Motor_Ver.Mode = "---";
  4058. Class_Motor_Ver.SN = "---";
  4059. Class_Motor_Ver.HW = "---";
  4060. Class_Motor_Ver.FW = "---";
  4061. Class_Motor_Ver.Special = "---";
  4062. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4063. Delay_ms(100);
  4064. //读取一次生产信息
  4065. textBox_MAC.Text = "";
  4066. textBox_MACAdd.Text = "";
  4067. textBox_MACDate.Text = "";
  4068. textBox_PP.Text = "";
  4069. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4070. Delay_ms(100);
  4071. //读取一次自定义信息
  4072. textBox_User1.Text = "---";
  4073. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4074. Delay_ms(100);
  4075. textBox_User2.Text = "---";
  4076. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4077. Delay_ms(100);
  4078. textBox_User3.Text = "---";
  4079. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4080. Delay_ms(100);
  4081. //读取一次密钥
  4082. textBox_Key.Text = "---";
  4083. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4084. Delay_ms(100);
  4085. //读取一次存储标志
  4086. radioButton_EE_SaveYes.Checked = false;
  4087. radioButton_EE_SaveNo.Checked = false;
  4088. radioButton_SIP_SaveYes.Checked = false;
  4089. radioButton_SIP_SaveNo.Checked = false;
  4090. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4091. Delay_ms(100);
  4092. //读取一次MOS内阻校准参数
  4093. foreach (Control c in groupBox21.Controls)
  4094. {
  4095. if (c is TextBox)
  4096. c.Text = "";
  4097. }
  4098. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4099. Delay_ms(100);
  4100. //提示检查
  4101. #if false
  4102. timer_1s.Enabled = false;
  4103. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4104. {
  4105. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4106. timer_1s.Enabled = true;
  4107. return;
  4108. }
  4109. timer_1s.Enabled = true;
  4110. Delay_ms(200);
  4111. #endif
  4112. //判断数据是否有效
  4113. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4114. {
  4115. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4116. break;
  4117. }
  4118. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4119. {
  4120. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4121. break;
  4122. }
  4123. //设置文件存储路径
  4124. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4125. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4126. Save_Path += PD_PathName;
  4127. if (!Directory.Exists(Save_Path))
  4128. Directory.CreateDirectory(Save_Path);
  4129. //保存页面
  4130. string PIC_SaveFileName = "";
  4131. Double scaleX = PrimaryScreen.ScaleX;
  4132. Double scaleY = PrimaryScreen.ScaleY;
  4133. //保存页面
  4134. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4135. Graphics g = Graphics.FromImage(bit);
  4136. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4137. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4138. bit.Save(PIC_SaveFileName);
  4139. //保存数据
  4140. string DataFileName = "";
  4141. string FileInfo = "";
  4142. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4143. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4144. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4145. FileInfo += "\r\n";
  4146. FileInfo += "[电机信息]\r\n";
  4147. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4148. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4149. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4150. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4151. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4152. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4153. FileInfo += "\r\n";
  4154. FileInfo += "[马达参数]\r\n";
  4155. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4156. FileInfo += "\r\n";
  4157. FileInfo += "[整车参数]\r\n";
  4158. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4159. FileInfo += "\r\n";
  4160. FileInfo += "[控制参数]\r\n";
  4161. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4162. FileInfo += "\r\n";
  4163. FileInfo += "[传感器参数]\r\n";
  4164. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4165. FileInfo += "\r\n";
  4166. FileInfo += "[助力参数]\r\n";
  4167. for(int i=0;i<15;i++)
  4168. {
  4169. FileInfo += AssistParams[i] + "\r\n";
  4170. }
  4171. FileInfo += "[调试参数]\r\n";
  4172. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4173. FileInfo += "\r\n";
  4174. FileInfo += "[历史信息]\r\n";
  4175. FileInfo += richTextBox_Record.Text + "\r\n";
  4176. FileInfo += "\r\n";
  4177. FileInfo += "[MOS内阻校准参数]\r\n";
  4178. FileInfo += textBox_MOS_K1.Text + ", ";
  4179. FileInfo += textBox_MOS_K2.Text + ", ";
  4180. FileInfo += textBox_MOS_K3.Text + ", ";
  4181. FileInfo += textBox_MOS_K4.Text + ", ";
  4182. FileInfo += textBox_MOS_K5.Text + ", ";
  4183. FileInfo += textBox_MOS_R1.Text + ", ";
  4184. FileInfo += textBox_MOS_R2.Text + ", ";
  4185. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4186. FileInfo += "\r\n";
  4187. FileInfo += "[生产信息]\r\n";
  4188. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4189. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4190. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4191. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4192. FileInfo += "\r\n";
  4193. FileInfo += "[自定义信息]\r\n";
  4194. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4195. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4196. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4197. FileInfo += "\r\n";
  4198. FileInfo += "[校验密钥]\r\n";
  4199. FileInfo += textBox_Key.Text + "\r\n";
  4200. FileInfo += "\r\n";
  4201. FileInfo += "[存储标志]\r\n";
  4202. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4203. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4204. FileInfo += "\r\n";
  4205. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4206. Delay_ms(1000);
  4207. timer_1s.Enabled = false;
  4208. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4209. timer_1s.Enabled = true;
  4210. //数据上传
  4211. if (myFtp.IsNetConnected == true)
  4212. {
  4213. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4214. //检查路径
  4215. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4216. {
  4217. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4218. }
  4219. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4220. {
  4221. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4222. }
  4223. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4224. {
  4225. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4226. }
  4227. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4228. {
  4229. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4230. }
  4231. //上传文件
  4232. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4233. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4234. if ((result1 & result2) == true)
  4235. {
  4236. timer_1s.Enabled = false;
  4237. MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4238. timer_1s.Enabled = true;
  4239. }
  4240. else
  4241. {
  4242. timer_1s.Enabled = false;
  4243. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4244. timer_1s.Enabled = true;
  4245. }
  4246. }
  4247. else
  4248. {
  4249. timer_1s.Enabled = false;
  4250. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4251. timer_1s.Enabled = true;
  4252. }
  4253. Button_FacModeSaveResult.Text = "保存数据";
  4254. return;
  4255. } while (false);
  4256. timer_1s.Enabled = false;
  4257. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4258. timer_1s.Enabled = true;
  4259. Button_FacModeSaveResult.Text = "保存数据";
  4260. }
  4261. /// <summary>
  4262. /// 工具箱页面保存
  4263. /// </summary>
  4264. /// <param name="sender"></param>
  4265. /// <param name="e"></param>
  4266. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4267. {
  4268. Double scaleX = PrimaryScreen.ScaleX;
  4269. Double scaleY = PrimaryScreen.ScaleY;
  4270. //保存页面
  4271. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4272. Graphics g = Graphics.FromImage(bit);
  4273. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4274. SaveFileDialog sf = new SaveFileDialog();
  4275. sf.Title = "页面保存";
  4276. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4277. sf.Filter = "图片|*.png";
  4278. timer_1s.Enabled = false;
  4279. if (sf.ShowDialog() == DialogResult.OK)
  4280. {
  4281. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4282. }
  4283. timer_1s.Enabled = true;
  4284. }
  4285. /// <summary>
  4286. /// 生产模式关机
  4287. /// </summary>
  4288. /// <param name="sender"></param>
  4289. /// <param name="e"></param>
  4290. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4291. {
  4292. var Code_Off = new byte[5];
  4293. var Code_Reset = new byte[5];
  4294. Code_Off[0] = (byte)'O';
  4295. Code_Off[1] = (byte)'F';
  4296. Code_Off[2] = (byte)'F';
  4297. Code_Off[3] = (byte)'.';
  4298. Code_Off[4] = (byte)'.';
  4299. Code_Reset[0] = (byte)'R';
  4300. Code_Reset[1] = (byte)'E';
  4301. Code_Reset[2] = (byte)'S';
  4302. Code_Reset[3] = (byte)'E';
  4303. Code_Reset[4] = (byte)'T';
  4304. timer_1s.Enabled = false;
  4305. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4306. {
  4307. timer_1s.Enabled = true;
  4308. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4309. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4310. PowerOffAckStatus = false;
  4311. Delay_ms(250);
  4312. int TryCnt = 3;
  4313. while ((TryCnt--) >= 0)
  4314. {
  4315. if (!PowerOffAckStatus)
  4316. {
  4317. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4318. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4319. PowerOffAckStatus = false;
  4320. Delay_ms(250);
  4321. }
  4322. else break;
  4323. }
  4324. if (PowerOffAckStatus)
  4325. {
  4326. timer_1s.Enabled = false;
  4327. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4328. timer_1s.Enabled = true;
  4329. }
  4330. else
  4331. {
  4332. timer_1s.Enabled = false;
  4333. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4334. timer_1s.Enabled = true;
  4335. }
  4336. }
  4337. timer_1s.Enabled = true;
  4338. }
  4339. //仪表电源键按下
  4340. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4341. {
  4342. var Code = new byte[2];
  4343. Code[0] = 0;
  4344. Code[1] = 0b00100000;
  4345. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4346. }
  4347. /// <summary>
  4348. /// 仪表加键按下
  4349. /// </summary>
  4350. /// <param name="sender"></param>
  4351. /// <param name="e"></param>
  4352. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4353. {
  4354. var Code = new byte[2];
  4355. Code[0] = 0;
  4356. Code[1] = 0b00010000;
  4357. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4358. }
  4359. /// <summary>
  4360. /// 仪表减键按下
  4361. /// </summary>
  4362. /// <param name="sender"></param>
  4363. /// <param name="e"></param>
  4364. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4365. {
  4366. var Code = new byte[2];
  4367. Code[0] = 0;
  4368. Code[1] = 0b00001000;
  4369. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4370. }
  4371. /// <summary>
  4372. /// 仪表Walk键按下
  4373. /// </summary>
  4374. /// <param name="sender"></param>
  4375. /// <param name="e"></param>
  4376. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4377. {
  4378. var Code = new byte[2];
  4379. Code[0] = 0;
  4380. Code[1] = 0b00000100;
  4381. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4382. }
  4383. /// <summary>
  4384. /// 仪表Light键按下
  4385. /// </summary>
  4386. /// <param name="sender"></param>
  4387. /// <param name="e"></param>
  4388. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4389. {
  4390. var Code = new byte[2];
  4391. Code[0] = 0;
  4392. Code[1] = 0b00000010;
  4393. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4394. }
  4395. /// <summary>
  4396. /// 仪表Set键按下
  4397. /// </summary>
  4398. /// <param name="sender"></param>
  4399. /// <param name="e"></param>
  4400. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4401. {
  4402. var Code = new byte[2];
  4403. Code[0] = 0;
  4404. Code[1] = 0b00000001;
  4405. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4406. }
  4407. /// <summary>
  4408. /// 导出电机故障日志
  4409. /// </summary>
  4410. /// <param name="sender"></param>
  4411. /// <param name="e"></param>
  4412. private void button_ExportLog_Click(object sender, EventArgs e)
  4413. {
  4414. var Address = new byte[4];
  4415. UInt32 Address_Begin;
  4416. UInt32 Addres_End;
  4417. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4418. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4419. richTextBox_Record.Clear();
  4420. textBox_LogAddrBegin.ReadOnly = true;
  4421. textBox_LogAddrEnd.ReadOnly = true;
  4422. if (!mySerialProcess.mySerial.IsOpen)
  4423. {
  4424. timer_1s.Enabled = false;
  4425. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4426. timer_1s.Enabled = true;
  4427. return;
  4428. }
  4429. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4430. {
  4431. timer_1s.Enabled = false;
  4432. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4433. timer_1s.Enabled = true;
  4434. return;
  4435. }
  4436. else
  4437. {
  4438. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4439. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4440. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4441. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4442. if (Addres_End <= Address_Begin)
  4443. {
  4444. timer_1s.Enabled = false;
  4445. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4446. timer_1s.Enabled = true;
  4447. return;
  4448. }
  4449. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4450. {
  4451. timer_1s.Enabled = false;
  4452. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4453. timer_1s.Enabled = true;
  4454. return;
  4455. }
  4456. else
  4457. {
  4458. UInt32 ReadCount = 0;
  4459. button_ExportLog.Text = "导出中...";
  4460. button_ExportLog.Enabled = false;
  4461. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4462. for (ushort i = 0; i < ReadCount; i++)
  4463. {
  4464. var SendByte = new byte[8];
  4465. UInt32 Address_Temp_Begin;
  4466. UInt32 Address_Temp_End;
  4467. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4468. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4469. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4470. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4471. SendByte[3] = (byte)(Address_Temp_Begin);
  4472. Address_Temp_End = Address_Temp_Begin + 127;
  4473. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4474. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4475. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4476. SendByte[7] = (byte)(Address_Temp_End);
  4477. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4478. Delay_ms(200);//Thread.Sleep(200);
  4479. }
  4480. button_ExportLog.Text = "导出日志";
  4481. button_ExportLog.Enabled = true;
  4482. }
  4483. }
  4484. }
  4485. /// <summary>
  4486. /// 保存日志信息
  4487. /// </summary>
  4488. /// <param name="sender"></param>
  4489. /// <param name="e"></param>
  4490. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4491. {
  4492. string SaveInfo = "";
  4493. if (richTextBox_Record.Text == string.Empty)
  4494. {
  4495. timer_1s.Enabled = false;
  4496. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4497. timer_1s.Enabled = true;
  4498. return;
  4499. }
  4500. //获取保存信息
  4501. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4502. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4503. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4504. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4505. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4506. SaveInfo += "\r\n";
  4507. SaveInfo += richTextBox_Record.Text;
  4508. //设置保存路径和文件名
  4509. SaveFileDialog sf = new SaveFileDialog();
  4510. sf.Title = "数据保存";
  4511. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4512. sf.FileName.Replace(" ", "");
  4513. sf.Filter = "日志|*.ttlog";
  4514. if (sf.ShowDialog() == DialogResult.OK)
  4515. {
  4516. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4517. }
  4518. }
  4519. /// <summary>
  4520. /// 双击修改日志起始地址
  4521. /// </summary>
  4522. /// <param name="sender"></param>
  4523. /// <param name="e"></param>
  4524. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4525. {
  4526. textBox_LogAddrBegin.ReadOnly = false;
  4527. }
  4528. /// <summary>
  4529. /// 双击修改日志结束地址
  4530. /// </summary>
  4531. /// <param name="sender"></param>
  4532. /// <param name="e"></param>
  4533. private void label88_DoubleClick(object sender, EventArgs e)
  4534. {
  4535. textBox_LogAddrEnd.ReadOnly = false;
  4536. }
  4537. /// <summary>
  4538. /// 存储器自动读取选择
  4539. /// </summary>
  4540. /// <param name="sender"></param>
  4541. /// <param name="e"></param>
  4542. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4543. {
  4544. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4545. {
  4546. //检查串口是否打开
  4547. if (!mySerialProcess.mySerial.IsOpen)
  4548. {
  4549. timer_1s.Enabled = false;
  4550. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4551. timer_1s.Enabled = true;
  4552. checkBox_ReadRanFlash_AutoSW.Checked = false;
  4553. return;
  4554. }
  4555. }
  4556. }
  4557. /// <summary>
  4558. /// 系统开机按钮
  4559. /// </summary>
  4560. /// <param name="sender"></param>
  4561. /// <param name="e"></param>
  4562. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4563. {
  4564. byte[] Data = new byte[1];
  4565. Data[0] = 0xF1;
  4566. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4567. }
  4568. /// <summary>
  4569. /// 系统关机按钮
  4570. /// </summary>
  4571. /// <param name="sender"></param>
  4572. /// <param name="e"></param>
  4573. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4574. {
  4575. byte[] Data = new byte[1];
  4576. Data[0] = 0xF0;
  4577. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4578. }
  4579. /// <summary>
  4580. /// 连接开机选择
  4581. /// </summary>
  4582. /// <param name="sender"></param>
  4583. /// <param name="e"></param>
  4584. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4585. {
  4586. //输入用户名
  4587. EnterForm1.ShowDialog();
  4588. try
  4589. {
  4590. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4591. {
  4592. if (EnterForm1.comboBox_User.Text == "管理员")
  4593. {
  4594. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  4595. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4596. }
  4597. else
  4598. {
  4599. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4600. }
  4601. }
  4602. else
  4603. {
  4604. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4605. }
  4606. }
  4607. catch (Exception)
  4608. {
  4609. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4610. }
  4611. }
  4612. /// <summary>
  4613. /// 断开关机选择
  4614. /// </summary>
  4615. /// <param name="sender"></param>
  4616. /// <param name="e"></param>
  4617. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4618. {
  4619. //输入用户名
  4620. EnterForm1.ShowDialog();
  4621. try
  4622. {
  4623. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4624. {
  4625. if (EnterForm1.comboBox_User.Text == "管理员")
  4626. {
  4627. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  4628. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4629. }
  4630. else
  4631. {
  4632. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4633. }
  4634. }
  4635. else
  4636. {
  4637. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4638. }
  4639. }
  4640. catch (Exception)
  4641. {
  4642. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4643. }
  4644. }
  4645. /// <summary>
  4646. /// 识别通讯盒选择
  4647. /// </summary>
  4648. /// <param name="sender"></param>
  4649. /// <param name="e"></param>
  4650. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  4651. {
  4652. //输入用户名
  4653. EnterForm1.ShowDialog();
  4654. try
  4655. {
  4656. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4657. {
  4658. if (EnterForm1.comboBox_User.Text == "管理员")
  4659. {
  4660. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  4661. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4662. }
  4663. else
  4664. {
  4665. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4666. }
  4667. }
  4668. else
  4669. {
  4670. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4671. }
  4672. }
  4673. catch (Exception)
  4674. {
  4675. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4676. }
  4677. }
  4678. /// <summary>
  4679. /// 将配置信息导出为cfg文件
  4680. /// </summary>
  4681. private void ConfigFileSave(bool DeleteFlag, string FileName)
  4682. {
  4683. if (DeleteFlag)
  4684. {
  4685. if (File.Exists(FileName))
  4686. File.Delete(FileName);
  4687. }
  4688. string CfgFileInfo = "";
  4689. CfgFileInfo += "[PortSet]" + "\r\n";
  4690. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  4691. CfgFileInfo += "PortBaudrate:" + toolStripComboBox_Baudrate.Text + "\r\n";
  4692. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4693. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4694. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  4695. CfgFileInfo += "\r\n";
  4696. CfgFileInfo += "[Option]" + "\r\n";
  4697. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  4698. CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
  4699. CfgFileInfo += "\r\n";
  4700. CfgFileInfo += "[ServerSet]" + "\r\n";
  4701. CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
  4702. CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
  4703. CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
  4704. CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
  4705. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  4706. CfgFileInfo += "\r\n";
  4707. CfgFileInfo += "[MacInfo]" + "\r\n";
  4708. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  4709. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  4710. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  4711. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  4712. CfgFileInfo += "\r\n";
  4713. CfgFileInfo += "[LogAddress]" + "\r\n";
  4714. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  4715. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  4716. CfgFileInfo += "\r\n";
  4717. CfgFileInfo += "[MotorType]" + "\r\n";
  4718. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4719. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4720. CfgFileInfo += "\r\n";
  4721. CfgFileInfo += "[CheckValue]" + "\r\n";
  4722. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  4723. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  4724. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  4725. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  4726. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  4727. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  4728. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  4729. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  4730. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  4731. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  4732. }
  4733. /// <summary>
  4734. /// 配置状态更新,点击时保存
  4735. /// </summary>
  4736. private void ConfigFileSave_Click(object sender, EventArgs e)
  4737. {
  4738. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4739. }
  4740. /// <summary>
  4741. /// 文本框修改结束,回车保存
  4742. /// </summary>
  4743. /// <param name="sender"></param>
  4744. /// <param name="e"></param>
  4745. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  4746. {
  4747. if (e.KeyCode == Keys.Enter)
  4748. {
  4749. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4750. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4751. }
  4752. }
  4753. /// <summary>
  4754. /// 允许离线使用
  4755. /// </summary>
  4756. /// <param name="sender"></param>
  4757. /// <param name="e"></param>
  4758. private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
  4759. {
  4760. //输入用户名
  4761. EnterForm1.ShowDialog();
  4762. try
  4763. {
  4764. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4765. {
  4766. if (EnterForm1.comboBox_User.Text == "管理员")
  4767. {
  4768. 允许ToolStripMenuItem.Checked = true;
  4769. 不允许ToolStripMenuItem.Checked = false;
  4770. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4771. }
  4772. else
  4773. {
  4774. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4775. 允许ToolStripMenuItem.Checked = false;
  4776. 不允许ToolStripMenuItem.Checked = true;
  4777. }
  4778. }
  4779. else
  4780. {
  4781. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4782. 允许ToolStripMenuItem.Checked = false;
  4783. 不允许ToolStripMenuItem.Checked = true;
  4784. }
  4785. }
  4786. catch (Exception)
  4787. {
  4788. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4789. 允许ToolStripMenuItem.Checked = false;
  4790. 不允许ToolStripMenuItem.Checked = true;
  4791. }
  4792. }
  4793. /// <summary>
  4794. /// 不允许离线使用
  4795. /// </summary>
  4796. /// <param name="sender"></param>
  4797. /// <param name="e"></param>
  4798. private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
  4799. {
  4800. 允许ToolStripMenuItem.Checked = false;
  4801. 不允许ToolStripMenuItem.Checked = true;
  4802. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4803. }
  4804. /// <summary>
  4805. /// 弹出扫码按钮
  4806. /// </summary>
  4807. /// <param name="sender"></param>
  4808. /// <param name="e"></param>
  4809. private void button_ScanCode_Click(object sender, EventArgs e)
  4810. {
  4811. Scan scan_form = new Scan();
  4812. scan_form.ShowDialog();
  4813. do
  4814. {
  4815. if (scan_form.textBox_Scan.Text == string.Empty)
  4816. {
  4817. timer_1s.Enabled = false;
  4818. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4819. timer_1s.Enabled = true;
  4820. break;
  4821. }
  4822. string ScanInfo = scan_form.textBox_Scan.Text.Replace(" ", "");
  4823. string regexInfo = "";
  4824. string[] InfoList = { "" };
  4825. try
  4826. {
  4827. if (中置电机ToolStripMenuItem.Checked == true)
  4828. {
  4829. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  4830. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  4831. }
  4832. else if (轮毂电机ToolStripMenuItem.Checked == true)
  4833. {
  4834. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  4835. string Model = InfoList[0];
  4836. string Spec = InfoList[1];
  4837. string Sn = InfoList[2];
  4838. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  4839. InfoList[1] = Sn;
  4840. }
  4841. }
  4842. catch (Exception)
  4843. {
  4844. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4845. return;
  4846. }
  4847. if (InfoList.Length >= 2)
  4848. {
  4849. //写入型号
  4850. textBox_FacModeName.Text = InfoList[0];
  4851. string Mode = textBox_FacModeName.Text;
  4852. var ModeArray = new byte[16];
  4853. for (ushort i = 0; i < Mode.Length; i++)
  4854. {
  4855. ModeArray[i] = (byte)Mode[i];
  4856. }
  4857. if (Mode.Length < 16)
  4858. {
  4859. ModeArray[Mode.Length] = (byte)'.';
  4860. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4861. {
  4862. ModeArray[Mode.Length + 1 + i] = 0x20;
  4863. }
  4864. }
  4865. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4866. //写入SN
  4867. textBox_FacModeNum.Text = InfoList[1];
  4868. string SN = textBox_FacModeNum.Text;
  4869. var SNArray = new byte[16];
  4870. for (ushort i = 0; i < SN.Length; i++)
  4871. {
  4872. SNArray[i] = (byte)SN[i];
  4873. }
  4874. if (SN.Length < 16)
  4875. {
  4876. SNArray[SN.Length] = (byte)'.';
  4877. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4878. {
  4879. SNArray[SN.Length + 1 + i] = 0x20;
  4880. }
  4881. }
  4882. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4883. }
  4884. else
  4885. {
  4886. timer_1s.Enabled = false;
  4887. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4888. timer_1s.Enabled = true;
  4889. break;
  4890. }
  4891. } while (false);
  4892. scan_form.Dispose();
  4893. }
  4894. private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
  4895. {
  4896. //输入用户名
  4897. EnterForm1.ShowDialog();
  4898. try
  4899. {
  4900. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4901. {
  4902. if (EnterForm1.comboBox_User.Text == "管理员")
  4903. {
  4904. IP地址ToolStripMenuItem.Visible = true;
  4905. 端口ToolStripMenuItem.Visible = true;
  4906. 用户名ToolStripMenuItem.Visible = true;
  4907. 密码ToolStripMenuItem.Visible = true;
  4908. 存储路径ToolStripMenuItem.Visible = true;
  4909. }
  4910. else
  4911. {
  4912. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4913. IP地址ToolStripMenuItem.Visible = false;
  4914. 端口ToolStripMenuItem.Visible = false;
  4915. 用户名ToolStripMenuItem.Visible = false;
  4916. 密码ToolStripMenuItem.Visible = false;
  4917. 存储路径ToolStripMenuItem.Visible = false;
  4918. }
  4919. }
  4920. else
  4921. {
  4922. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4923. IP地址ToolStripMenuItem.Visible = false;
  4924. 端口ToolStripMenuItem.Visible = false;
  4925. 用户名ToolStripMenuItem.Visible = false;
  4926. 密码ToolStripMenuItem.Visible = false;
  4927. 存储路径ToolStripMenuItem.Visible = false;
  4928. }
  4929. }
  4930. catch (Exception)
  4931. {
  4932. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4933. IP地址ToolStripMenuItem.Visible = false;
  4934. 端口ToolStripMenuItem.Visible = false;
  4935. 用户名ToolStripMenuItem.Visible = false;
  4936. 密码ToolStripMenuItem.Visible = false;
  4937. 存储路径ToolStripMenuItem.Visible = false;
  4938. }
  4939. }
  4940. private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
  4941. {
  4942. //输入用户名
  4943. EnterForm1.ShowDialog();
  4944. try
  4945. {
  4946. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4947. {
  4948. if (EnterForm1.comboBox_User.Text == "管理员")
  4949. {
  4950. 生产商ToolStripMenuItem.Visible = true;
  4951. 生产地ToolStripMenuItem.Visible = true;
  4952. 生产日期ToolStripMenuItem.Visible = true;
  4953. 产品标识ToolStripMenuItem.Visible = true;
  4954. }
  4955. else
  4956. {
  4957. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4958. 生产商ToolStripMenuItem.Visible = false;
  4959. 生产地ToolStripMenuItem.Visible = false;
  4960. 生产日期ToolStripMenuItem.Visible = false;
  4961. 产品标识ToolStripMenuItem.Visible = false;
  4962. }
  4963. }
  4964. else
  4965. {
  4966. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4967. 生产商ToolStripMenuItem.Visible = false;
  4968. 生产地ToolStripMenuItem.Visible = false;
  4969. 生产日期ToolStripMenuItem.Visible = false;
  4970. 产品标识ToolStripMenuItem.Visible = false;
  4971. }
  4972. }
  4973. catch (Exception)
  4974. {
  4975. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4976. 生产商ToolStripMenuItem.Visible = false;
  4977. 生产地ToolStripMenuItem.Visible = false;
  4978. 生产日期ToolStripMenuItem.Visible = false;
  4979. 产品标识ToolStripMenuItem.Visible = false;
  4980. }
  4981. }
  4982. /// <summary>
  4983. /// 切换电机类型
  4984. /// </summary>
  4985. /// <param name="sender"></param>
  4986. /// <param name="e"></param>
  4987. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  4988. {
  4989. 中置电机ToolStripMenuItem.Checked = true;
  4990. 轮毂电机ToolStripMenuItem.Checked = false;
  4991. toolStripTextBox_MACPD.Text = "MM_MC1";
  4992. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  4993. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4994. }
  4995. /// <summary>
  4996. /// 切换电机类型
  4997. /// </summary>
  4998. /// <param name="sender"></param>
  4999. /// <param name="e"></param>
  5000. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5001. {
  5002. 中置电机ToolStripMenuItem.Checked = false;
  5003. 轮毂电机ToolStripMenuItem.Checked = true;
  5004. toolStripTextBox_MACPD.Text = "GF_250_1";
  5005. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5006. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5007. }
  5008. /// <summary>
  5009. /// 获取配置文件日期
  5010. /// </summary>
  5011. /// <param name="DisAll"></param>
  5012. private void GetDateList(bool DisAll)
  5013. {
  5014. string[] DateList = { "" };
  5015. //从服务器更新日期列表
  5016. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5017. {
  5018. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5019. }
  5020. //从本地更新日期列表
  5021. else
  5022. {
  5023. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5024. }
  5025. comboBox_FacModeCfgDate.Items.Clear();
  5026. comboBox_CheckModeCfgDate.Items.Clear();
  5027. //日期列表加载
  5028. if (DisAll == true)
  5029. {
  5030. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5031. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5032. comboBox_FacModeCfgDate.Items.Add("---");
  5033. comboBox_CheckModeCfgDate.Items.Add("---");
  5034. foreach (var file in DateList)
  5035. {
  5036. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5037. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5038. }
  5039. }
  5040. else
  5041. {
  5042. if (DateList.Length > 10)
  5043. {
  5044. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5045. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5046. comboBox_FacModeCfgDate.Items.Add("---");
  5047. comboBox_CheckModeCfgDate.Items.Add("---");
  5048. }
  5049. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5050. {
  5051. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5052. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5053. }
  5054. }
  5055. }
  5056. /// <summary>
  5057. /// 获取配置文件列表
  5058. /// </summary>
  5059. /// <param name="date"></param>
  5060. private void GetFileListFrom(string date)
  5061. {
  5062. string[] FileList = { "" };
  5063. //从服务器更新文件列表
  5064. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5065. {
  5066. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5067. }
  5068. else
  5069. {
  5070. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5071. }
  5072. comboBox_CheckModeCfgFile.Items.Clear();
  5073. comboBox_FacModeCfgFile.Items.Clear();
  5074. foreach (var file in FileList)
  5075. {
  5076. if (file.Contains(".ttcfg"))
  5077. {
  5078. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5079. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5080. }
  5081. }
  5082. }
  5083. /// <summary>
  5084. /// 检验模式选择文件日期
  5085. /// </summary>
  5086. /// <param name="sender"></param>
  5087. /// <param name="e"></param>
  5088. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5089. {
  5090. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5091. {
  5092. GetDateList(true);
  5093. }
  5094. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5095. {
  5096. GetDateList(false);
  5097. }
  5098. else
  5099. {
  5100. comboBox_CheckModeCfgFile.Text = "";
  5101. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5102. }
  5103. }
  5104. /// <summary>
  5105. /// 配置模式选择文件日期
  5106. /// </summary>
  5107. /// <param name="sender"></param>
  5108. /// <param name="e"></param>
  5109. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5110. {
  5111. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5112. {
  5113. GetDateList(true);
  5114. }
  5115. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5116. {
  5117. GetDateList(false);
  5118. }
  5119. else
  5120. {
  5121. comboBox_FacModeCfgFile.Text = "";
  5122. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5123. }
  5124. }
  5125. /// <summary>
  5126. /// 选中量产模式
  5127. /// </summary>
  5128. /// <param name="sender"></param>
  5129. /// <param name="e"></param>
  5130. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5131. {
  5132. //更新生产配置文件目录
  5133. GetDateList(false);
  5134. }
  5135. /// <summary>
  5136. /// 量产测试结束
  5137. /// </summary>
  5138. /// <param name=""></param>
  5139. private void FacMode_Stop(bool OK_Flag)
  5140. {
  5141. //打开开始按钮
  5142. button__FacMode_Start.Enabled = true;
  5143. //系统关机
  5144. var Code = new byte[32];//发送的指令数据
  5145. Code[0] = 0xF0;
  5146. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5147. //关闭串口
  5148. mySerialProcess.SerialClose(false);
  5149. //路径设置
  5150. string LocalSavePath = "";
  5151. string ServerSavePath = "";
  5152. if (OK_Flag)
  5153. {
  5154. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5155. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5156. }
  5157. else
  5158. {
  5159. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5160. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5161. }
  5162. if (Directory.Exists(LocalSavePath) == false)
  5163. {
  5164. Directory.CreateDirectory(LocalSavePath);
  5165. }
  5166. //保存和上传
  5167. string LogSavePath = "";
  5168. string LogSaveFileName = "";
  5169. string ProductInfo = textBox_FacModeScan.Text;
  5170. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5171. if (Directory.Exists(LogSavePath) == false)
  5172. {
  5173. Directory.CreateDirectory(LogSavePath);
  5174. }
  5175. //测试页面
  5176. Double scaleX = PrimaryScreen.ScaleX;
  5177. Double scaleY = PrimaryScreen.ScaleY;
  5178. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5179. Graphics g = Graphics.FromImage(bit);
  5180. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5181. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5182. bit.Save(LogSaveFileName);
  5183. //上传测试页面到服务器
  5184. if (myFtp.IsNetConnected == true)
  5185. {
  5186. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5187. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5188. {
  5189. myFtp.MakeDir(ServerSavePath + DateNow);
  5190. }
  5191. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5192. {
  5193. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5194. }
  5195. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5196. if (result == true)
  5197. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5198. }
  5199. else
  5200. {
  5201. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5202. }
  5203. //测试记录
  5204. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5205. string file_str = "";
  5206. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5207. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5208. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5209. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5210. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5211. //上传测试记录到服务器
  5212. if (myFtp.IsNetConnected == true)
  5213. {
  5214. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5215. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5216. {
  5217. myFtp.MakeDir(ServerSavePath + DateNow);
  5218. }
  5219. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5220. {
  5221. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5222. }
  5223. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5224. if (result == true)
  5225. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5226. }
  5227. else
  5228. {
  5229. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5230. }
  5231. //扫码框清空
  5232. textBox_FacModeScan.Text = "";
  5233. }
  5234. /// <summary>
  5235. /// 量产测试开始
  5236. /// </summary>
  5237. /// <param name="sender"></param>
  5238. /// <param name="e"></param>
  5239. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5240. {
  5241. //关闭测试项目编辑
  5242. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5243. foreach (Control c in groupBox2.Controls)
  5244. {
  5245. if (c is CheckBox)
  5246. c.Enabled = false;
  5247. }
  5248. WriteLockStatus = true;
  5249. //检查配置文件
  5250. if (comboBox_FacModeCfgFile.Text == "")
  5251. {
  5252. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5253. return;
  5254. }
  5255. //开始测试
  5256. TestStart();
  5257. }
  5258. /// <summary>
  5259. /// 测试子函数
  5260. /// </summary>
  5261. private void TestStart()
  5262. {
  5263. //初始化标签
  5264. FacModelLabelInit();
  5265. richTextBox_FacModeLog.Clear();
  5266. //按钮禁止操作
  5267. button__FacMode_Start.Enabled = false;
  5268. //记录配置文件
  5269. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5270. //检查打标信息格式
  5271. label_FacModeStatus.Text = "检查扫码信息";
  5272. Delay_ms(500);
  5273. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5274. if (textBox_FacModeScan.Text == string.Empty)
  5275. {
  5276. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5277. return;
  5278. }
  5279. try
  5280. {
  5281. if (中置电机ToolStripMenuItem.Checked == true)
  5282. {
  5283. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5284. {
  5285. label_FacModeStatus.Text = "存在故障!";
  5286. label_FacModeResult.BackColor = Color.Red;
  5287. label_FacModeResult.Text = "标签格式错误";
  5288. button__FacMode_Start.Enabled = true;
  5289. return;
  5290. }
  5291. }
  5292. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5293. {
  5294. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5295. {
  5296. label_FacModeStatus.Text = "存在故障!";
  5297. label_FacModeResult.BackColor = Color.Red;
  5298. label_FacModeResult.Text = "标签格式错误";
  5299. button__FacMode_Start.Enabled = true;
  5300. return;
  5301. }
  5302. }
  5303. }
  5304. catch (System.Exception)
  5305. {
  5306. label_FacModeStatus.Text = "存在故障!";
  5307. label_FacModeResult.BackColor = Color.Red;
  5308. label_FacModeResult.Text = "标签格式错误";
  5309. button__FacMode_Start.Enabled = true;
  5310. return;
  5311. }
  5312. //打开串口
  5313. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5314. if (!mySerialProcess.mySerial.IsOpen)
  5315. {
  5316. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5317. return;
  5318. }
  5319. //流水号计数
  5320. //...
  5321. //创建线程,执行测试任务
  5322. Thread th = new Thread(FacModeTest_Task);
  5323. th.Start();
  5324. }
  5325. /// <summary>
  5326. /// 执行一次测试任务
  5327. /// </summary>
  5328. private void FacModeTest_Task()
  5329. {
  5330. //开始测试
  5331. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5332. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5333. //变量定义
  5334. var Code = new byte[255];//发送的指令数据
  5335. label_FacModeStatus.Text = "开始测试";
  5336. Delay_ms(500);
  5337. label_FacModeStatus.Text = "系统开机";
  5338. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  5339. BootInfo = "";
  5340. Code[0] = 0xF0;
  5341. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5342. Delay_ms(1500);
  5343. Code[0] = 0xF1;
  5344. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5345. ACK_WaitCnt = 0;
  5346. while (ACK_WaitCnt <= 2); //1s
  5347. //检查BOOT版本
  5348. if (BootInfo != string.Empty)
  5349. {
  5350. label_FacModeBootVer.BackColor = Color.Green;
  5351. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5352. Delay_ms(500);
  5353. }
  5354. else
  5355. {
  5356. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5357. label_FacModeStatus.Text = "存在故障!";
  5358. label_FacModeResult.BackColor = Color.Red;
  5359. label_FacModeResult.Text = "测试异常";
  5360. Delay_ms(500);
  5361. //存储异常并上传
  5362. FacMode_Stop(false);
  5363. return;
  5364. }
  5365. //系统清除
  5366. if (checkBox_FacModeSysClear.Checked)
  5367. {
  5368. do
  5369. {
  5370. //发送系统清除指令
  5371. label_FacModeStatus.Text = "系统清除";
  5372. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5373. Code[0] = (byte)'C';
  5374. Code[1] = (byte)'L';
  5375. Code[2] = (byte)'E';
  5376. Code[3] = (byte)'A';
  5377. Code[4] = (byte)'R';
  5378. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5379. WriteACK = false;
  5380. WriteCnt = 0;
  5381. ACK_WaitCnt = 0;
  5382. while (ACK_WaitCnt <= 6); //3s
  5383. //等待系统清除完成指令
  5384. if (WriteACK == true)
  5385. {
  5386. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5387. label_FacModeSysClear.BackColor = Color.Green;
  5388. }
  5389. else
  5390. {
  5391. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5392. label_FacModeStatus.Text = "存在故障!";
  5393. label_FacModeResult.BackColor = Color.Red;
  5394. label_FacModeResult.Text = "测试异常";
  5395. Delay_ms(500);
  5396. //存储异常并上传
  5397. FacMode_Stop(false);
  5398. return;
  5399. }
  5400. //系统重新开机
  5401. label_FacModeStatus.Text = "重新开机";
  5402. BootInfo = "";
  5403. Code[0] = 0xF1;
  5404. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5405. ACK_WaitCnt = 0;
  5406. while (ACK_WaitCnt <= 4); //2s
  5407. //获取Boot版本信息
  5408. if (BootInfo != string.Empty)
  5409. {
  5410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5411. }
  5412. else
  5413. {
  5414. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5415. label_FacModeStatus.Text = "存在故障!";
  5416. label_FacModeResult.BackColor = Color.Red;
  5417. label_FacModeResult.Text = "测试异常";
  5418. Delay_ms(500);
  5419. //存储异常并上传
  5420. FacMode_Stop(false);
  5421. return;
  5422. }
  5423. } while (false);
  5424. }
  5425. else
  5426. {
  5427. label_FacModeSysClear.BackColor = Color.Yellow;
  5428. label_FacModeStatus.Text = "跳过系统清除!";
  5429. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5430. Delay_ms(500);
  5431. }
  5432. //检查是否有故障
  5433. if (textBox_ErrorCode.Text.Contains("H"))
  5434. {
  5435. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5436. label_FacModeStatus.Text = "电机存在故障!";
  5437. label_FacModeResult.BackColor = Color.Red;
  5438. label_FacModeResult.Text = "测试异常";
  5439. Delay_ms(500);
  5440. //存储异常并上传
  5441. FacMode_Stop(false);
  5442. return;
  5443. }
  5444. //参数写入
  5445. if (checkBox_FacModeCfgWrite.Checked)
  5446. {
  5447. label_FacModeStatus.Text = "参数写入";
  5448. //写入产品型号和SN
  5449. do
  5450. {
  5451. //根据扫码信息获取型号和SN
  5452. string ScanInfo = textBox_FacModeScan.Text;
  5453. string regexInfo = "";
  5454. string[] InfoList = { "" };
  5455. try
  5456. {
  5457. if (中置电机ToolStripMenuItem.Checked == true)
  5458. {
  5459. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5460. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  5461. }
  5462. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5463. {
  5464. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5465. string Model = InfoList[0];
  5466. string Spec = InfoList[1];
  5467. string Sn = InfoList[2];
  5468. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5469. InfoList[1] = Sn;
  5470. }
  5471. }
  5472. catch
  5473. {
  5474. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  5475. label_FacModeStatus.Text = "存在故障!";
  5476. label_FacModeResult.BackColor = Color.Red;
  5477. label_FacModeResult.Text = "标签格式错误";
  5478. Delay_ms(500);
  5479. //存储异常并上传
  5480. FacMode_Stop(false);
  5481. return;
  5482. }
  5483. if (InfoList.Length >= 2)
  5484. {
  5485. //检查配置文件是否与打标信息一致
  5486. //...
  5487. //写入型号
  5488. label_FacModeStatus.Text = "写入型号";
  5489. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  5490. textBox_FacModeName.Text = InfoList[0];
  5491. string Mode = textBox_FacModeName.Text;
  5492. var ModeArray = new byte[16];
  5493. for (ushort i = 0; i < Mode.Length; i++)
  5494. {
  5495. ModeArray[i] = (byte)Mode[i];
  5496. }
  5497. if (Mode.Length < 16)
  5498. {
  5499. ModeArray[Mode.Length] = (byte)'.';
  5500. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5501. {
  5502. ModeArray[Mode.Length + 1 + i] = 0x20;
  5503. }
  5504. }
  5505. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5506. WriteACK = false;
  5507. WriteCnt = 0;
  5508. ACK_WaitCnt = 0;
  5509. while (ACK_WaitCnt <= 2); //1s
  5510. if (WriteACK == true)
  5511. {
  5512. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  5513. }
  5514. else
  5515. {
  5516. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  5517. label_FacModeStatus.Text = "存在故障!";
  5518. label_FacModeResult.BackColor = Color.Red;
  5519. label_FacModeResult.Text = "测试异常";
  5520. Delay_ms(500);
  5521. //存储异常并上传
  5522. FacMode_Stop(false);
  5523. return;
  5524. }
  5525. //写入SN
  5526. label_FacModeStatus.Text = "写入SN";
  5527. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  5528. textBox_FacModeNum.Text = InfoList[1];
  5529. string SN = textBox_FacModeNum.Text;
  5530. var SNArray = new byte[16];
  5531. for (ushort i = 0; i < SN.Length; i++)
  5532. {
  5533. SNArray[i] = (byte)SN[i];
  5534. }
  5535. if (SN.Length < 16)
  5536. {
  5537. SNArray[SN.Length] = (byte)'.';
  5538. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5539. {
  5540. SNArray[SN.Length + 1 + i] = 0x20;
  5541. }
  5542. }
  5543. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5544. WriteACK = false;
  5545. WriteCnt = 0;
  5546. ACK_WaitCnt = 0;
  5547. while (ACK_WaitCnt <= 2); //1s
  5548. if (WriteACK == true)
  5549. {
  5550. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  5551. }
  5552. else
  5553. {
  5554. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  5555. label_FacModeStatus.Text = "存在故障!";
  5556. label_FacModeResult.BackColor = Color.Red;
  5557. label_FacModeResult.Text = "测试异常";
  5558. Delay_ms(500);
  5559. //存储异常并上传
  5560. FacMode_Stop(false);
  5561. return;
  5562. }
  5563. }
  5564. else
  5565. {
  5566. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5567. return;
  5568. }
  5569. } while (false);
  5570. //写入配置文件
  5571. do
  5572. {
  5573. label_FacModeStatus.Text = "写入配置文件";
  5574. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  5575. //配置文件
  5576. List<byte[]> CmdList = new List<byte[]>();
  5577. //从服务器下载文件
  5578. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5579. {
  5580. string SelectFile = "";
  5581. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  5582. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  5583. {
  5584. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  5585. }
  5586. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  5587. //打开文件
  5588. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  5589. CmdList.Clear();
  5590. while (streamReader.Peek() != -1)
  5591. {
  5592. string fileLineInfo = streamReader.ReadLine();
  5593. if (fileLineInfo.IndexOf("[") != -1)
  5594. {
  5595. continue;
  5596. }
  5597. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  5598. }
  5599. streamReader.Close();
  5600. }
  5601. //加载本地文件
  5602. else
  5603. {
  5604. string SelectFile = "";
  5605. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  5606. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  5607. CmdList.Clear();
  5608. while (streamReader.Peek() != -1)
  5609. {
  5610. string fileLineInfo = streamReader.ReadLine();
  5611. if (fileLineInfo.IndexOf("[") != -1)
  5612. {
  5613. continue;
  5614. }
  5615. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  5616. }
  5617. streamReader.Close();
  5618. }
  5619. int CmdNum = CmdList.Count(); //指令个数
  5620. Delay_ms(500);
  5621. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  5622. Delay_ms(500);
  5623. //开始写入
  5624. WriteCnt = 0;
  5625. for (int i = 0; i < CmdList.Count; i++)
  5626. {
  5627. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  5628. Thread.Sleep(200);
  5629. }
  5630. //判断写入是否完整
  5631. if (CmdNum == WriteCnt)
  5632. {
  5633. label_FacMode_CfgWrite.BackColor = Color.Green;
  5634. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  5635. Delay_ms(500);
  5636. }
  5637. else
  5638. {
  5639. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败" + "\r\n");
  5640. label_FacModeStatus.Text = "存在故障!";
  5641. label_FacModeResult.BackColor = Color.Red;
  5642. label_FacModeResult.Text = "测试异常";
  5643. Delay_ms(500);
  5644. //存储异常并上传
  5645. FacMode_Stop(false);
  5646. return;
  5647. }
  5648. } while (false);
  5649. }
  5650. else
  5651. {
  5652. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  5653. label_FacModeStatus.Text = "跳过参数写入!";
  5654. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  5655. Delay_ms(500);
  5656. }
  5657. //BMS通讯
  5658. if (checkBox_FacModeBMS.Checked)
  5659. {
  5660. if (label_FacModeBMS.BackColor == Color.Red)
  5661. {
  5662. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  5663. label_FacModeStatus.Text = "存在故障!";
  5664. label_FacModeResult.BackColor = Color.Red;
  5665. label_FacModeResult.Text = "测试异常";
  5666. Delay_ms(500);
  5667. //存储异常并上传
  5668. FacMode_Stop(false);
  5669. return;
  5670. }
  5671. }
  5672. else
  5673. {
  5674. label_FacModeBMS.BackColor = Color.Yellow;
  5675. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  5676. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  5677. Delay_ms(500);
  5678. }
  5679. //基础功能检测
  5680. if (checkBox_FacBaseFucTest.Checked)
  5681. {
  5682. label_FacModeStatus.Text = "基础功能检测";
  5683. //发送指令进入配置模式
  5684. do
  5685. {
  5686. Code[0] = 0x01;
  5687. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5688. WriteACK = false;
  5689. WriteCnt = 0;
  5690. ACK_WaitCnt = 0;
  5691. while (ACK_WaitCnt <= 2); //1s
  5692. if (textBox_RunInfo_Vol.Text != "---")
  5693. {
  5694. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5695. }
  5696. else
  5697. {
  5698. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  5699. label_FacModeStatus.Text = "存在故障!";
  5700. label_FacModeResult.BackColor = Color.Red;
  5701. label_FacModeResult.Text = "测试异常";
  5702. Delay_ms(500);
  5703. //存储异常并上传
  5704. FacMode_Stop(false);
  5705. return;
  5706. }
  5707. } while (false);
  5708. //发送指令启动电机
  5709. do
  5710. {
  5711. //发送指令读取调试信息
  5712. richTextBox_DebugParam.Clear();
  5713. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  5714. WriteACK = false;
  5715. WriteCnt = 0;
  5716. ACK_WaitCnt = 0;
  5717. while (ACK_WaitCnt <= 2); //1s
  5718. //获取调试信息
  5719. string DebugDefaultInfo = "";
  5720. if (richTextBox_DebugParam.Text == string.Empty)
  5721. {
  5722. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  5723. label_FacModeStatus.Text = "存在故障!";
  5724. label_FacModeResult.BackColor = Color.Red;
  5725. label_FacModeResult.Text = "测试异常";
  5726. Delay_ms(500);
  5727. //存储异常并上传
  5728. FacMode_Stop(false);
  5729. return;
  5730. }
  5731. else
  5732. {
  5733. DebugDefaultInfo = richTextBox_DebugParam.Text;
  5734. }
  5735. //设置模式
  5736. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  5737. strDataTemp[0] = "整体运行模式=3";
  5738. //发送数据
  5739. Code[0] = 0;
  5740. Code[1] = 0;
  5741. for (int i = 0; i < strDataTemp.Length; i++)
  5742. {
  5743. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  5744. Code[2 * i + 2] = (byte)uwDataTemp;
  5745. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  5746. }
  5747. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  5748. label_FacModeStatus.Text = "启动电机";
  5749. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  5750. //设置转速100%
  5751. var Data = new byte[1];
  5752. Data[0] = (byte)100;
  5753. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  5754. Delay_ms(3000);
  5755. } while (false);
  5756. //判断车速
  5757. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  5758. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  5759. {
  5760. label_FacModeSpeed.BackColor = Color.Green;
  5761. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  5762. }
  5763. else
  5764. {
  5765. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\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. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  5776. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  5777. {
  5778. label_FacModeVolTest.BackColor = Color.Green;
  5779. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  5780. }
  5781. else
  5782. {
  5783. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  5784. label_FacModeStatus.Text = "存在故障!";
  5785. label_FacModeResult.BackColor = Color.Red;
  5786. label_FacModeResult.Text = "测试异常";
  5787. Delay_ms(500);
  5788. //存储异常并上传
  5789. FacMode_Stop(false);
  5790. return;
  5791. }
  5792. //判断电流
  5793. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  5794. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  5795. {
  5796. label_FacModeCurrentTest.BackColor = Color.Green;
  5797. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  5798. }
  5799. else
  5800. {
  5801. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  5802. label_FacModeStatus.Text = "存在故障!";
  5803. label_FacModeResult.BackColor = Color.Red;
  5804. label_FacModeResult.Text = "测试异常";
  5805. Delay_ms(500);
  5806. //存储异常并上传
  5807. FacMode_Stop(false);
  5808. return;
  5809. }
  5810. //判断温度
  5811. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  5812. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  5813. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  5814. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  5815. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  5816. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  5817. {
  5818. label_FacModeNTC.BackColor = Color.Green;
  5819. 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");
  5820. }
  5821. else
  5822. {
  5823. 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");
  5824. label_FacModeStatus.Text = "存在故障!";
  5825. label_FacModeResult.BackColor = Color.Red;
  5826. label_FacModeResult.Text = "测试异常";
  5827. Delay_ms(500);
  5828. //存储异常并上传
  5829. FacMode_Stop(false);
  5830. return;
  5831. }
  5832. //判断转速
  5833. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  5834. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  5835. {
  5836. label_FacModeMotorSpeed.BackColor = Color.Green;
  5837. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  5838. }
  5839. else
  5840. {
  5841. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  5842. label_FacModeStatus.Text = "存在故障!";
  5843. label_FacModeResult.BackColor = Color.Red;
  5844. label_FacModeResult.Text = "测试异常";
  5845. Delay_ms(500);
  5846. //存储异常并上传
  5847. FacMode_Stop(false);
  5848. return;
  5849. }
  5850. //发送指令停止电机
  5851. do
  5852. {
  5853. //设置转速0%
  5854. var Data = new byte[1];
  5855. Data[0] = (byte)0;
  5856. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  5857. //获取调试信息
  5858. string DebugDefaultInfo = "";
  5859. if (richTextBox_DebugParam.Text == string.Empty)
  5860. {
  5861. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\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. else
  5871. {
  5872. DebugDefaultInfo = richTextBox_DebugParam.Text;
  5873. }
  5874. //设置模式
  5875. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  5876. //发送数据
  5877. Code[0] = 0;
  5878. Code[1] = 0;
  5879. for (int i = 0; i < strDataTemp.Length; i++)
  5880. {
  5881. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  5882. Code[2 * i + 2] = (byte)uwDataTemp;
  5883. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  5884. }
  5885. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  5886. label_FacModeStatus.Text = "停止电机";
  5887. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  5888. Delay_ms(2000);
  5889. } while (false);
  5890. }
  5891. else
  5892. {
  5893. label_FacModeSpeed.BackColor = Color.Yellow;
  5894. label_FacModeVolTest.BackColor = Color.Yellow;
  5895. label_FacModeCurrentTest.BackColor = Color.Yellow;
  5896. label_FacModeNTC.BackColor = Color.Yellow;
  5897. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  5898. label_FacModeStatus.Text = "跳过基础功能检测!";
  5899. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  5900. Delay_ms(500);
  5901. }
  5902. //力矩检测
  5903. if (checkBox_FacTor.Checked)
  5904. {
  5905. label_FacModeStatus.Text = "力矩传感器检测!";
  5906. //发送指令进入配置模式
  5907. do
  5908. {
  5909. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  5910. {
  5911. break;
  5912. }
  5913. Code[0] = 0x01;
  5914. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5915. WriteACK = false;
  5916. WriteCnt = 0;
  5917. ACK_WaitCnt = 0;
  5918. while (ACK_WaitCnt <= 2) ; //1s
  5919. if (textBox_RunInfo_Vol.Text != "---")
  5920. {
  5921. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5922. Delay_ms(500);
  5923. }
  5924. else
  5925. {
  5926. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  5927. label_FacModeStatus.Text = "存在故障!";
  5928. label_FacModeResult.BackColor = Color.Red;
  5929. label_FacModeResult.Text = "测试异常";
  5930. Delay_ms(500);
  5931. //存储异常并上传
  5932. FacMode_Stop(false);
  5933. return;
  5934. }
  5935. } while (false);
  5936. ushort Max = 0, Torque = 0;
  5937. //提示输入力矩信号
  5938. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  5939. ACK_WaitCnt = 0;
  5940. while (ACK_WaitCnt <= 20) //10s
  5941. {
  5942. //获取力矩值
  5943. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  5944. if (Torque > Max)
  5945. Max = Torque;
  5946. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  5947. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  5948. (ACK_WaitCnt >= 6))
  5949. {
  5950. label_FacModeTq.BackColor = Color.Green;
  5951. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  5952. break;
  5953. }
  5954. }
  5955. if (ACK_WaitCnt >= 20)
  5956. {
  5957. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + "\r\n");
  5958. label_FacModeStatus.Text = "存在故障!";
  5959. label_FacModeResult.BackColor = Color.Red;
  5960. label_FacModeResult.Text = "测试异常";
  5961. Delay_ms(500);
  5962. //存储异常并上传
  5963. FacMode_Stop(false);
  5964. return;
  5965. }
  5966. }
  5967. else
  5968. {
  5969. label_FacModeTq.BackColor = Color.Yellow;
  5970. label_FacModeCad.BackColor = Color.Yellow;
  5971. label_FacModeStatus.Text = "跳过力矩检测!";
  5972. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  5973. Delay_ms(500);
  5974. }
  5975. //踏频检测
  5976. if (checkBox_FacCad.Checked)
  5977. {
  5978. label_FacModeStatus.Text = "踏频传感器检测!";
  5979. //发送指令进入配置模式
  5980. do
  5981. {
  5982. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  5983. {
  5984. break;
  5985. }
  5986. Code[0] = 0x01;
  5987. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5988. WriteACK = false;
  5989. WriteCnt = 0;
  5990. ACK_WaitCnt = 0;
  5991. while (ACK_WaitCnt <= 2) ; //1s
  5992. if (textBox_RunInfo_Vol.Text != "---")
  5993. {
  5994. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5995. Delay_ms(500);
  5996. }
  5997. else
  5998. {
  5999. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6000. label_FacModeStatus.Text = "存在故障!";
  6001. label_FacModeResult.BackColor = Color.Red;
  6002. label_FacModeResult.Text = "测试异常";
  6003. Delay_ms(500);
  6004. //存储异常并上传
  6005. FacMode_Stop(false);
  6006. return;
  6007. }
  6008. } while (false);
  6009. ushort Max = 0, Cadence = 0;
  6010. //提示输入踏频信号
  6011. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  6012. ACK_WaitCnt = 0;
  6013. while (ACK_WaitCnt <= 20) //10s
  6014. {
  6015. //获取踏频
  6016. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  6017. if (Cadence > Max)
  6018. Max = Cadence;
  6019. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  6020. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  6021. (ACK_WaitCnt >= 6))
  6022. {
  6023. label_FacModeCad.BackColor = Color.Green;
  6024. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6025. break;
  6026. }
  6027. }
  6028. if (ACK_WaitCnt >= 20)
  6029. {
  6030. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + "\r\n");
  6031. label_FacModeStatus.Text = "存在故障!";
  6032. label_FacModeResult.BackColor = Color.Red;
  6033. label_FacModeResult.Text = "测试异常";
  6034. Delay_ms(500);
  6035. //存储异常并上传
  6036. FacMode_Stop(false);
  6037. return;
  6038. }
  6039. }
  6040. else
  6041. {
  6042. label_FacModeTq.BackColor = Color.Yellow;
  6043. label_FacModeCad.BackColor = Color.Yellow;
  6044. label_FacModeStatus.Text = "跳过踏频检测!";
  6045. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  6046. Delay_ms(500);
  6047. }
  6048. //转把检测
  6049. if (checkBox_FacThrrotleTest.Checked)
  6050. {
  6051. label_FacModeStatus.Text = "转把检测";
  6052. //发送指令进入配置模式
  6053. do
  6054. {
  6055. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6056. {
  6057. break;
  6058. }
  6059. Code[0] = 0x01;
  6060. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6061. WriteACK = false;
  6062. WriteCnt = 0;
  6063. ACK_WaitCnt = 0;
  6064. while (ACK_WaitCnt <= 2) ; //1s
  6065. if (textBox_RunInfo_Vol.Text != "---")
  6066. {
  6067. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6068. Delay_ms(500);
  6069. }
  6070. else
  6071. {
  6072. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6073. label_FacModeStatus.Text = "存在故障!";
  6074. label_FacModeResult.BackColor = Color.Red;
  6075. label_FacModeResult.Text = "测试异常";
  6076. Delay_ms(500);
  6077. //存储异常并上传
  6078. FacMode_Stop(false);
  6079. return;
  6080. }
  6081. } while (false);
  6082. //进入TURBO档
  6083. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  6084. Code[0] = 0x04;
  6085. Code[1] = 0xF0;
  6086. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6087. WriteACK = false;
  6088. WriteCnt = 0;
  6089. ACK_WaitCnt = 0;
  6090. while (ACK_WaitCnt <= 2) ; //1s
  6091. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6092. {
  6093. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  6094. label_FacModeStatus.Text = "存在故障!";
  6095. label_FacModeResult.BackColor = Color.Red;
  6096. label_FacModeResult.Text = "测试异常";
  6097. Delay_ms(500);
  6098. //存储异常并上传
  6099. FacMode_Stop(false);
  6100. return;
  6101. }
  6102. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,10s内转动转把" + "\r\n");
  6103. ACK_WaitCnt = 0;
  6104. while (ACK_WaitCnt <= 20)
  6105. {
  6106. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  6107. {
  6108. label_FacModeGas.BackColor = Color.Green;
  6109. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  6110. break;
  6111. }
  6112. }
  6113. if (ACK_WaitCnt >= 20) //转把超时
  6114. {
  6115. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  6116. label_FacModeStatus.Text = "存在故障!";
  6117. label_FacModeResult.BackColor = Color.Red;
  6118. label_FacModeResult.Text = "测试异常";
  6119. Delay_ms(500);
  6120. //存储异常并上传
  6121. FacMode_Stop(false);
  6122. return;
  6123. }
  6124. }
  6125. else
  6126. {
  6127. label_FacModeGas.BackColor = Color.Yellow;
  6128. label_FacModeStatus.Text = "跳过转把检测!";
  6129. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  6130. Delay_ms(500);
  6131. }
  6132. //刹车检测
  6133. if (checkBox_FacBreakTest.Checked)
  6134. {
  6135. label_FacModeStatus.Text = "刹把检测";
  6136. //发送指令进入配置模式
  6137. do
  6138. {
  6139. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6140. {
  6141. break;
  6142. }
  6143. Code[0] = 0x01;
  6144. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6145. WriteACK = false;
  6146. WriteCnt = 0;
  6147. ACK_WaitCnt = 0;
  6148. while (ACK_WaitCnt <= 2) ; //1s
  6149. if (textBox_RunInfo_Vol.Text != "---")
  6150. {
  6151. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6152. Delay_ms(500);
  6153. }
  6154. else
  6155. {
  6156. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6157. label_FacModeStatus.Text = "存在故障!";
  6158. label_FacModeResult.BackColor = Color.Red;
  6159. label_FacModeResult.Text = "测试异常";
  6160. Delay_ms(500);
  6161. //存储异常并上传
  6162. FacMode_Stop(false);
  6163. return;
  6164. }
  6165. } while (false);
  6166. //启动电机进入WALK模式
  6167. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  6168. Code[0] = 0x22;
  6169. Code[1] = 0xF0;
  6170. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6171. WriteACK = false;
  6172. WriteCnt = 0;
  6173. ACK_WaitCnt = 0;
  6174. while (ACK_WaitCnt <= 2) ; //1s
  6175. if (textBox_RunInfo_GearSt.Text != "WALK")
  6176. {
  6177. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6178. label_FacModeStatus.Text = "存在故障!";
  6179. label_FacModeResult.BackColor = Color.Red;
  6180. label_FacModeResult.Text = "测试异常";
  6181. Delay_ms(500);
  6182. //存储异常并上传
  6183. FacMode_Stop(false);
  6184. return;
  6185. }
  6186. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  6187. ACK_WaitCnt = 0;
  6188. while (ACK_WaitCnt <= 20)
  6189. {
  6190. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  6191. {
  6192. label_FacModeBreak.BackColor = Color.Green;
  6193. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  6194. break;
  6195. }
  6196. }
  6197. if (ACK_WaitCnt >= 20) //剎把超时
  6198. {
  6199. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
  6200. label_FacModeStatus.Text = "存在故障!";
  6201. label_FacModeResult.BackColor = Color.Red;
  6202. label_FacModeResult.Text = "测试异常";
  6203. Delay_ms(500);
  6204. //存储异常并上传
  6205. FacMode_Stop(false);
  6206. return;
  6207. }
  6208. //停止电机
  6209. Code[0] = 0x00;
  6210. Code[1] = 0xF0;
  6211. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6212. WriteACK = false;
  6213. WriteCnt = 0;
  6214. ACK_WaitCnt = 0;
  6215. while (ACK_WaitCnt <= 2) ; //1s
  6216. if (textBox_RunInfo_GearSt.Text != "OFF")
  6217. {
  6218. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6219. label_FacModeStatus.Text = "存在故障!";
  6220. label_FacModeResult.BackColor = Color.Red;
  6221. label_FacModeResult.Text = "测试异常";
  6222. Delay_ms(500);
  6223. //存储异常并上传
  6224. FacMode_Stop(false);
  6225. return;
  6226. }
  6227. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  6228. Delay_ms(500);
  6229. }
  6230. else
  6231. {
  6232. label_FacModeBreak.BackColor = Color.Yellow;
  6233. label_FacModeStatus.Text = "跳过刹车检测!";
  6234. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  6235. Delay_ms(500);
  6236. }
  6237. //前后灯检测
  6238. if (checkBox_FacLightTest.Checked)
  6239. {
  6240. //前后灯检测
  6241. label_FacModeStatus.Text = "前后灯检测";
  6242. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  6243. //发送指令打开车灯
  6244. Code[0] = 0x00;
  6245. Code[1] = 0xF1;
  6246. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6247. WriteACK = false;
  6248. WriteCnt = 0;
  6249. ACK_WaitCnt = 0;
  6250. while (ACK_WaitCnt <= 2) ; //1s
  6251. if (textBox_RunInfo_LightSwitch.Text != "ON")
  6252. {
  6253. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  6254. label_FacModeStatus.Text = "存在故障!";
  6255. label_FacModeResult.BackColor = Color.Red;
  6256. label_FacModeResult.Text = "测试异常";
  6257. Delay_ms(500);
  6258. //存储异常并上传
  6259. FacMode_Stop(false);
  6260. return;
  6261. }
  6262. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  6263. Delay_ms(500);
  6264. //提示检查灯压是否正确
  6265. if (MessageBox.Show("前后灯是否正常?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  6266. {
  6267. label_FacModeLightF.BackColor = Color.Green;
  6268. label_FacModeLightB.BackColor = Color.Green;
  6269. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  6270. Delay_ms(500);
  6271. }
  6272. else
  6273. {
  6274. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  6275. label_FacModeStatus.Text = "存在故障!";
  6276. label_FacModeResult.BackColor = Color.Red;
  6277. label_FacModeResult.Text = "测试异常";
  6278. Delay_ms(500);
  6279. //存储异常并上传
  6280. FacMode_Stop(false);
  6281. return;
  6282. }
  6283. //发送指令关闭车灯
  6284. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  6285. Code[0] = 0x00;
  6286. Code[1] = 0xF0;
  6287. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6288. WriteACK = false;
  6289. WriteCnt = 0;
  6290. ACK_WaitCnt = 0;
  6291. while (ACK_WaitCnt <= 2) ; //1s
  6292. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  6293. {
  6294. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  6295. label_FacModeStatus.Text = "存在故障!";
  6296. label_FacModeResult.BackColor = Color.Red;
  6297. label_FacModeResult.Text = "测试异常";
  6298. Delay_ms(500);
  6299. //存储异常并上传
  6300. FacMode_Stop(false);
  6301. return;
  6302. }
  6303. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  6304. Delay_ms(500);
  6305. }
  6306. else
  6307. {
  6308. label_FacModeLightF.BackColor = Color.Yellow;
  6309. label_FacModeLightB.BackColor = Color.Yellow;
  6310. label_FacModeStatus.Text = "跳过前后灯检测!";
  6311. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  6312. Delay_ms(500);
  6313. }
  6314. //软件版本检测
  6315. do
  6316. {
  6317. label_FacModeStatus.Text = "软件版本确认";
  6318. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  6319. //发送指令读取版本
  6320. Class_Motor_Ver.Mode = "---";
  6321. Class_Motor_Ver.SN = "---";
  6322. Class_Motor_Ver.HW = "---";
  6323. Class_Motor_Ver.FW = "---";
  6324. Class_Motor_Ver.Special = "---";
  6325. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  6326. ACK_WaitCnt = 0;
  6327. while (ACK_WaitCnt <= 2) ; //1s
  6328. if (Class_Motor_Ver.Mode == "---")
  6329. {
  6330. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  6331. label_FacModeStatus.Text = "存在故障!";
  6332. label_FacModeResult.BackColor = Color.Red;
  6333. label_FacModeResult.Text = "测试异常";
  6334. Delay_ms(500);
  6335. //存储异常并上传
  6336. FacMode_Stop(false);
  6337. return;
  6338. }
  6339. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  6340. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  6341. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  6342. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  6343. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  6344. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  6345. //判断版本是否正确
  6346. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  6347. string VerRead = "";
  6348. try
  6349. {
  6350. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  6351. }
  6352. catch (System.Exception)
  6353. {
  6354. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  6355. label_FacModeStatus.Text = "存在故障!";
  6356. label_FacModeResult.BackColor = Color.Red;
  6357. label_FacModeResult.Text = "测试异常";
  6358. Delay_ms(500);
  6359. //存储异常并上传
  6360. FacMode_Stop(false);
  6361. return;
  6362. }
  6363. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  6364. {
  6365. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  6366. label_FacModeStatus.Text = "存在故障!";
  6367. label_FacModeResult.BackColor = Color.Red;
  6368. label_FacModeResult.Text = "测试异常";
  6369. Delay_ms(500);
  6370. //存储异常并上传
  6371. FacMode_Stop(false);
  6372. return;
  6373. }
  6374. label_FacModeFWVersion.BackColor = Color.Green;
  6375. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  6376. Delay_ms(500);
  6377. } while (false);
  6378. //测试合格
  6379. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  6380. label_FacModeStatus.Text = "测试结束!";
  6381. label_FacModeResult.BackColor = Color.Green;
  6382. label_FacModeResult.Text = "测试合格";
  6383. Delay_ms(500);
  6384. //存储并上传
  6385. FacMode_Stop(true);
  6386. return;
  6387. }
  6388. private void FacModelLabelInit()
  6389. {
  6390. //测试状态标签
  6391. label_FacModeResult.BackColor = Color.Yellow;
  6392. label_FacModeResult.Text = "测试中";
  6393. //测试过程标签
  6394. label_FacModeStatus.Text = "测试就绪";
  6395. //测试结果标签
  6396. foreach (Control c in groupBox28.Controls)
  6397. {
  6398. if (c is Label)
  6399. {
  6400. if (c.Text == string.Empty)
  6401. c.BackColor = Color.Red;
  6402. }
  6403. }
  6404. }
  6405. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  6406. {
  6407. //更新生产配置文件目录
  6408. GetDateList(false);
  6409. }
  6410. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  6411. {
  6412. //更新生产配置文件目录
  6413. GetDateList(false);
  6414. }
  6415. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  6416. {
  6417. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  6418. richTextBox_FacModeLog.ScrollToCaret();
  6419. }
  6420. /// <summary>
  6421. /// 参数检验测试停止
  6422. /// </summary>
  6423. /// <param name="OK_Flag"></param>
  6424. private void CheckMode_Stop(bool OK_Flag)
  6425. {
  6426. //打开开始按钮
  6427. button_CheckModeStart.Enabled = true;
  6428. //系统关机
  6429. var Code = new byte[32];//发送的指令数据
  6430. Code[0] = 0xF0;
  6431. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6432. //关闭串口
  6433. mySerialProcess.SerialClose(false);
  6434. //路径设置
  6435. string LocalSavePath = "";
  6436. string ServerSavePath = "";
  6437. if (OK_Flag)
  6438. {
  6439. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  6440. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  6441. }
  6442. else
  6443. {
  6444. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  6445. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  6446. }
  6447. if (Directory.Exists(LocalSavePath) == false)
  6448. {
  6449. Directory.CreateDirectory(LocalSavePath);
  6450. }
  6451. //保存和上传
  6452. string LogSavePath = "";
  6453. string LogSaveFileName = "";
  6454. string ProductInfo = textBox_CheckModeScan.Text;
  6455. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  6456. if (Directory.Exists(LogSavePath) == false)
  6457. {
  6458. Directory.CreateDirectory(LogSavePath);
  6459. }
  6460. //测试页面
  6461. Double scaleX = PrimaryScreen.ScaleX;
  6462. Double scaleY = PrimaryScreen.ScaleY;
  6463. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  6464. Graphics g = Graphics.FromImage(bit);
  6465. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  6466. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  6467. bit.Save(LogSaveFileName);
  6468. //上传测试页面到服务器
  6469. if (myFtp.IsNetConnected == true)
  6470. {
  6471. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6472. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6473. {
  6474. myFtp.MakeDir(ServerSavePath + DateNow);
  6475. }
  6476. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6477. {
  6478. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6479. }
  6480. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6481. if (result == true)
  6482. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  6483. }
  6484. //测试记录
  6485. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  6486. string file_str = "";
  6487. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  6488. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  6489. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  6490. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  6491. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  6492. //上传测试记录到服务器
  6493. if (myFtp.IsNetConnected == true)
  6494. {
  6495. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6496. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6497. {
  6498. myFtp.MakeDir(ServerSavePath + DateNow);
  6499. }
  6500. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6501. {
  6502. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6503. }
  6504. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6505. if (result == true)
  6506. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  6507. }
  6508. //扫码框清空
  6509. textBox_CheckModeScan.Text = "";
  6510. }
  6511. /// <summary>
  6512. /// 参数检验开始
  6513. /// </summary>
  6514. /// <param name="sender"></param>
  6515. /// <param name="e"></param>
  6516. private void button_CheckModeStart_Click(object sender, EventArgs e)
  6517. {
  6518. //测试项目关闭编辑
  6519. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  6520. foreach (Control c in groupBox29.Controls)
  6521. {
  6522. if (c is CheckBox)
  6523. c.Enabled = false;
  6524. }
  6525. ReadLockStatus = true;
  6526. //检查配置文件
  6527. if (comboBox_CheckModeCfgFile.Text == "")
  6528. {
  6529. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6530. return;
  6531. }
  6532. //开始测试
  6533. CheckTestStart();
  6534. }
  6535. /// <summary>
  6536. /// 参数检验测试子函数
  6537. /// </summary>
  6538. private void CheckTestStart()
  6539. {
  6540. //初始化标签
  6541. CheckModeLabelInit();
  6542. richTextBox_CheckModeLog.Clear();
  6543. //按钮禁止操作
  6544. button_CheckModeStart.Enabled = false;
  6545. //记录配置文件
  6546. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  6547. //检查打标信息
  6548. label_CheckModeStatus.Text = "检查扫码信息";
  6549. Delay_ms(500);
  6550. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  6551. if (textBox_CheckModeScan.Text == string.Empty)
  6552. {
  6553. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6554. return;
  6555. }
  6556. try
  6557. {
  6558. if (中置电机ToolStripMenuItem.Checked == true)
  6559. {
  6560. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  6561. {
  6562. label_CheckModeStatus.Text = "存在故障!";
  6563. label_CheckModeResult.BackColor = Color.Red;
  6564. label_CheckModeResult.Text = "标签格式错误";
  6565. button_CheckModeStart.Enabled = true;
  6566. return;
  6567. }
  6568. }
  6569. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6570. {
  6571. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  6572. {
  6573. label_CheckModeStatus.Text = "存在故障!";
  6574. label_CheckModeResult.BackColor = Color.Red;
  6575. label_CheckModeResult.Text = "标签格式错误";
  6576. button_CheckModeStart.Enabled = true;
  6577. return;
  6578. }
  6579. }
  6580. }
  6581. catch (System.Exception)
  6582. {
  6583. label_CheckModeStatus.Text = "存在故障!";
  6584. label_CheckModeResult.BackColor = Color.Red;
  6585. label_CheckModeResult.Text = "标签格式错误";
  6586. button_CheckModeStart.Enabled = true;
  6587. return;
  6588. }
  6589. //打开串口
  6590. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  6591. if (!mySerialProcess.mySerial.IsOpen)
  6592. {
  6593. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6594. return;
  6595. }
  6596. //流水号计数
  6597. //...
  6598. //创建线程,执行测试任务
  6599. Thread th = new Thread(CheckModeTest_Task);
  6600. th.Start();
  6601. }
  6602. /// <summary>
  6603. /// 执行一次测试任务
  6604. /// </summary>
  6605. private void CheckModeTest_Task()
  6606. {
  6607. //开始测试
  6608. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  6609. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  6610. //变量定义
  6611. var Code = new byte[255];//发送的指令数据
  6612. ushort DataTemp;
  6613. short DataTemp_Int16;
  6614. string ResultPathName = "";
  6615. label_CheckModeStatus.Text = "开始测试";
  6616. Delay_ms(500);
  6617. label_CheckModeStatus.Text = "系统开机";
  6618. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  6619. BootInfo = "";
  6620. Code[0] = 0xF0;
  6621. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6622. Delay_ms(1500);
  6623. Code[0] = 0xF1;
  6624. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6625. ACK_WaitCnt = 0;
  6626. while (ACK_WaitCnt <= 2) ; //1s
  6627. //检查BOOT版本
  6628. if (BootInfo != string.Empty)
  6629. {
  6630. label_CheckModeBoot.BackColor = Color.Green;
  6631. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  6632. Delay_ms(500);
  6633. }
  6634. else
  6635. {
  6636. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  6637. label_CheckModeStatus.Text = "存在故障!";
  6638. label_CheckModeResult.BackColor = Color.Red;
  6639. label_CheckModeResult.Text = "测试异常";
  6640. Delay_ms(500);
  6641. //存储异常并上传
  6642. CheckMode_Stop(false);
  6643. return;
  6644. }
  6645. //发送指令读取版本信息
  6646. do
  6647. {
  6648. label_CheckModeStatus.Text = "读取版本信息";
  6649. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  6650. //发送指令读取版本
  6651. Class_Motor_Ver.Mode = "---";
  6652. Class_Motor_Ver.SN = "---";
  6653. Class_Motor_Ver.HW = "---";
  6654. Class_Motor_Ver.FW = "---";
  6655. Class_Motor_Ver.Special = "---";
  6656. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  6657. ACK_WaitCnt = 0;
  6658. while (ACK_WaitCnt <= 2) ; //1s
  6659. if (Class_Motor_Ver.Mode == "---")
  6660. {
  6661. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  6662. label_CheckModeStatus.Text = "存在故障!";
  6663. label_CheckModeResult.BackColor = Color.Red;
  6664. label_CheckModeResult.Text = "测试异常";
  6665. Delay_ms(500);
  6666. //存储异常并上传
  6667. CheckMode_Stop(false);
  6668. return;
  6669. }
  6670. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  6671. Delay_ms(500);
  6672. } while (false);
  6673. //软件版本检查
  6674. if (checkBox_CheckModeFWVer.Checked)
  6675. {
  6676. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  6677. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  6678. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  6679. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  6680. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  6681. //判断版本是否正确
  6682. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  6683. string VerRead = "";
  6684. try
  6685. {
  6686. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  6687. }
  6688. catch (System.Exception)
  6689. {
  6690. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  6691. label_CheckModeStatus.Text = "存在故障!";
  6692. label_CheckModeResult.BackColor = Color.Red;
  6693. label_CheckModeResult.Text = "测试异常";
  6694. Delay_ms(500);
  6695. //存储异常并上传
  6696. CheckMode_Stop(false);
  6697. return;
  6698. }
  6699. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  6700. {
  6701. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  6702. label_CheckModeStatus.Text = "存在故障!";
  6703. label_CheckModeResult.BackColor = Color.Red;
  6704. label_CheckModeResult.Text = "测试异常";
  6705. Delay_ms(500);
  6706. //存储异常并上传
  6707. CheckMode_Stop(false);
  6708. return;
  6709. }
  6710. label_CheckModeFWVer.BackColor = Color.Green;
  6711. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  6712. Delay_ms(500);
  6713. }
  6714. else
  6715. {
  6716. label_CheckModeFWVer.BackColor = Color.Yellow;
  6717. label_CheckModeStatus.Text = "跳过软件版本查询";
  6718. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  6719. Delay_ms(500);
  6720. }
  6721. //打标信息核对
  6722. if (checkBox_CheckModeSN.Checked)
  6723. {
  6724. label_CheckModeStatus.Text = "核对打标信息";
  6725. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  6726. //根据扫码信息获取型号和SN
  6727. string ScanInfo = textBox_CheckModeScan.Text;
  6728. string regexInfo = "";
  6729. string[] InfoList = { "" };
  6730. try
  6731. {
  6732. if (中置电机ToolStripMenuItem.Checked == true)
  6733. {
  6734. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6735. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6736. }
  6737. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6738. {
  6739. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6740. string Model = InfoList[0];
  6741. string Spec = InfoList[1];
  6742. string Sn = InfoList[2];
  6743. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6744. InfoList[1] = Sn;
  6745. }
  6746. }
  6747. catch
  6748. {
  6749. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6750. label_FacModeStatus.Text = "存在故障!";
  6751. label_FacModeResult.BackColor = Color.Red;
  6752. label_FacModeResult.Text = "标签格式错误";
  6753. Delay_ms(500);
  6754. //存储异常并上传
  6755. CheckMode_Stop(false);
  6756. return;
  6757. }
  6758. //核对型号
  6759. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  6760. {
  6761. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  6762. label_CheckModeStatus.Text = "存在故障!";
  6763. label_CheckModeResult.BackColor = Color.Red;
  6764. label_CheckModeResult.Text = "测试异常";
  6765. Delay_ms(500);
  6766. //存储异常并上传
  6767. CheckMode_Stop(false);
  6768. return;
  6769. }
  6770. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  6771. Delay_ms(500);
  6772. //核对SN
  6773. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  6774. {
  6775. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  6776. label_CheckModeStatus.Text = "存在故障!";
  6777. label_CheckModeResult.BackColor = Color.Red;
  6778. label_CheckModeResult.Text = "测试异常";
  6779. Delay_ms(500);
  6780. //存储异常并上传
  6781. CheckMode_Stop(false);
  6782. return;
  6783. }
  6784. label_CheckModeSN.BackColor = Color.Green;
  6785. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  6786. Delay_ms(500);
  6787. }
  6788. else
  6789. {
  6790. label_CheckModeSN.BackColor = Color.Yellow;
  6791. label_CheckModeStatus.Text = "跳过打标信息确认";
  6792. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  6793. Delay_ms(500);
  6794. }
  6795. //参数检验
  6796. if (checkBox_CheckModeCfg.Checked)
  6797. {
  6798. //读取配置文件信息
  6799. label_CheckModeStatus.Text = "参数检查";
  6800. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6801. //配置文件
  6802. List<byte[]> CmdList = new List<byte[]>();
  6803. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  6804. //从服务器下载文件
  6805. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6806. {
  6807. string SelectFile = "";
  6808. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  6809. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6810. {
  6811. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  6812. }
  6813. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6814. //打开文件
  6815. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  6816. ConfigCmd.Clear();
  6817. while (streamReader.Peek() != -1)
  6818. {
  6819. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  6820. if (fileLineInfo.Contains("["))
  6821. {
  6822. if (fileLineInfo.Contains("助力参数"))
  6823. {
  6824. fileLineInfo = streamReader.ReadLine();
  6825. }
  6826. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  6827. }
  6828. }
  6829. streamReader.Close();
  6830. }
  6831. //从本地加载文件
  6832. else
  6833. {
  6834. string SelectFile = "";
  6835. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  6836. //打开文件
  6837. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6838. ConfigCmd.Clear();
  6839. while (streamReader.Peek() != -1)
  6840. {
  6841. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  6842. if (fileLineInfo.Contains("["))
  6843. {
  6844. if (fileLineInfo.Contains("助力参数"))
  6845. {
  6846. fileLineInfo = streamReader.ReadLine();
  6847. }
  6848. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  6849. }
  6850. }
  6851. streamReader.Close();
  6852. }
  6853. int CmdNum = ConfigCmd.Count(); //指令个数
  6854. Delay_ms(500);
  6855. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  6856. Delay_ms(500);
  6857. //逐条读取比较
  6858. try
  6859. {
  6860. foreach (string key in ConfigCmd.Keys)
  6861. {
  6862. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  6863. CmdRevStrTemp = "";
  6864. if (key.Contains("曲线"))
  6865. {
  6866. byte LineNum = 0;
  6867. var code = new byte[4];
  6868. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  6869. if (LineNum <= 5)
  6870. {
  6871. code[0] = (byte)(LineNum & 0xFF);
  6872. code[1] = (byte)((LineNum >> 8) & 0xFF);
  6873. code[2] = (byte)(LineNum & 0xFF);
  6874. code[3] = (byte)((LineNum >> 8) & 0xFF);
  6875. }
  6876. else
  6877. {
  6878. code[0] = (byte)(LineNum & 0xFF);
  6879. code[1] = (byte)((LineNum >> 8) & 0xFF);
  6880. code[2] = (byte)(5 & 0xFF);
  6881. code[3] = (byte)((5 >> 8) & 0xFF);
  6882. }
  6883. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  6884. }
  6885. else
  6886. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  6887. Delay_ms(500);
  6888. if (CmdRevStrTemp == string.Empty)
  6889. {
  6890. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  6891. label_CheckModeStatus.Text = "存在故障!";
  6892. label_CheckModeResult.BackColor = Color.Red;
  6893. label_CheckModeResult.Text = "测试异常";
  6894. Delay_ms(500);
  6895. //存储异常并上传
  6896. CheckMode_Stop(false);
  6897. return;
  6898. }
  6899. //比较当前指令,读取的配置文件和返回数据比较
  6900. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  6901. string ParamRead = "";
  6902. if (string.Compare(key, "[其它传感器参数]") == 0)
  6903. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //该指令包含力矩参数
  6904. else
  6905. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim();
  6906. if (ParamWrite.Contains(ParamRead))
  6907. {
  6908. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  6909. continue;
  6910. }
  6911. else
  6912. {
  6913. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  6914. label_CheckModeStatus.Text = "存在故障!";
  6915. label_CheckModeResult.BackColor = Color.Red;
  6916. label_CheckModeResult.Text = "测试异常";
  6917. Delay_ms(500);
  6918. //存储异常并上传
  6919. CheckMode_Stop(false);
  6920. return;
  6921. }
  6922. }
  6923. }
  6924. catch (System.Exception)
  6925. {
  6926. timer_1s.Enabled = false;
  6927. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6928. timer_1s.Enabled = true;
  6929. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  6930. }
  6931. }
  6932. else
  6933. {
  6934. label_CheckModeCfg.BackColor = Color.Yellow;
  6935. label_CheckModeStatus.Text = "跳过参数检验";
  6936. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  6937. Delay_ms(500);
  6938. }
  6939. label_CheckModeCfg.BackColor = Color.Green;
  6940. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  6941. Delay_ms(500);
  6942. //读取力矩传感器
  6943. do
  6944. {
  6945. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  6946. //发送指令读取力矩传感器标定数据
  6947. CmdRevStrTemp = "";
  6948. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  6949. ACK_WaitCnt = 0;
  6950. while (ACK_WaitCnt <= 2) ; //1s
  6951. if (CmdRevStrTemp == "---")
  6952. {
  6953. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  6954. label_CheckModeStatus.Text = "存在故障!";
  6955. label_CheckModeResult.BackColor = Color.Red;
  6956. label_CheckModeResult.Text = "测试异常";
  6957. Delay_ms(500);
  6958. //存储异常并上传
  6959. CheckMode_Stop(false);
  6960. return;
  6961. }
  6962. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  6963. //取力矩传感器数据
  6964. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  6965. ushort MaxTorque;
  6966. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  6967. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  6968. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  6969. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  6970. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  6971. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  6972. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  6973. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  6974. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  6975. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  6976. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  6977. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  6978. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  6979. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  6980. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  6981. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  6982. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  6983. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  6984. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  6985. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  6986. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  6987. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  6988. //传感器标定检验
  6989. if (checkBox_CheckModeTorque.Checked)
  6990. {
  6991. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  6992. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  6993. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  6994. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  6995. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  6996. //与设置值比较
  6997. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  6998. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  6999. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  7000. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  7001. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  7002. )
  7003. {
  7004. label_CheckModeTorque.BackColor = Color.Green;
  7005. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  7006. Delay_ms(500);
  7007. }
  7008. else
  7009. {
  7010. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  7011. label_CheckModeStatus.Text = "存在故障!";
  7012. label_CheckModeResult.BackColor = Color.Red;
  7013. label_CheckModeResult.Text = "测试异常";
  7014. Delay_ms(500);
  7015. //存储异常并上传
  7016. CheckMode_Stop(false);
  7017. return;
  7018. }
  7019. }
  7020. else
  7021. {
  7022. label_CheckModeFWVer.BackColor = Color.Yellow;
  7023. label_CheckModeStatus.Text = "跳过传感器标定检验";
  7024. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  7025. Delay_ms(500);
  7026. }
  7027. } while (false);
  7028. //测试合格
  7029. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7030. label_CheckModeStatus.Text = "测试结束!";
  7031. label_CheckModeResult.BackColor = Color.Green;
  7032. label_CheckModeResult.Text = "测试合格";
  7033. Delay_ms(500);
  7034. //存储并上传
  7035. CheckMode_Stop(true);
  7036. return;
  7037. }
  7038. private void CheckModeLabelInit()
  7039. {
  7040. //测试状态标签
  7041. label_CheckModeResult.BackColor = Color.Yellow;
  7042. label_CheckModeResult.Text = "测试中";
  7043. //测试过程标签
  7044. label_CheckModeStatus.Text = "测试就绪";
  7045. //测试结果标签
  7046. foreach (Control c in groupBox31.Controls)
  7047. {
  7048. if (c is Label)
  7049. {
  7050. if (c.Text == string.Empty)
  7051. c.BackColor = Color.Red;
  7052. }
  7053. }
  7054. }
  7055. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  7056. {
  7057. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  7058. }
  7059. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  7060. {
  7061. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  7062. }
  7063. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  7064. {
  7065. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  7066. UInt32 hour = Time / 3600;
  7067. UInt32 min = (Time % 3600) / 60;
  7068. UInt32 s = (Time % 60);
  7069. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  7070. }
  7071. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  7072. {
  7073. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  7074. richTextBox_CheckModeLog.ScrollToCaret();
  7075. }
  7076. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  7077. {
  7078. EnterForm1.ShowDialog();
  7079. try
  7080. {
  7081. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7082. {
  7083. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7084. {
  7085. TorqueParamsForm.ShowDialog();
  7086. }
  7087. else
  7088. {
  7089. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7090. }
  7091. }
  7092. else
  7093. {
  7094. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7095. }
  7096. }
  7097. catch (Exception)
  7098. {
  7099. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7100. }
  7101. }
  7102. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  7103. {
  7104. if (e.KeyCode == Keys.Enter)
  7105. CheckTestStart();
  7106. }
  7107. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  7108. {
  7109. if (e.KeyCode == Keys.Enter)
  7110. TestStart();
  7111. }
  7112. private void button_SpeedDec10_Click(object sender, EventArgs e)
  7113. {
  7114. if (numericUpDown_SpeedAdj.Value <= 10)
  7115. numericUpDown_SpeedAdj.Value = 0;
  7116. else
  7117. numericUpDown_SpeedAdj.Value -= 10;
  7118. }
  7119. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  7120. {
  7121. if (numericUpDown_SpeedAdj.Value >= 90)
  7122. numericUpDown_SpeedAdj.Value = 100;
  7123. else
  7124. numericUpDown_SpeedAdj.Value += 10;
  7125. }
  7126. private void button_SpeedDec1_Click(object sender, EventArgs e)
  7127. {
  7128. if (numericUpDown_SpeedAdj.Value <= 1)
  7129. numericUpDown_SpeedAdj.Value = 0;
  7130. else
  7131. numericUpDown_SpeedAdj.Value -= 1;
  7132. }
  7133. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  7134. {
  7135. if(numericUpDown_SpeedAdj.Value >= 99)
  7136. numericUpDown_SpeedAdj.Value = 100;
  7137. else
  7138. numericUpDown_SpeedAdj.Value += 1;
  7139. }
  7140. bool WriteLockStatus = true;
  7141. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  7142. {
  7143. if (WriteLockStatus == true)
  7144. {
  7145. EnterForm1.ShowDialog();
  7146. try
  7147. {
  7148. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7149. {
  7150. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7151. {
  7152. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  7153. foreach (Control c in groupBox2.Controls)
  7154. {
  7155. if (c is CheckBox)
  7156. c.Enabled = true;
  7157. }
  7158. WriteLockStatus = !WriteLockStatus;
  7159. }
  7160. else
  7161. {
  7162. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7163. }
  7164. }
  7165. else
  7166. {
  7167. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7168. }
  7169. }
  7170. catch (Exception)
  7171. {
  7172. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7173. }
  7174. }
  7175. else
  7176. {
  7177. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7178. foreach (Control c in groupBox2.Controls)
  7179. {
  7180. if (c is CheckBox)
  7181. c.Enabled = false;
  7182. }
  7183. WriteLockStatus = !WriteLockStatus;
  7184. }
  7185. }
  7186. bool ReadLockStatus = true;
  7187. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  7188. {
  7189. if (ReadLockStatus == true)
  7190. {
  7191. EnterForm1.ShowDialog();
  7192. try
  7193. {
  7194. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7195. {
  7196. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7197. {
  7198. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  7199. foreach (Control c in groupBox29.Controls)
  7200. {
  7201. if (c is CheckBox)
  7202. c.Enabled = true;
  7203. }
  7204. ReadLockStatus = !ReadLockStatus;
  7205. }
  7206. else
  7207. {
  7208. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7209. }
  7210. }
  7211. else
  7212. {
  7213. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7214. }
  7215. }
  7216. catch (Exception)
  7217. {
  7218. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7219. }
  7220. }
  7221. else
  7222. {
  7223. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7224. foreach (Control c in groupBox29.Controls)
  7225. {
  7226. if (c is CheckBox)
  7227. c.Enabled = false;
  7228. }
  7229. ReadLockStatus = !ReadLockStatus;
  7230. }
  7231. }
  7232. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  7233. {
  7234. System.Diagnostics.Process.Start("osk.exe");
  7235. }
  7236. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  7237. {
  7238. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  7239. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  7240. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  7241. }
  7242. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  7243. {
  7244. comboBox_FacModeCfgDate.SelectedIndex = -1;
  7245. comboBox_FacModeCfgFile.SelectedIndex = -1;
  7246. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  7247. }
  7248. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  7249. {
  7250. VersionForm.ShowDialog();
  7251. }
  7252. private void button_MOS_Cal_Click(object sender, EventArgs e)
  7253. {
  7254. textBox_MOS_R1.Text = "";
  7255. textBox_MOS_R2.Text = "";
  7256. textBox_MOS_R3.Text = "";
  7257. try
  7258. {
  7259. var Code = new byte[18];
  7260. for (int i = 0; i < 18; i++)
  7261. Code[i] = 0;
  7262. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  7263. ushort uwDataTemp = 0;
  7264. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  7265. Code[2] = (byte)(uwDataTemp & 0xFF);
  7266. Code[3] = (byte)(uwDataTemp >> 8);
  7267. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  7268. Code[4] = (byte)(uwDataTemp & 0xFF);
  7269. Code[5] = (byte)(uwDataTemp >> 8);
  7270. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  7271. Code[6] = (byte)(uwDataTemp & 0xFF);
  7272. Code[7] = (byte)(uwDataTemp >> 8);
  7273. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  7274. Code[8] = (byte)(uwDataTemp & 0xFF);
  7275. Code[9] = (byte)(uwDataTemp >> 8);
  7276. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  7277. Code[10] = (byte)(uwDataTemp & 0xFF);
  7278. Code[11] = (byte)(uwDataTemp >> 8);
  7279. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  7280. }
  7281. catch (Exception)
  7282. {
  7283. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7284. }
  7285. }
  7286. private void button_MOS_Read_Click(object sender, EventArgs e)
  7287. {
  7288. foreach (Control c in groupBox21.Controls)
  7289. {
  7290. if (c is TextBox)
  7291. c.Text = "";
  7292. }
  7293. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7294. }
  7295. private void button_MOS_Write_Click(object sender, EventArgs e)
  7296. {
  7297. try
  7298. {
  7299. var Code = new byte[34];
  7300. for (int i = 0; i < 34; i++)
  7301. Code[i] = 0;
  7302. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  7303. ushort uwDataTemp = 0;
  7304. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  7305. Code[2] = (byte)(uwDataTemp & 0xFF);
  7306. Code[3] = (byte)(uwDataTemp >> 8);
  7307. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  7308. Code[4] = (byte)(uwDataTemp & 0xFF);
  7309. Code[5] = (byte)(uwDataTemp >> 8);
  7310. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  7311. Code[6] = (byte)(uwDataTemp & 0xFF);
  7312. Code[7] = (byte)(uwDataTemp >> 8);
  7313. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  7314. Code[8] = (byte)(uwDataTemp & 0xFF);
  7315. Code[9] = (byte)(uwDataTemp >> 8);
  7316. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  7317. Code[10] = (byte)(uwDataTemp & 0xFF);
  7318. Code[11] = (byte)(uwDataTemp >> 8);
  7319. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  7320. Code[12] = (byte)(uwDataTemp & 0xFF);
  7321. Code[13] = (byte)(uwDataTemp >> 8);
  7322. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  7323. Code[14] = (byte)(uwDataTemp & 0xFF);
  7324. Code[15] = (byte)(uwDataTemp >> 8);
  7325. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  7326. Code[16] = (byte)(uwDataTemp & 0xFF);
  7327. Code[17] = (byte)(uwDataTemp >> 8);
  7328. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  7329. }
  7330. catch (Exception)
  7331. {
  7332. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7333. }
  7334. }
  7335. /// <summary>
  7336. /// 测试模式点击文本框自动全选
  7337. /// </summary>
  7338. /// <param name="sender"></param>
  7339. /// <param name="e"></param>
  7340. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  7341. {
  7342. textBox_FacModeScan.SelectAll();
  7343. }
  7344. /// <summary>
  7345. /// 检验模式点击文本框自动全选
  7346. /// </summary>
  7347. /// <param name="sender"></param>
  7348. /// <param name="e"></param>
  7349. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  7350. {
  7351. textBox_CheckModeScan.SelectAll();
  7352. }
  7353. /// <summary>
  7354. /// 鼠标放置显示连接服务器信息
  7355. /// </summary>
  7356. /// <param name="sender"></param>
  7357. /// <param name="e"></param>
  7358. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  7359. {
  7360. // 创建the ToolTip
  7361. ToolTip toolTip1 = new ToolTip();
  7362. // 设置显示样式
  7363. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  7364. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  7365. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  7366. toolTip1.ShowAlways = true;//是否显示提示框
  7367. if (myFtp.IsNetConnected)
  7368. {
  7369. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + toolStripTextBox_ServerIP.Text);//设置故障内容显示
  7370. }
  7371. else
  7372. {
  7373. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  7374. }
  7375. }
  7376. /// <summary>
  7377. /// UART协议类型修改
  7378. /// </summary>
  7379. /// <param name="sender"></param>
  7380. /// <param name="e"></param>
  7381. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  7382. {
  7383. var Code = new byte[2];
  7384. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  7385. Code[1] = 0x00;
  7386. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7387. }
  7388. }
  7389. }