mainForm.cs 495 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Diagnostics.Eventing.Reader;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.IO.Ports;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Runtime.InteropServices;
  13. using System.Runtime.InteropServices.ComTypes;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading;
  17. using System.Web;
  18. using System.Windows.Forms;
  19. using System.Xml.Linq;
  20. namespace Welling_Motor_Debug_Tool
  21. {
  22. public partial class mainForm : Form
  23. {
  24. #region 变量定义
  25. //版本号
  26. public static string Version = "2.4.1";
  27. //串口实例
  28. Serial_Process mySerialProcess = new Serial_Process();
  29. string PortNumSave = "";
  30. string PortBaudrateSave = "";
  31. //本地信息定义
  32. LocalInfo localInfo = new LocalInfo();
  33. //FTP实例
  34. ftp myFtp = new ftp();
  35. public string ServerIP = "";
  36. public string ServerPort = "";
  37. public string ServerUser = "";
  38. public string ServerPassWd = "";
  39. public bool OfflineFlag = false;
  40. //MC运行信息超时计数
  41. bool MC_RunInfo_Refresh = false;
  42. ushort MC_RunInfo_Refresh_Cnt = 0;
  43. //MC调试信息超时计数
  44. bool MC_DebugInfo_Refresh = false;
  45. ushort MC_DebugInfo_Refresh_Cnt = 0;
  46. //MC故障码超时计数
  47. bool MC_ErrorCode_Refresh = false;
  48. ushort MC_ErrorCode_Refresh_Cnt = 0;
  49. //配置参数实例
  50. Params myParams = new Params();
  51. //记录文件名称
  52. string RunInfoSaveFilename = "";
  53. //BMS运行信息超时计数
  54. bool BMS_RunInfo_Refresh = false;
  55. ushort BMS_RunInfo_Refresh_Cnt = 0;
  56. //生产模式关机指令反馈状态
  57. bool PowerOffAckStatus = false;
  58. //登录窗口
  59. public static Login EnterForm1 = new Login();
  60. //生产配置文件信息
  61. ArrayList array_CfgInfo = new ArrayList();
  62. //写入参数返回标志和计数
  63. public bool WriteACK = false;
  64. public ushort ACK_WaitCnt = 0;
  65. //写入参数返回提示标志
  66. public bool ACK_DisFlag = true;
  67. //Boot版本信息
  68. public string BootInfo = "";
  69. //接收指令临时缓存,转string
  70. public string CmdRevStrTemp = "";
  71. //计时器,用于统计运行时间
  72. public Stopwatch stopwatch = new Stopwatch();
  73. //力矩传感器检验参数窗口
  74. public static TorqueParams TorqueParamsForm = new TorqueParams();
  75. //参数生成窗口
  76. public static GenerateParams GenerateParamsForm = new GenerateParams();
  77. //版本信息窗口
  78. public static Version VersionForm = new Version();
  79. //本机硬件信息
  80. public string Local_HdInformation = "";
  81. //指令窗口显示
  82. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  83. //位置传感器数据记录
  84. string[] AngledataRecord = new string[42];
  85. //服务器设置窗口
  86. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  87. #endregion
  88. #region 故障日志结构体定义
  89. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  90. [StructLayout(LayoutKind.Sequential)]
  91. public struct MC_ErrorLogSaveInfo_Struct_t
  92. {
  93. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  94. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  95. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  96. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  97. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  98. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  99. //电机运行信息,占用空间32bytes
  100. [StructLayout(LayoutKind.Sequential)]
  101. public struct MC_RunInfo_Struct_t
  102. {
  103. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  104. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  105. public ushort Power; //电功率 1W,地址偏移4
  106. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  107. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  108. public byte Cadence; //踏频 1rpm,地址偏移10
  109. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  110. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  111. public byte GearSt; //助力档位,地址偏移13
  112. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  113. public byte SOC; //剩余电量 1%,地址偏移15
  114. public ushort RemainDistance; //续航里程 1km,地址偏移16
  115. public ushort Torque_AD; //力矩寄存器,地址偏移18
  116. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  117. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  118. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  119. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  120. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  121. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  122. public UInt32 RS; //预留 4bytes
  123. };
  124. [MarshalAs(UnmanagedType.Struct)]
  125. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  126. //控制变量
  127. public Int16 IqCurrent; //Pu, 地址偏移 48
  128. public Int16 IqVoltage; //Pu, 地址偏移 50
  129. public Int16 IdCurrent; //Pu, 地址偏移 52
  130. public Int16 IdVoltage; //Pu, 地址偏移 54
  131. //状态机
  132. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  133. //预留
  134. public UInt16 RS1;
  135. public UInt16 RS2;
  136. public UInt16 RS3;
  137. };
  138. #endregion
  139. #region 屏幕缩放比例获取
  140. public class PrimaryScreen
  141. {
  142. #region Win32 API
  143. [DllImport("user32.dll")]
  144. static extern IntPtr GetDC(IntPtr ptr);
  145. [DllImport("gdi32.dll")]
  146. static extern int GetDeviceCaps(
  147. IntPtr hdc, // handle to DC
  148. int nIndex // index of capability
  149. );
  150. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  151. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  152. #endregion
  153. #region DeviceCaps常量
  154. const int HORZRES = 8;
  155. const int VERTRES = 10;
  156. const int LOGPIXELSX = 88;
  157. const int LOGPIXELSY = 90;
  158. const int DESKTOPVERTRES = 117;
  159. const int DESKTOPHORZRES = 118;
  160. #endregion
  161. #region 属性
  162. /// <summary>
  163. /// 获取屏幕分辨率当前物理大小
  164. /// </summary>
  165. public static Size WorkingArea
  166. {
  167. get
  168. {
  169. IntPtr hdc = GetDC(IntPtr.Zero);
  170. Size size = new Size();
  171. size.Width = GetDeviceCaps(hdc, HORZRES);
  172. size.Height = GetDeviceCaps(hdc, VERTRES);
  173. ReleaseDC(IntPtr.Zero, hdc);
  174. return size;
  175. }
  176. }
  177. /// <summary>
  178. /// 当前系统DPI_X 大小 一般为96
  179. /// </summary>
  180. public static int DpiX
  181. {
  182. get
  183. {
  184. IntPtr hdc = GetDC(IntPtr.Zero);
  185. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  186. ReleaseDC(IntPtr.Zero, hdc);
  187. return DpiX;
  188. }
  189. }
  190. /// <summary>
  191. /// 当前系统DPI_Y 大小 一般为96
  192. /// </summary>
  193. public static int DpiY
  194. {
  195. get
  196. {
  197. IntPtr hdc = GetDC(IntPtr.Zero);
  198. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  199. ReleaseDC(IntPtr.Zero, hdc);
  200. return DpiX;
  201. }
  202. }
  203. /// <summary>
  204. /// 获取真实设置的桌面分辨率大小
  205. /// </summary>
  206. public static Size DESKTOP
  207. {
  208. get
  209. {
  210. IntPtr hdc = GetDC(IntPtr.Zero);
  211. Size size = new Size();
  212. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  213. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  214. ReleaseDC(IntPtr.Zero, hdc);
  215. return size;
  216. }
  217. }
  218. /// <summary>
  219. /// 获取宽度缩放百分比
  220. /// </summary>
  221. public static float ScaleX
  222. {
  223. get
  224. {
  225. IntPtr hdc = GetDC(IntPtr.Zero);
  226. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  227. int d = GetDeviceCaps(hdc, HORZRES);
  228. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  229. ReleaseDC(IntPtr.Zero, hdc);
  230. return ScaleX;
  231. }
  232. }
  233. /// <summary>
  234. /// 获取高度缩放百分比
  235. /// </summary>
  236. public static float ScaleY
  237. {
  238. get
  239. {
  240. IntPtr hdc = GetDC(IntPtr.Zero);
  241. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  242. ReleaseDC(IntPtr.Zero, hdc);
  243. return ScaleY;
  244. }
  245. }
  246. #endregion
  247. }
  248. #endregion
  249. public static mainForm mainform1 = null;
  250. public mainForm()
  251. {
  252. InitializeComponent();
  253. mainform1 = this;
  254. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  255. stopwatch.Start();
  256. //端口初始化
  257. mySerialProcess.Init();
  258. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  259. //检查备忘录文件
  260. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  261. {
  262. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  263. }
  264. //检验流水号记录文件
  265. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  266. {
  267. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  268. }
  269. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  270. {
  271. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  272. }
  273. //检查文件夹
  274. if (!Directory.Exists(localInfo.LocalPath))
  275. {
  276. Directory.CreateDirectory(localInfo.LocalPath);
  277. }
  278. if (!Directory.Exists(localInfo.LocalDataPath))
  279. {
  280. Directory.CreateDirectory(localInfo.LocalDataPath);
  281. }
  282. if (!Directory.Exists(localInfo.ToolsPath))
  283. {
  284. Directory.CreateDirectory(localInfo.ToolsPath);
  285. }
  286. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  287. {
  288. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  289. }
  290. //服务器初始化
  291. do
  292. {
  293. //检查是否存在配置文件
  294. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  295. {
  296. //解密
  297. string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  298. string[] array_CfgInfo = sLine.Split(',');
  299. //解析配置文件
  300. ServerIP = array_CfgInfo[0].ToString();
  301. ServerPort = array_CfgInfo[1].ToString();
  302. ServerUser = array_CfgInfo[2].ToString();
  303. ServerPassWd = array_CfgInfo[3].ToString();
  304. if (array_CfgInfo[4].ToString() == "True")
  305. {
  306. OfflineFlag = true;
  307. checkBox_OffLineFacMode.Checked = true;
  308. checkBox_OffLineCheckMode.Checked = true;
  309. }
  310. }
  311. else //不存在配置文件由用户选择
  312. {
  313. ServerCfgForm1.ShowDialog();
  314. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  315. {
  316. case 0: //武汉园区
  317. case 1: //顺德工厂
  318. {
  319. ServerIP = "10.177.130.30";
  320. ServerPort = "15021";
  321. ServerUser = "factory_test";
  322. ServerPassWd = "ttium";
  323. OfflineFlag = false;
  324. checkBox_OffLineFacMode.Checked = false;
  325. checkBox_OffLineCheckMode.Checked = false;
  326. break;
  327. }
  328. case 2: //威灵园区
  329. case 3: //越南工厂
  330. case 4: //公司外部
  331. {
  332. ServerIP = "8.134.109.44";
  333. ServerPort = "21";
  334. ServerUser = "ttium";
  335. ServerPassWd = "ttium123";
  336. OfflineFlag = false;
  337. checkBox_OffLineFacMode.Checked = false;
  338. checkBox_OffLineCheckMode.Checked = false;
  339. break;
  340. }
  341. case 5: //离线使用
  342. {
  343. //输入管理员密码
  344. Scan scan_form = new Scan();
  345. scan_form.label1.Text = "请输入管理员密码";
  346. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  347. scan_form.ShowDialog();
  348. if (scan_form.textBox_Scan.Text == "ttium.123")
  349. {
  350. OfflineFlag = true;
  351. checkBox_OffLineFacMode.Checked = true;
  352. checkBox_OffLineCheckMode.Checked = true;
  353. }
  354. else
  355. {
  356. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  357. System.Environment.Exit(0);
  358. }
  359. break;
  360. }
  361. default: //无效
  362. {
  363. System.Environment.Exit(0);
  364. break;
  365. }
  366. }
  367. //保存网络配置文件
  368. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  369. {
  370. string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
  371. //加密保存
  372. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  373. }
  374. }
  375. } while (false);
  376. //检查配置文件
  377. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  378. {
  379. //打开文件
  380. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  381. string sLine = "";
  382. ArrayList array_CfgInfo = new ArrayList();
  383. array_CfgInfo.Clear();
  384. while (sLine != null)
  385. {
  386. sLine = objReader.ReadLine();
  387. array_CfgInfo.Add(sLine);
  388. }
  389. objReader.Close();
  390. //解析配置文件
  391. try
  392. {
  393. //Port Set
  394. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  395. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  396. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  397. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  398. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  399. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  400. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  401. //Option
  402. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  403. //Server Set
  404. toolStripTextBox_ServerPath.Text = array_CfgInfo[11].ToString().Split(':')[1];
  405. //MacInfo
  406. toolStripTextBox_MAC.Text = array_CfgInfo[14].ToString().Split(':')[1];
  407. toolStripTextBoxMACAddr.Text = array_CfgInfo[15].ToString().Split(':')[1];
  408. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  409. toolStripTextBox_MACPD.Text = array_CfgInfo[17].ToString().Split(':')[1];
  410. //Log Address
  411. textBox_LogAddrBegin.Text = array_CfgInfo[20].ToString().Split(':')[1];
  412. textBox_LogAddrEnd.Text = array_CfgInfo[21].ToString().Split(':')[1];
  413. //电机类型
  414. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[24].ToString().Split(':')[1] == "True");
  415. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  416. //检测阈值
  417. toolStripTextBox_ThVol.Text = array_CfgInfo[28].ToString().Split(':')[1];
  418. toolStripTextBox_ThCur.Text = array_CfgInfo[29].ToString().Split(':')[1];
  419. toolStripTextBox_ThSpeed.Text = array_CfgInfo[30].ToString().Split(':')[1];
  420. toolStripTextBox_ThTor.Text = array_CfgInfo[31].ToString().Split(':')[1];
  421. toolStripTextBox_ThCad.Text = array_CfgInfo[32].ToString().Split(':')[1];
  422. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[33].ToString().Split(':')[1];
  423. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[34].ToString().Split(':')[1];
  424. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[35].ToString().Split(':')[1];
  425. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  426. //MOS内阻校准系数
  427. toolStripTextBox_MosCalK.Text = array_CfgInfo[39].ToString().Split(':')[1];
  428. toolStripTextBox_MOS1.Text= array_CfgInfo[40].ToString().Split(':')[1];
  429. toolStripTextBox_MOS2.Text = array_CfgInfo[41].ToString().Split(':')[1];
  430. toolStripTextBox_MOS3.Text = array_CfgInfo[42].ToString().Split(':')[1];
  431. //通信协议类型
  432. cANToolStripMenuItem.Checked = (array_CfgInfo[45].ToString().Split(':')[1] == "True");
  433. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  434. //自动更新开关
  435. 打开ToolStripMenuItem.Checked = (array_CfgInfo[49].ToString().Split(':')[1] == "True");
  436. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  437. //位置校准偏差
  438. textBox_AngleDiffTh.Text = array_CfgInfo[52].ToString().Split(':')[1];
  439. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  440. textBox_AngleZeroTh.Text = array_CfgInfo[53].ToString().Split(':')[1];
  441. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  442. }
  443. catch (System.Exception)
  444. {
  445. timer_500ms.Enabled = false;
  446. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  447. timer_500ms.Enabled = true;
  448. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  449. }
  450. }
  451. else //不存在配置文件,生成文件写入默认值
  452. {
  453. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  454. }
  455. //解析本地流水号记录
  456. do
  457. {
  458. //测试模式
  459. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  460. //检验模式
  461. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  462. } while (false);
  463. //获取本机信息,读取时间较长,优先从本地文件获取
  464. do
  465. {
  466. try
  467. {
  468. //本地文件为空,读取信息保存
  469. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  470. {
  471. Local_HdInformation = "";
  472. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  473. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  474. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  475. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  476. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  477. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  478. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  479. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  480. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  481. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  482. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  483. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  484. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  485. }
  486. //从本地读取,计算机名和IP地址重新读
  487. else
  488. {
  489. Local_HdInformation = "";
  490. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  491. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  492. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  493. for (int i = 0; i < fileInfo.Length; i++)
  494. Local_HdInformation += fileInfo[i] + "\r\n";
  495. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  496. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  497. }
  498. }
  499. catch(Exception)
  500. {
  501. }
  502. } while (false);
  503. //系统登录
  504. do
  505. {
  506. EnterForm1.ShowDialog();
  507. try
  508. {
  509. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  510. {
  511. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  512. {
  513. //隐藏设置项
  514. 其它配置项ToolStripMenuItem.Visible = false;
  515. 写入存储ToolStripMenuItem.Visible = false;
  516. 服务器配置ToolStripMenuItem.Visible = false;
  517. 判断阈值ToolStripMenuItem.Visible = false;
  518. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  519. mOS内阻范围ToolStripMenuItem.Visible = false;
  520. 力矩传感器检验ToolStripMenuItem.Visible = false;
  521. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  522. //显示生产信息
  523. 生产信息ToolStripMenuItem.Visible = true;
  524. //显示电机类型,但不可编辑
  525. 电机类型ToolStripMenuItem.Visible = true;
  526. 中置电机ToolStripMenuItem.Enabled = false;
  527. 轮毂电机ToolStripMenuItem.Enabled = false;
  528. if (uARTToolStripMenuItem.Checked)
  529. UART协议ToolStripMenuItem.Visible = true;
  530. //隐藏研发调试界面
  531. tabPage_MotorParam.Parent = null;
  532. tabPage_BikeParam.Parent = null;
  533. tabPage_BikeParam2.Parent = null;
  534. tabPage_ControlParam.Parent = null;
  535. tabPage_SensorParam.Parent = null;
  536. tabPage_AssistParam.Parent = null;
  537. tabPage_UsrRideParam.Parent = null;
  538. tabPage_DebugParam.Parent = null;
  539. tabPage_RecordInfo.Parent = null;
  540. tabPage_OtherInfo.Parent = null;
  541. tabPage_OBC.Parent = null;
  542. tabPage_RAMorFLASH.Parent = null;
  543. tabPage_FactoryMode.Parent = null;
  544. tabPage_DebugInfo.Parent = null;
  545. tabPage_AngleCal.Parent = null;
  546. //显示运行信息
  547. tabPage_RunInfo.Parent = tabControl2;
  548. //根据电机类型修改生产信息和电机类型
  549. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  550. {
  551. 中置电机ToolStripMenuItem.Checked = true;
  552. 轮毂电机ToolStripMenuItem.Checked = false;
  553. toolStripTextBox_MACPD.Text = "MM_MC1";
  554. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  555. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  556. }
  557. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  558. {
  559. 中置电机ToolStripMenuItem.Checked = false;
  560. 轮毂电机ToolStripMenuItem.Checked = true;
  561. toolStripTextBox_MACPD.Text = "GF_250_1";
  562. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  563. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  564. }
  565. //显示对应生产测试界面
  566. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  567. {
  568. tabPage_ProductMode_Write.Parent = tabControl1;
  569. tabPage_ProductMode_Write.Select();
  570. tabPage_ProductMode_Read.Parent = null;
  571. }
  572. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  573. {
  574. tabPage_ProductMode_Read.Parent = tabControl1;
  575. tabPage_ProductMode_Read.Select();
  576. tabPage_ProductMode_Write.Parent = null;
  577. }
  578. //应答指令不提示
  579. ACK_DisFlag = false;
  580. //退出登录
  581. break;
  582. }
  583. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  584. {
  585. //隐藏工作台内容,新建窗口完成配置
  586. groupBox1.Visible = false;
  587. groupBox3.Visible = false;
  588. tabControl2.Visible = false;
  589. //隐藏提示信息
  590. label_StarInfo.Visible = false;
  591. //打开参数配置框
  592. GenerateParamsForm.ShowDialog();
  593. System.Environment.Exit(0);
  594. //退出登录
  595. break;
  596. }
  597. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  598. {
  599. //隐藏量产界面
  600. tabPage_ProductMode_Read.Parent = null;
  601. tabPage_ProductMode_Write.Parent = null;
  602. //隐藏配置项
  603. 其它配置项ToolStripMenuItem.Visible = false;
  604. 服务器配置ToolStripMenuItem.Visible = false;
  605. 判断阈值ToolStripMenuItem.Visible = false;
  606. 力矩传感器检验ToolStripMenuItem.Visible = false;
  607. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  608. mOS内阻范围ToolStripMenuItem.Visible = false;
  609. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  610. //显示生产信息
  611. 生产信息ToolStripMenuItem.Visible = true;
  612. //显示电机类型,但不可编辑
  613. 电机类型ToolStripMenuItem.Visible = true;
  614. 中置电机ToolStripMenuItem.Enabled = true;
  615. 轮毂电机ToolStripMenuItem.Enabled = true;
  616. if (uARTToolStripMenuItem.Checked)
  617. UART协议ToolStripMenuItem.Visible = true;
  618. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  619. {
  620. 中置电机ToolStripMenuItem.Checked = true;
  621. 轮毂电机ToolStripMenuItem.Checked = false;
  622. toolStripTextBox_MACPD.Text = "MM_MC1";
  623. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  624. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  625. }
  626. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  627. {
  628. 中置电机ToolStripMenuItem.Checked = false;
  629. 轮毂电机ToolStripMenuItem.Checked = true;
  630. toolStripTextBox_MACPD.Text = "GF_250_1";
  631. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  632. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  633. }
  634. //退出登录
  635. break;
  636. }
  637. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  638. {
  639. //隐藏设置项
  640. 其它配置项ToolStripMenuItem.Visible = false;
  641. 写入存储ToolStripMenuItem.Visible = false;
  642. 服务器配置ToolStripMenuItem.Visible = false;
  643. 判断阈值ToolStripMenuItem.Visible = false;
  644. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  645. mOS内阻范围ToolStripMenuItem.Visible = false;
  646. 力矩传感器检验ToolStripMenuItem.Visible = false;
  647. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  648. //显示生产信息
  649. 生产信息ToolStripMenuItem.Visible = true;
  650. //显示电机类型,但不可编辑
  651. 电机类型ToolStripMenuItem.Visible = false;
  652. 中置电机ToolStripMenuItem.Enabled = false;
  653. 轮毂电机ToolStripMenuItem.Enabled = false;
  654. if (uARTToolStripMenuItem.Checked)
  655. UART协议ToolStripMenuItem.Visible = true;
  656. //隐藏研发调试界面
  657. tabPage_MotorParam.Parent = null;
  658. tabPage_BikeParam.Parent = null;
  659. tabPage_BikeParam2.Parent = null;
  660. tabPage_ControlParam.Parent = null;
  661. tabPage_SensorParam.Parent = null;
  662. tabPage_AssistParam.Parent = null;
  663. tabPage_UsrRideParam.Parent = null;
  664. tabPage_DebugParam.Parent = null;
  665. tabPage_RecordInfo.Parent = null;
  666. tabPage_OtherInfo.Parent = null;
  667. tabPage_OBC.Parent = null;
  668. tabPage_RAMorFLASH.Parent = null;
  669. tabPage_FactoryMode.Parent = null;
  670. tabPage_DebugInfo.Parent = null;
  671. tabPage_AngleCal.Parent = null;
  672. //显示运行信息
  673. tabPage_RunInfo.Parent = tabControl2;
  674. //目前仅轮毂使用
  675. 中置电机ToolStripMenuItem.Checked = false;
  676. 轮毂电机ToolStripMenuItem.Checked = true;
  677. toolStripTextBox_MACPD.Text = "GF_250_1";
  678. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  679. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  680. //显示量产测试界面
  681. tabPage_ProductMode_Write.Parent = tabControl1;
  682. tabPage_ProductMode_Write.Select();
  683. tabPage_ProductMode_Read.Parent = null;
  684. checkBox_OffLineFacMode.Checked = false;
  685. checkBox_OffLineFacMode.Enabled = true;
  686. checkBox_OffLineCheckMode.Checked = false;
  687. checkBox_OffLineCheckMode.Enabled = true;
  688. //应答指令不提示
  689. ACK_DisFlag = false;
  690. //退出登录
  691. break;
  692. }
  693. else if (EnterForm1.comboBox_User.Text == "研发调试")
  694. {
  695. //隐藏量产界面
  696. tabPage_ProductMode_Read.Parent = null;
  697. tabPage_ProductMode_Write.Parent = null;
  698. 服务器配置ToolStripMenuItem.Visible = false;
  699. if (uARTToolStripMenuItem.Checked)
  700. UART协议ToolStripMenuItem.Visible = true;
  701. //退出登录
  702. break;
  703. }
  704. else if (EnterForm1.comboBox_User.Text == "管理员")
  705. {
  706. //不隐藏任何界面
  707. //...
  708. //退出登录
  709. break;
  710. }
  711. else
  712. {
  713. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  714. //重新登录
  715. continue;
  716. }
  717. }
  718. else
  719. {
  720. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  721. //重新登录
  722. continue;
  723. }
  724. }
  725. catch (Exception)
  726. {
  727. System.Environment.Exit(0);
  728. }
  729. } while (true);
  730. //配置网络FTP服务器
  731. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  732. //创建线程,定时检测网络连接状态
  733. Thread th = new Thread(NetworkCheck);
  734. th.IsBackground = true;
  735. th.Start();
  736. //允许跨线程访问
  737. Control.CheckForIllegalCrossThreadCalls = false;
  738. }
  739. /// <summary>
  740. /// 检查网络状态线程
  741. /// </summary>
  742. private void NetworkCheck()
  743. {
  744. //允许离线使用,直接退出
  745. if (OfflineFlag == true) //允许离线使用
  746. {
  747. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  748. return;
  749. }
  750. //不允许离线使用,实时监测网络状态
  751. else
  752. {
  753. //初始化第一次连接FTP服务器
  754. bool Result = myFtp.CheckFtp();
  755. if (Result == true)//服务器连接成功
  756. {
  757. myFtp.IsNetConnected = true;
  758. //上传登录日志
  759. do
  760. {
  761. //日志文件名
  762. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  763. string fileName = date;
  764. //日志内容
  765. string fileInfo = Local_HdInformation;
  766. //保存本地
  767. if (!Directory.Exists(localInfo.LocalLogPath))
  768. Directory.CreateDirectory(localInfo.LocalLogPath);
  769. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  770. //上传服务器
  771. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  772. } while (false);
  773. }
  774. else//服务器连接失败
  775. {
  776. myFtp.IsNetConnected = false;
  777. if (EnterForm1.comboBox_User.Text != "管理员")
  778. {
  779. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  780. this.Close();
  781. }
  782. }
  783. //创建定时器,定时30s检查网络
  784. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  785. timer_CheckNet.Enabled = true;
  786. timer_CheckNet.Interval = 30000;
  787. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  788. timer_CheckNet.Start();
  789. while (true)
  790. {
  791. Thread.Sleep(1);
  792. if (myFtp.IsNetConnected == false)
  793. {
  794. label_Server_ComStatus.Text = "网络已断开";
  795. label_ServerStatus.BackColor = Color.Red;
  796. }
  797. else
  798. {
  799. label_Server_ComStatus.Text = "网络已连接";
  800. label_ServerStatus.BackColor = Color.Green;
  801. }
  802. }
  803. }
  804. }
  805. /// <summary>
  806. /// 线程中定时任务,检查网络状态
  807. /// </summary>
  808. /// <param name="sender"></param>
  809. /// <param name="e"></param>
  810. private void timer_CheckNet_Tick(object sender, EventArgs e)
  811. {
  812. //连接FTP服务器
  813. bool Result = myFtp.CheckFtp();
  814. if (Result == true)//服务器连接成功
  815. {
  816. myFtp.IsNetConnected = true;
  817. //允许使用
  818. groupBox1.Enabled = true;
  819. groupBox3.Enabled = true;
  820. tabControl2.Enabled = true;
  821. }
  822. else//服务器连接失败
  823. {
  824. myFtp.IsNetConnected = false;
  825. if (EnterForm1.comboBox_User.Text != "管理员")
  826. {
  827. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  828. //禁止使用
  829. groupBox1.Enabled = false;
  830. groupBox3.Enabled = false;
  831. tabControl2.Enabled = false;
  832. }
  833. }
  834. }
  835. #region 非独占性延时函数
  836. public static void Delay_ms(int milliSecond)
  837. {
  838. int start = Environment.TickCount;
  839. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  840. {
  841. Application.DoEvents();
  842. }
  843. }
  844. #endregion
  845. private void MainForm_Load(object sender, System.EventArgs e)
  846. {
  847. timer_500ms.Start();
  848. //页面初始化
  849. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  850. label_Computername.Text = System.Environment.UserName;
  851. label_UserName.Text = EnterForm1.comboBox_User.Text;
  852. //位置校准表格初始化
  853. for (int i = 0; i < 7; i++)
  854. {
  855. int index = dataGridView_AngleCal.Rows.Add();
  856. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  857. }
  858. dataGridView_AngleCal.AllowUserToAddRows = false;
  859. this.Text += Version;
  860. //检查版本,自动更新
  861. do
  862. {
  863. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  864. {
  865. break;
  866. }
  867. //检查网络状态
  868. if (myFtp.CheckFtp() == false)
  869. {
  870. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  871. break;
  872. }
  873. else
  874. {
  875. //检查本地文件删除
  876. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  877. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  878. //读取最新版本号
  879. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  880. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  881. string sLine = "";
  882. ArrayList arrText = new ArrayList();//创建一个动态数组
  883. while (sLine != null)
  884. {
  885. sLine = objReader.ReadLine();
  886. arrText.Add(sLine);
  887. }
  888. objReader.Close();
  889. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  890. //检查是否有最新版本
  891. string[] VerOld = mainForm.Version.Trim().Split('.');
  892. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  893. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  894. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  895. if (VerNew_int <= VerOld_int)
  896. {
  897. //版本已是最新,跳出
  898. break;
  899. }
  900. //确认下载最新版本
  901. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  902. {
  903. string SavePath = Directory.GetCurrentDirectory();
  904. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  905. foreach (string file in FileList)
  906. {
  907. if (file.Contains(".exe"))
  908. {
  909. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  910. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  911. System.Environment.Exit(0);
  912. }
  913. }
  914. }
  915. }
  916. } while (false);
  917. //下拉控件初始值设定
  918. comboBox_WorkMode.SelectedIndex = 0;
  919. comboBox_GearSt.SelectedIndex = 0;
  920. comboBox_LightSwitch.SelectedIndex = 1;
  921. comboBox_OBC_SetGearST.SelectedIndex = 0;
  922. comboBox_OBC_LightSw.SelectedIndex = 1;
  923. comboBox_AssistTorque.SelectedIndex = 0;
  924. comboBox_AssistCadence.SelectedIndex = 0;
  925. //combobox事件定义
  926. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  927. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  928. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  929. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  930. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  931. //端口自动连接
  932. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  933. {
  934. try
  935. {
  936. PortConnect();
  937. }
  938. catch (System.Exception)
  939. {
  940. timer_500ms.Enabled = false;
  941. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  942. timer_500ms.Enabled = true;
  943. }
  944. }
  945. //不识别联动装置盒自动打开界面
  946. #if true
  947. groupBox1.Visible = true;
  948. groupBox3.Visible = true;
  949. tabControl2.Visible = true;
  950. label_StarInfo.Visible = false;
  951. #endif
  952. //创建线程,定时解析数据
  953. Thread th = new Thread(Task_SerialProcess);
  954. th.IsBackground = true;
  955. th.Start();
  956. }
  957. #region 结构体与字节流相互转换
  958. public static class MyConverter
  959. {
  960. /// <summary>
  961. /// 由结构体转换为byte数组
  962. /// </summary>
  963. public static byte[] StructureToByte<T>(T structure)
  964. {
  965. int size = Marshal.SizeOf(typeof(T));
  966. byte[] buffer = new byte[size];
  967. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  968. try
  969. {
  970. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  971. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  972. }
  973. finally
  974. {
  975. Marshal.FreeHGlobal(bufferIntPtr);
  976. }
  977. return buffer;
  978. }
  979. /// <summary>
  980. /// 由byte数组转换为结构体
  981. /// </summary>
  982. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  983. {
  984. object structure = null;
  985. int size = Marshal.SizeOf(typeof(T));
  986. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  987. try
  988. {
  989. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  990. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  991. }
  992. finally
  993. {
  994. Marshal.FreeHGlobal(allocIntPtr);
  995. }
  996. return (T)structure;
  997. }
  998. }
  999. #endregion
  1000. #region 故障日志解析显示
  1001. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1002. {
  1003. string SaveData = "";
  1004. //Log1
  1005. if (Log1.Error_Index != 0xFFFF)
  1006. {
  1007. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1008. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1009. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1010. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1011. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1012. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1013. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1014. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1015. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1016. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1017. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1018. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1019. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1020. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1021. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1022. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1023. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1024. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1025. {
  1026. SaveData += "续航:" + "---km" + ", ";
  1027. }
  1028. else
  1029. {
  1030. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1031. }
  1032. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1033. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1034. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1035. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1036. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1037. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1038. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1039. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1040. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1041. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1042. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1043. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1044. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1045. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1046. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1047. SaveData += "\r\n\r\n";
  1048. richTextBox_Record.AppendText(SaveData);
  1049. SaveData = "";
  1050. }
  1051. //Log2
  1052. if (Log2.Error_Index != 0xFFFF)
  1053. {
  1054. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1055. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1056. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1057. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1058. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1059. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1060. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1061. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1062. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1063. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1064. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1065. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1066. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1067. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1068. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1069. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1070. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1071. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1072. {
  1073. SaveData += "续航:" + "---km" + ", ";
  1074. }
  1075. else
  1076. {
  1077. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1078. }
  1079. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1080. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1081. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1082. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1083. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1084. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1085. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1086. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1087. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1088. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1089. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1090. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1091. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1092. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1093. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1094. SaveData += "\r\n\r\n";
  1095. richTextBox_Record.AppendText(SaveData);
  1096. SaveData = "";
  1097. }
  1098. }
  1099. #endregion
  1100. #region 串口数据解析线程
  1101. /// <summary>
  1102. /// 串口数据解析线程
  1103. /// </summary>
  1104. private void Task_SerialProcess()
  1105. {
  1106. //创建定时器,定时读取串口数据
  1107. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1108. timer_ReadSerial.Enabled = true;
  1109. timer_ReadSerial.Interval = 20;
  1110. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1111. timer_ReadSerial.Start();
  1112. while (true)
  1113. {
  1114. Thread.Sleep(1);
  1115. };
  1116. }
  1117. /// <summary>
  1118. /// 串口解析定时器
  1119. /// </summary>
  1120. /// <param name="sender"></param>
  1121. /// <param name="e"></param>
  1122. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1123. {
  1124. //串口解析
  1125. Serial_process(mySerialProcess.buffer);
  1126. }
  1127. #endregion
  1128. #region 数据解析
  1129. public void Serial_process(List<byte> buffer)
  1130. {
  1131. byte DataNum = 0; //记录每条命令数据段的长度
  1132. ushort PackageID, Cmd;
  1133. byte[] Data = new byte[1024];
  1134. try
  1135. {
  1136. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1137. {
  1138. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1139. {
  1140. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1141. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1142. {
  1143. int CmdLen = buffer[5];
  1144. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1145. while (CmdLen > 0) //读取命令段
  1146. {
  1147. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1148. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1149. if (DataNum <= (CmdLen - 2))
  1150. {
  1151. for (int i = 0; i < DataNum; i++)
  1152. {
  1153. Data[i] = buffer[i + 8];
  1154. }
  1155. // 串口接收的数据 显示在子窗口
  1156. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1157. {
  1158. string strTemp = String.Empty;
  1159. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1160. for (int i = 0; i < CmdLen + 11; i++)
  1161. {
  1162. strTemp += (buffer[i].ToString("X2") + " ");
  1163. }
  1164. strTemp += "\n";
  1165. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1166. }
  1167. buffer.RemoveRange(0, CmdLen + 11);
  1168. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1169. DataRevToString(Cmd, Data);//指令数据转为字符串
  1170. }
  1171. }
  1172. }
  1173. else
  1174. {
  1175. buffer.RemoveAt(0);//ID不对
  1176. }
  1177. }
  1178. else
  1179. {
  1180. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1181. }
  1182. }
  1183. }
  1184. catch (Exception)
  1185. {
  1186. }
  1187. }
  1188. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1189. {
  1190. int DataTemp;
  1191. ushort uData16;
  1192. unchecked
  1193. {
  1194. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1195. }
  1196. #region 解析发送给CDL的指令
  1197. if (ID == 0x7FF)
  1198. {
  1199. switch (CmdTemp)
  1200. {
  1201. case 0x1100://
  1202. {
  1203. unchecked
  1204. {
  1205. this.Invoke((EventHandler)(delegate
  1206. {
  1207. //CDL连接成功
  1208. mySerialProcess.CDL_Online_Flag = true;
  1209. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1210. groupBox1.Visible = true;
  1211. groupBox3.Visible = true;
  1212. tabControl2.Visible = true;
  1213. label_StarInfo.Visible = false;
  1214. }));
  1215. }
  1216. break;
  1217. }
  1218. default: break;
  1219. }
  1220. }
  1221. #endregion
  1222. #region 解析电机的命令
  1223. else if ((ID == 0x715) || (ID == 0x710))
  1224. {
  1225. switch (CmdTemp)
  1226. {
  1227. case 0x1020://电机运行信息
  1228. {
  1229. unchecked
  1230. {
  1231. this.Invoke((EventHandler)(delegate
  1232. {
  1233. MC_RunInfo_Refresh = true;
  1234. //车速
  1235. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1236. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1237. //输出转速
  1238. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1239. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1240. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1241. Class_MotorSpeed.Data = DataTemp;
  1242. //电功率
  1243. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1244. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1245. //母线电压
  1246. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1247. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1248. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1249. //母线电流
  1250. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1251. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1252. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1253. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1254. Class_CurrentData.Data = DataTemp;
  1255. //踏频
  1256. DataTemp = (ushort)(Data[10]);
  1257. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1258. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1259. Class_CadenceData.Data = DataTemp;
  1260. //踩踏力矩
  1261. DataTemp = (ushort)(Data[11]);
  1262. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1263. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1264. Class_TorqueData.Data = DataTemp;
  1265. //踩踏方向
  1266. DataTemp = (ushort)(Data[12]);
  1267. if (DataTemp == 0)
  1268. {
  1269. textBox_RunInfo_Dir.Text = "正向";
  1270. }
  1271. else if (DataTemp == 1)
  1272. {
  1273. textBox_RunInfo_Dir.Text = "反向";
  1274. }
  1275. else if (DataTemp == 2)
  1276. {
  1277. textBox_RunInfo_Dir.Text = "停止";
  1278. }
  1279. //助力档位
  1280. DataTemp = (ushort)(Data[13]);
  1281. if (DataTemp == 0x33)
  1282. {
  1283. textBox_RunInfo_GearSt.Text = "SMART";
  1284. //comboBox_GearSt.SelectedIndex = 5;
  1285. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1286. }
  1287. else if (DataTemp == 0x22)
  1288. {
  1289. textBox_RunInfo_GearSt.Text = "WALK";
  1290. //comboBox_GearSt.SelectedIndex = 6;
  1291. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1292. }
  1293. else
  1294. {
  1295. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1296. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1297. //comboBox_GearSt.SelectedIndex = DataTemp;
  1298. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1299. }
  1300. //大灯状态
  1301. DataTemp = (ushort)(Data[14]);
  1302. if (DataTemp == 0xF0)
  1303. {
  1304. textBox_RunInfo_LightSwitch.Text = "OFF";
  1305. //comboBox_LightSwitch.SelectedIndex = 1;
  1306. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1307. }
  1308. else if (DataTemp == 0xF1)
  1309. {
  1310. textBox_RunInfo_LightSwitch.Text = "ON";
  1311. //comboBox_LightSwitch.SelectedIndex = 0;
  1312. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1313. }
  1314. //剩余电量
  1315. DataTemp = (ushort)(Data[15]);
  1316. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1317. //剩余续航里程
  1318. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1319. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1320. {
  1321. textBox_RunInfo_Range.Text = "---";
  1322. }
  1323. else
  1324. {
  1325. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1326. }
  1327. //预留(显示力矩Reg),空2bytes
  1328. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1329. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1330. //平均功耗
  1331. DataTemp = (ushort)(Data[20]);
  1332. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1333. //PCB温度
  1334. DataTemp = (ushort)(Data[21]);
  1335. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1336. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1337. Class_MotorTemp.Data = DataTemp - 40;
  1338. //绕组温度
  1339. DataTemp = (ushort)(Data[22]);
  1340. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1341. //MCU温度
  1342. DataTemp = (ushort)(Data[23]);
  1343. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1344. //单次里程
  1345. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1346. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1347. //单次时间
  1348. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1349. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1350. //数据保存
  1351. RunInfoAutoSave();
  1352. }));
  1353. }
  1354. break;
  1355. }
  1356. case 0x1104://故障码
  1357. {
  1358. unchecked
  1359. {
  1360. this.Invoke((EventHandler)(delegate
  1361. {
  1362. MC_ErrorCode_Refresh = true;
  1363. textBox_ErrorCode.Text =
  1364. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1365. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1366. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1367. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1368. "H";
  1369. }));
  1370. }
  1371. break;
  1372. }
  1373. case 0xA903://反馈指令
  1374. {
  1375. unchecked
  1376. {
  1377. this.Invoke((EventHandler)(delegate
  1378. {
  1379. if (ACK_DisFlag == true)
  1380. {
  1381. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1382. //关机反馈
  1383. PowerOffAckStatus = true;
  1384. }
  1385. //应答标志置位
  1386. WriteACK = true;
  1387. }));
  1388. }
  1389. break;
  1390. }
  1391. case 0xB226://马达参数
  1392. {
  1393. unchecked
  1394. {
  1395. this.Invoke((EventHandler)(delegate
  1396. {
  1397. richTextBox_MotorParam.Clear();
  1398. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1399. {
  1400. if (i == 6)
  1401. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1402. else
  1403. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1404. }
  1405. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1406. }));
  1407. }
  1408. break;
  1409. }
  1410. case 0xB31A://整车信息
  1411. {
  1412. unchecked
  1413. {
  1414. this.Invoke((EventHandler)(delegate
  1415. {
  1416. richTextBox_BikeParam.Clear();
  1417. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1418. {
  1419. if (i == 9)
  1420. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1421. else
  1422. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1423. //更新前后灯参数
  1424. if (i == 8)
  1425. {
  1426. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1427. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1428. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1429. }
  1430. //更新开关机参数
  1431. else if (i == 11)
  1432. {
  1433. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1434. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1435. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1436. }
  1437. }
  1438. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1439. }));
  1440. }
  1441. break;
  1442. }
  1443. case 0xB420://控制器参数
  1444. {
  1445. unchecked
  1446. {
  1447. this.Invoke((EventHandler)(delegate
  1448. {
  1449. richTextBox_ControlParam.Clear();
  1450. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1451. {
  1452. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1453. //转把定速巡航
  1454. if (i == 13)
  1455. {
  1456. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1457. }
  1458. }
  1459. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1460. }));
  1461. }
  1462. break;
  1463. }
  1464. case 0xB528://传感器参数
  1465. {
  1466. unchecked
  1467. {
  1468. this.Invoke((EventHandler)(delegate
  1469. {
  1470. richTextBox_SensorParam.Clear();
  1471. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1472. {
  1473. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1474. }
  1475. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1476. //更新生产模式页面传感器零点和标定值
  1477. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1478. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1479. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1480. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1481. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1482. WriteACK = true;
  1483. }));
  1484. }
  1485. break;
  1486. }
  1487. case 0xB64C://助力参数
  1488. {
  1489. unchecked
  1490. {
  1491. this.Invoke((EventHandler)(delegate
  1492. {
  1493. richTextBox_AssistParam.Clear();
  1494. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1495. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1496. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1497. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1498. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1499. {
  1500. if (i < index_1) //数据占用2bytes
  1501. {
  1502. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1503. }
  1504. else if (i <= index_2) //数据占用4bytes
  1505. {
  1506. 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])) + ", ");
  1507. }
  1508. else if (i < index_3) //数据占用2bytes,无符号
  1509. {
  1510. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1511. }
  1512. else if (i <= index_4) //数据占用2bytes,有符号
  1513. {
  1514. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1515. }
  1516. else //数据占用2bytes,无符号
  1517. {
  1518. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1519. }
  1520. }
  1521. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1522. }));
  1523. }
  1524. break;
  1525. }
  1526. case 0xB74C://历史记录
  1527. {
  1528. unchecked
  1529. {
  1530. this.Invoke((EventHandler)(delegate
  1531. {
  1532. richTextBox_Record.Clear();
  1533. for (int i = 0; i < myParams.Record.Count; i++)
  1534. {
  1535. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1536. }
  1537. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1538. }));
  1539. }
  1540. break;
  1541. }
  1542. case 0xB83A://调试参数
  1543. {
  1544. unchecked
  1545. {
  1546. this.Invoke((EventHandler)(delegate
  1547. {
  1548. richTextBox_DebugParam.Clear();
  1549. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1550. {
  1551. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1552. }
  1553. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1554. }));
  1555. }
  1556. break;
  1557. }
  1558. case 0xB904://存储标志
  1559. {
  1560. unchecked
  1561. {
  1562. this.Invoke((EventHandler)(delegate
  1563. {
  1564. ushort Flag = 0;
  1565. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1566. if (Flag == 0)
  1567. {
  1568. radioButton_EE_SaveNo.Checked = true;
  1569. radioButton_EE_SaveYes.Checked = false;
  1570. }
  1571. else
  1572. {
  1573. radioButton_EE_SaveNo.Checked = false;
  1574. radioButton_EE_SaveYes.Checked = true;
  1575. }
  1576. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1577. if (Flag == 0)
  1578. {
  1579. radioButton_SIP_SaveNo.Checked = true;
  1580. radioButton_SIP_SaveYes.Checked = false;
  1581. }
  1582. else
  1583. {
  1584. radioButton_SIP_SaveNo.Checked = false;
  1585. radioButton_SIP_SaveYes.Checked = true;
  1586. }
  1587. }));
  1588. }
  1589. break;
  1590. }
  1591. case 0x1240://电机版本信息
  1592. {
  1593. unchecked
  1594. {
  1595. this.Invoke((EventHandler)(delegate
  1596. {
  1597. //电机型号
  1598. textBox_Model.Text = "";
  1599. textBox_OBC_ReadModel.Text = "";
  1600. textBox_FacModeName.Text = "";
  1601. for (ushort i = 0; i < 16; i++)
  1602. {
  1603. if (Data[i] == 0x2E)
  1604. {
  1605. break;
  1606. }
  1607. textBox_Model.Text += ((char)Data[i]).ToString();
  1608. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1609. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1610. }
  1611. Class_Motor_Ver.Mode = textBox_Model.Text;
  1612. //电机SN
  1613. textBox_SN.Text = "";
  1614. textBox_OBC_ReadSN.Text = "";
  1615. textBox_FacModeNum.Text = "";
  1616. for (ushort i = 0; i < 16; i++)
  1617. {
  1618. if (Data[16 + i] == 0x2E)
  1619. {
  1620. break;
  1621. }
  1622. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1623. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1624. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1625. }
  1626. Class_Motor_Ver.SN = textBox_SN.Text;
  1627. //电机HW
  1628. textBox_HW.Text = "";
  1629. textBox_OBC_ReadHW.Text = "";
  1630. textBox_FacModeHW.Text = "";
  1631. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1632. {
  1633. if (Data[32 + i] == 0x2E)
  1634. {
  1635. break;
  1636. }
  1637. else if (Data[32 + i] == 'r')
  1638. {
  1639. Data[32 + i] = (byte)'.';
  1640. break;
  1641. }
  1642. string strTemp = "";
  1643. strTemp = ((char)Data[32 + i]).ToString();
  1644. textBox_HW.Text += strTemp;
  1645. textBox_OBC_ReadHW.Text += strTemp;
  1646. textBox_FacModeHW.Text += strTemp;
  1647. }
  1648. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1649. {
  1650. if (Data[40 + i] == 0x2E)
  1651. {
  1652. break;
  1653. }
  1654. else if (Data[40 + i] == 'r')
  1655. {
  1656. Data[40 + i] = (byte)'.';
  1657. break;
  1658. }
  1659. string strTemp = "";
  1660. strTemp = ((char)Data[40 + i]).ToString();
  1661. textBox_HW.Text += strTemp;
  1662. textBox_OBC_ReadHW.Text += strTemp;
  1663. textBox_FacModeHW.Text += strTemp;
  1664. }
  1665. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1666. {
  1667. string strTemp = "";
  1668. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1669. textBox_HW.Text += strTemp;
  1670. textBox_OBC_ReadHW.Text += strTemp;
  1671. textBox_FacModeHW.Text += strTemp;
  1672. }
  1673. Class_Motor_Ver.HW = textBox_HW.Text;
  1674. //电机FW
  1675. textBox_FW.Text = "";
  1676. textBox_OBC_ReadFW.Text = "";
  1677. textBox_FacModeFW.Text = "";
  1678. for (ushort i = 0; i < 16; i++)
  1679. {
  1680. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1681. {
  1682. break;
  1683. }
  1684. if (Data[48 + i] == 'r')
  1685. {
  1686. Data[48 + i] = (byte)'.';
  1687. }
  1688. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1689. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1690. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1691. }
  1692. Class_Motor_Ver.FW = textBox_FW.Text;
  1693. }));
  1694. }
  1695. break;
  1696. }
  1697. case 0xA610://自定义1
  1698. {
  1699. unchecked
  1700. {
  1701. this.Invoke((EventHandler)(delegate
  1702. {
  1703. textBox_User1.Text = "";
  1704. for (ushort i = 0; i < 16; i++)
  1705. {
  1706. if (Data[i] == 0x2E)
  1707. {
  1708. break;
  1709. }
  1710. textBox_User1.Text += ((char)Data[i]).ToString();
  1711. }
  1712. }));
  1713. }
  1714. break;
  1715. }
  1716. case 0xA710://自定义2
  1717. {
  1718. unchecked
  1719. {
  1720. this.Invoke((EventHandler)(delegate
  1721. {
  1722. textBox_User2.Text = "";
  1723. for (ushort i = 0; i < 16; i++)
  1724. {
  1725. if (Data[i] == 0x2E)
  1726. {
  1727. break;
  1728. }
  1729. textBox_User2.Text += ((char)Data[i]).ToString();
  1730. }
  1731. }));
  1732. }
  1733. break;
  1734. }
  1735. case 0xA810://自定义1
  1736. {
  1737. unchecked
  1738. {
  1739. this.Invoke((EventHandler)(delegate
  1740. {
  1741. textBox_User3.Text = "";
  1742. for (ushort i = 0; i < 16; i++)
  1743. {
  1744. if (Data[i] == 0x2E)
  1745. {
  1746. break;
  1747. }
  1748. textBox_User3.Text += ((char)Data[i]).ToString();
  1749. }
  1750. }));
  1751. }
  1752. break;
  1753. }
  1754. case 0xA520://生产信息
  1755. {
  1756. unchecked
  1757. {
  1758. this.Invoke((EventHandler)(delegate
  1759. {
  1760. //生产商
  1761. textBox_MAC.Text = "";
  1762. for (ushort i = 0; i < 8; i++)
  1763. {
  1764. if (Data[i] == 0x2E)
  1765. {
  1766. break;
  1767. }
  1768. textBox_MAC.Text += ((char)Data[i]).ToString();
  1769. }
  1770. //生产地
  1771. textBox_MACAdd.Text = "";
  1772. for (ushort i = 0; i < 8; i++)
  1773. {
  1774. if (Data[8 + i] == 0x2E)
  1775. {
  1776. break;
  1777. }
  1778. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1779. }
  1780. //生产日期
  1781. textBox_MACDate.Text = "";
  1782. for (ushort i = 0; i < 8; i++)
  1783. {
  1784. if (Data[16 + i] == 0x2E)
  1785. {
  1786. break;
  1787. }
  1788. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1789. }
  1790. //品牌信息
  1791. textBox_PP.Text = "";
  1792. for (ushort i = 0; i < 8; i++)
  1793. {
  1794. if (Data[24 + i] == 0x2E)
  1795. {
  1796. break;
  1797. }
  1798. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1799. }
  1800. }));
  1801. }
  1802. break;
  1803. }
  1804. case 0xA408://密钥
  1805. {
  1806. unchecked
  1807. {
  1808. this.Invoke((EventHandler)(delegate
  1809. {
  1810. textBox_Key.Text = "";
  1811. for (ushort i = 0; i < 8; i++)
  1812. {
  1813. textBox_Key.Text += ((char)Data[i]).ToString();
  1814. }
  1815. }));
  1816. }
  1817. break;
  1818. }
  1819. case 0xAB09://存储器数据
  1820. case 0xAB0A:
  1821. case 0xAB0B:
  1822. case 0xAB0C:
  1823. {
  1824. unchecked
  1825. {
  1826. this.Invoke((EventHandler)(delegate
  1827. {
  1828. long ByteNum = 0;
  1829. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1830. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1831. {
  1832. for (int i = 0; i < ByteNum; i++)
  1833. {
  1834. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1835. }
  1836. }
  1837. else //根据设置自动转换10进制显示
  1838. {
  1839. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1840. {
  1841. switch (ByteNum)
  1842. {
  1843. case 1:
  1844. {
  1845. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1846. break;
  1847. }
  1848. case 2:
  1849. {
  1850. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1851. break;
  1852. }
  1853. case 3:
  1854. {
  1855. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1856. break;
  1857. }
  1858. case 4:
  1859. {
  1860. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1861. break;
  1862. }
  1863. default:
  1864. {
  1865. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1866. break;
  1867. }
  1868. }
  1869. }
  1870. else //16进制显示
  1871. {
  1872. switch (ByteNum)
  1873. {
  1874. case 1:
  1875. {
  1876. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1877. break;
  1878. }
  1879. case 2:
  1880. {
  1881. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1882. break;
  1883. }
  1884. case 3:
  1885. {
  1886. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1887. break;
  1888. }
  1889. case 4:
  1890. {
  1891. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1892. break;
  1893. }
  1894. default:
  1895. {
  1896. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1897. break;
  1898. }
  1899. }
  1900. }
  1901. }
  1902. }));
  1903. }
  1904. break;
  1905. }
  1906. case 0xAB88://故障日志
  1907. {
  1908. unchecked
  1909. {
  1910. this.Invoke((EventHandler)(delegate
  1911. {
  1912. //电机存储的故障日志,一包128字节包含2条故障日志
  1913. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1914. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1915. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1916. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1917. //数据显示
  1918. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1919. }));
  1920. }
  1921. break;
  1922. }
  1923. case 0x1401://在线检测结果
  1924. {
  1925. unchecked
  1926. {
  1927. this.Invoke((EventHandler)(delegate
  1928. {
  1929. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1930. }));
  1931. }
  1932. break;
  1933. }
  1934. case 0x1510://骑行历史信息
  1935. {
  1936. unchecked
  1937. {
  1938. this.Invoke((EventHandler)(delegate
  1939. {
  1940. long DataTemp32;
  1941. //ODO里程
  1942. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1943. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1944. textBox_ODO_KM.Text = DataTemp32.ToString();
  1945. //ODO时间
  1946. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1947. if (DataTemp32 >= 60 * 100000)
  1948. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1949. else
  1950. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1951. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1952. //TRIP里程
  1953. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1954. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1955. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1956. //TRIP时间
  1957. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1958. if (DataTemp32 >= 60 * 100000)
  1959. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1960. else
  1961. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1962. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1963. }));
  1964. }
  1965. break;
  1966. }
  1967. case 0x1720://客户信息
  1968. {
  1969. unchecked
  1970. {
  1971. this.Invoke((EventHandler)(delegate
  1972. {
  1973. //软件标识
  1974. textBox_SP.Text = "";
  1975. textBox_OBC_ReadSP.Text = "";
  1976. textBox_FacModeSP.Text = "";
  1977. for (ushort i = 0; i < 23; i++)
  1978. {
  1979. if (Data[i] == 'r')
  1980. {
  1981. Data[i] = (byte)'.';
  1982. }
  1983. textBox_SP.Text += ((char)Data[i]).ToString();
  1984. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1985. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1986. }
  1987. //Git提交版本信息
  1988. textBox_FacModeGit.Text = "";
  1989. for (ushort i = 0; i < 9; i++)
  1990. {
  1991. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  1992. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  1993. }
  1994. Class_Motor_Ver.Special = textBox_SP.Text;
  1995. }));
  1996. }
  1997. break;
  1998. }
  1999. case 0xBA20: //调试信息
  2000. {
  2001. unchecked
  2002. {
  2003. this.Invoke((EventHandler)(delegate
  2004. {
  2005. MC_DebugInfo_Refresh = true;
  2006. //系统状态机
  2007. DataTemp = (short)(Data[0]);
  2008. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2009. //二层状态机
  2010. DataTemp = (short)(Data[1]);
  2011. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2012. //电机状态机
  2013. DataTemp = (short)(Data[2]);
  2014. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2015. //助力状态机
  2016. DataTemp = (short)(Data[3]);
  2017. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2018. //IdRef
  2019. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2020. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2021. //IqRef
  2022. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2023. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2024. //UdRef
  2025. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2026. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2027. //UqRef
  2028. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2029. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2030. //瞬时力矩
  2031. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2032. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2033. //时间滤波力矩
  2034. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2035. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2036. //踏频滤波力矩
  2037. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2038. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2039. //IdFdb
  2040. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2041. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2042. //IqFdb
  2043. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2044. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2045. //助力输出
  2046. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2047. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2048. //转把百分比
  2049. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2050. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2051. //数据保存
  2052. RunInfoAutoSave();
  2053. }));
  2054. }
  2055. break;
  2056. }
  2057. case 0xBB20: //产品标签信息
  2058. {
  2059. unchecked
  2060. {
  2061. this.Invoke((EventHandler)(delegate
  2062. {
  2063. //产品标签
  2064. textBox_TagInfo.Text = "";
  2065. for (ushort i = 0; i < 32; i++)
  2066. {
  2067. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2068. }
  2069. }));
  2070. }
  2071. break;
  2072. }
  2073. case 0xBC20: //内阻校正信息
  2074. {
  2075. unchecked
  2076. {
  2077. this.Invoke((EventHandler)(delegate
  2078. {
  2079. //内阻1
  2080. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2081. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2082. //内阻2
  2083. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2084. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2085. //内阻3
  2086. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2087. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2088. //K1
  2089. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2090. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2091. //K2
  2092. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2093. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2094. //K3
  2095. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2096. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2097. //K4
  2098. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2099. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2100. //K5
  2101. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2102. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2103. }));
  2104. }
  2105. break;
  2106. }
  2107. case 0xBD20: //整车信息2
  2108. {
  2109. unchecked
  2110. {
  2111. this.Invoke((EventHandler)(delegate
  2112. {
  2113. richTextBox_BikeParam2.Clear();
  2114. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2115. {
  2116. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2117. }
  2118. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2119. }));
  2120. }
  2121. break;
  2122. }
  2123. case 0xBE20: //用户骑行参数
  2124. {
  2125. unchecked
  2126. {
  2127. this.Invoke((EventHandler)(delegate
  2128. {
  2129. richTextBox_UsrRidesParam.Clear();
  2130. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2131. {
  2132. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2133. }
  2134. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2135. }));
  2136. }
  2137. break;
  2138. }
  2139. case 0xBF58:
  2140. {
  2141. unchecked
  2142. {
  2143. this.Invoke((EventHandler)(delegate
  2144. {
  2145. string[] str1 = new string[42];
  2146. double[] error1 = new double[42];
  2147. //更新校准数据
  2148. for (int i = 0; i < 42; i++)
  2149. {
  2150. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2151. error1[i] = data1 - (60 * (i % 6) + 60);
  2152. if (error1[i] < -180)
  2153. {
  2154. error1[i] = error1[i] + 360;
  2155. }
  2156. str1[i] = data1.ToString("F2");
  2157. AngledataRecord[i] = str1[i];
  2158. }
  2159. for (int i = 0; i < 7; i++)
  2160. for (int j = 0; j < 6; j++)
  2161. {
  2162. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2163. }
  2164. //计算偏差最小值、最大值和平均值
  2165. //Array.ConvertAll(error1, Math.Abs);
  2166. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2167. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2168. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2169. //计算零点偏差
  2170. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2171. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2172. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2173. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2174. double tmp3 = (tmp2 - tmp1);
  2175. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2176. }));
  2177. }
  2178. break;
  2179. }
  2180. case 0xC109: //Boot版本信息
  2181. {
  2182. BootInfo = "";
  2183. for (ushort i = 0; i < 9; i++)
  2184. {
  2185. BootInfo += ((char)Data[i]).ToString();
  2186. }
  2187. break;
  2188. }
  2189. default:
  2190. {
  2191. break;
  2192. }
  2193. }
  2194. //存储器导出数据显示
  2195. if ((CmdTemp & 0xFF00) == 0xAB00)
  2196. {
  2197. unchecked
  2198. {
  2199. this.Invoke((EventHandler)(delegate
  2200. {
  2201. long ByteNum = 0;
  2202. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2203. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2204. {
  2205. for (int i = 0; i < ByteNum; i++)
  2206. {
  2207. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2208. }
  2209. }
  2210. }));
  2211. }
  2212. }
  2213. }
  2214. #endregion
  2215. #region 解析BMS广播的命令
  2216. else if (ID == 0x720)
  2217. {
  2218. switch (CmdTemp)
  2219. {
  2220. case 0x1010://BMS运行信息
  2221. {
  2222. unchecked
  2223. {
  2224. this.Invoke((EventHandler)(delegate
  2225. {
  2226. BMS_RunInfo_Refresh = true;
  2227. richTextBox_OBC_BMS_RunInfo.Clear();
  2228. //电压
  2229. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2230. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2231. //电流
  2232. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2233. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2234. //剩余容量
  2235. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2236. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2237. //满充容量
  2238. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2239. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2240. //电芯温度
  2241. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2242. //剩余电量
  2243. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2244. //电池状态
  2245. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2246. //SOH
  2247. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2248. //循环次数
  2249. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2250. }));
  2251. }
  2252. break;
  2253. }
  2254. default: break;
  2255. }
  2256. }
  2257. #endregion
  2258. #region 解析电机发送OBC的命令
  2259. else if (ID == 0x713)
  2260. {
  2261. switch (CmdTemp)
  2262. {
  2263. case 0x5408://电机用户参数
  2264. {
  2265. unchecked
  2266. {
  2267. this.Invoke((EventHandler)(delegate
  2268. {
  2269. richTextBox_OBC_ReadUserInfo.Clear();
  2270. //默认周长
  2271. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2272. //启动模式
  2273. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2274. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2275. //限速
  2276. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2277. //周长微调
  2278. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2279. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2280. //助力方案
  2281. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2282. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2283. //关机时间
  2284. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2285. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2286. //限速微调
  2287. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2288. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2289. //定速巡航
  2290. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2291. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2292. }));
  2293. }
  2294. break;
  2295. }
  2296. case 0x5303://电机应答反馈
  2297. {
  2298. unchecked
  2299. {
  2300. this.Invoke((EventHandler)(delegate
  2301. {
  2302. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2303. }));
  2304. }
  2305. break;
  2306. }
  2307. case 0x5620: //用户骑行参数
  2308. {
  2309. unchecked
  2310. {
  2311. this.Invoke((EventHandler)(delegate
  2312. {
  2313. richTextBox_UsrRidesParam.Clear();
  2314. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2315. {
  2316. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2317. }
  2318. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2319. }));
  2320. }
  2321. break;
  2322. }
  2323. default: break;
  2324. }
  2325. }
  2326. #endregion
  2327. }
  2328. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2329. {
  2330. CmdRevStrTemp = "";
  2331. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2332. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2333. ushort len = (ushort)(CmdTemp & 0x00FF);
  2334. for (int i = 0; i < len ; i++)
  2335. {
  2336. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2337. }
  2338. }
  2339. #endregion
  2340. /// <summary>
  2341. /// 端口连接或断开
  2342. /// </summary>
  2343. private void PortConnect()
  2344. {
  2345. bool result = false;
  2346. if (连接ToolStripMenuItem.Text == "连接")
  2347. {
  2348. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2349. if (result)
  2350. {
  2351. toolStripComboBox_ComNum.Enabled = false;
  2352. toolStripComboBox_Baudrate.Enabled = false;
  2353. 刷新ToolStripMenuItem.Enabled = false;
  2354. 连接ToolStripMenuItem.Text = "断开";
  2355. 连接ToolStripMenuItem.Checked = true;
  2356. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2357. label_PortStatus.BackColor = Color.Green;
  2358. }
  2359. }
  2360. else if (连接ToolStripMenuItem.Text == "断开")
  2361. {
  2362. checkBox_OBC_StartSetGearSt.Checked = false;
  2363. checkBox_OBC_StartReadBMS.Checked = false;
  2364. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2365. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2366. toolStripComboBox_ComNum.Enabled = true;
  2367. toolStripComboBox_Baudrate.Enabled = true;
  2368. 刷新ToolStripMenuItem.Enabled = true;
  2369. 连接ToolStripMenuItem.Text = "连接";
  2370. 连接ToolStripMenuItem.Checked = false;
  2371. label_COM_Sta.Text = "连接状态:未连接";
  2372. label_PortStatus.BackColor = Color.Red;
  2373. }
  2374. }
  2375. /// <summary>
  2376. /// 端口连接事件
  2377. /// </summary>
  2378. /// <param name="sender"></param>
  2379. /// <param name="e"></param>
  2380. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2381. {
  2382. PortConnect();
  2383. }
  2384. /// <summary>
  2385. /// 端口号刷新事件
  2386. /// </summary>
  2387. /// <param name="sender"></param>
  2388. /// <param name="e"></param>
  2389. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2390. {
  2391. toolStripComboBox_ComNum.Items.Clear();
  2392. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2393. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2394. }
  2395. /// <summary>
  2396. /// 存储标志修改事件
  2397. /// </summary>
  2398. /// <param name="sender"></param>
  2399. /// <param name="e"></param>
  2400. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2401. {
  2402. if (写入存储ToolStripMenuItem.Checked)
  2403. {
  2404. EnterForm1.ShowDialog();
  2405. try
  2406. {
  2407. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2408. {
  2409. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2410. {
  2411. 写入存储ToolStripMenuItem.Checked = false;
  2412. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2413. }
  2414. else
  2415. {
  2416. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2417. }
  2418. }
  2419. else
  2420. {
  2421. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2422. }
  2423. }
  2424. catch (Exception)
  2425. {
  2426. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2427. }
  2428. }
  2429. else
  2430. {
  2431. 写入存储ToolStripMenuItem.Checked = true;
  2432. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2433. }
  2434. }
  2435. /// <summary>
  2436. /// 1s定时器
  2437. /// </summary>
  2438. /// <param name="sender"></param>
  2439. /// <param name="e"></param>
  2440. private void timer_1s_Tick(object sender, EventArgs e)
  2441. {
  2442. //时间更新
  2443. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2444. //MC_Runinfo超时清除
  2445. if (MC_RunInfo_Refresh == false)
  2446. {
  2447. MC_RunInfo_Refresh_Cnt++;
  2448. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2449. {
  2450. MC_RunInfo_Clear();
  2451. MC_RunInfo_Refresh_Cnt = 0;
  2452. }
  2453. }
  2454. else
  2455. {
  2456. MC_RunInfo_Refresh_Cnt = 0;
  2457. }
  2458. MC_RunInfo_Refresh = false;
  2459. //MC_Debuginfo超时清除
  2460. if (MC_DebugInfo_Refresh == false)
  2461. {
  2462. MC_DebugInfo_Refresh_Cnt++;
  2463. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2464. {
  2465. MC_DebugInfo_Clear();
  2466. MC_DebugInfo_Refresh_Cnt = 0;
  2467. }
  2468. }
  2469. else
  2470. {
  2471. MC_DebugInfo_Refresh_Cnt = 0;
  2472. }
  2473. MC_DebugInfo_Refresh = false;
  2474. //BMS_RunInfo超时清除
  2475. if (BMS_RunInfo_Refresh == false)
  2476. {
  2477. BMS_RunInfo_Refresh_Cnt++;
  2478. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2479. {
  2480. richTextBox_OBC_BMS_RunInfo.Clear();
  2481. BMS_RunInfo_Refresh_Cnt = 0;
  2482. }
  2483. }
  2484. else
  2485. {
  2486. BMS_RunInfo_Refresh_Cnt = 0;
  2487. }
  2488. BMS_RunInfo_Refresh = false;
  2489. //故障码超时清除
  2490. if (MC_ErrorCode_Refresh == false)
  2491. {
  2492. MC_ErrorCode_Refresh_Cnt++;
  2493. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2494. {
  2495. textBox_ErrorCode.Text = "---";
  2496. MC_ErrorCode_Refresh_Cnt = 0;
  2497. }
  2498. }
  2499. else
  2500. {
  2501. MC_ErrorCode_Refresh_Cnt = 0;
  2502. }
  2503. MC_ErrorCode_Refresh = false;
  2504. //CDL连接超时
  2505. if (识别通讯盒ToolStripMenuItem.Checked)
  2506. {
  2507. if (mySerialProcess.CDL_Online_Flag == false)
  2508. {
  2509. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2510. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2511. {
  2512. timer_500ms.Enabled = false;
  2513. MessageBox.Show("连接失败!", "提示");
  2514. timer_500ms.Enabled = true;
  2515. //关闭串口
  2516. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2517. toolStripComboBox_ComNum.Enabled = true;
  2518. toolStripComboBox_Baudrate.Enabled = true;
  2519. 刷新ToolStripMenuItem.Enabled = true;
  2520. 连接ToolStripMenuItem.Text = "连接";
  2521. 连接ToolStripMenuItem.Checked = false;
  2522. label_COM_Sta.Text = "连接状态:未连接";
  2523. label_PortStatus.BackColor = Color.Red;
  2524. }
  2525. }
  2526. }
  2527. //OBC定时发送设置档位
  2528. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2529. {
  2530. var CtrlCode = new byte[2];
  2531. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2532. CtrlCode[0] = 0x33;
  2533. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2534. CtrlCode[0] = 0x22;
  2535. else
  2536. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2537. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2538. CtrlCode[1] = 0xF1;
  2539. else
  2540. CtrlCode[1] = 0xF0;
  2541. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2542. {
  2543. checkBox_OBC_StartSetGearSt.Checked = false;
  2544. }
  2545. }
  2546. //OBC定时发送查询电池
  2547. if (checkBox_OBC_StartReadBMS.Checked == true)
  2548. {
  2549. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2550. {
  2551. checkBox_OBC_StartReadBMS.Checked = false;
  2552. }
  2553. }
  2554. //定时读取存储器
  2555. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2556. {
  2557. var Address = new byte[4];
  2558. UInt32 Address_Begin;
  2559. UInt32 Addres_End;
  2560. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2561. richTextBox_RamFlasgData.Clear();
  2562. do
  2563. {
  2564. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2565. {
  2566. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2567. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2568. continue;
  2569. }
  2570. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2571. {
  2572. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2573. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2574. continue;
  2575. }
  2576. else
  2577. {
  2578. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2579. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2580. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2581. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2582. if (Addres_End < Address_Begin)
  2583. {
  2584. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2585. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2586. continue;
  2587. }
  2588. else
  2589. {
  2590. var SendByte = new byte[8];
  2591. SendByte[0] = (byte)(Address_Begin >> 24);
  2592. SendByte[1] = (byte)(Address_Begin >> 16);
  2593. SendByte[2] = (byte)(Address_Begin >> 8);
  2594. SendByte[3] = (byte)(Address_Begin);
  2595. SendByte[4] = (byte)(Addres_End >> 24);
  2596. SendByte[5] = (byte)(Addres_End >> 16);
  2597. SendByte[6] = (byte)(Addres_End >> 8);
  2598. SendByte[7] = (byte)(Addres_End);
  2599. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2600. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2601. }
  2602. }
  2603. } while (false);
  2604. }
  2605. //写入参数等待计时
  2606. ACK_WaitCnt++;
  2607. }
  2608. /// <summary>
  2609. /// 运行信息清除
  2610. /// </summary>
  2611. private void MC_RunInfo_Clear()
  2612. {
  2613. foreach (Control c in tabPage_RunInfo.Controls)
  2614. {
  2615. if ((c is TextBox))
  2616. {
  2617. if (c.Name != textBox_ErrorCode.ToString())
  2618. c.Text = "---";
  2619. }
  2620. }
  2621. }
  2622. /// <summary>
  2623. /// 调试信息清除
  2624. /// </summary>
  2625. private void MC_DebugInfo_Clear()
  2626. {
  2627. foreach (Control c in tabPage_DebugInfo.Controls)
  2628. {
  2629. if ((c is TextBox))
  2630. {
  2631. if (c.Name != textBox_ErrorCode.ToString())
  2632. c.Text = "---";
  2633. }
  2634. }
  2635. }
  2636. /// <summary>
  2637. /// 读取马达参数
  2638. /// </summary>
  2639. /// <param name="sender"></param>
  2640. /// <param name="e"></param>
  2641. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2642. {
  2643. richTextBox_MotorParam.Clear();
  2644. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2645. }
  2646. /// <summary>
  2647. /// 写入马达参数
  2648. /// </summary>
  2649. /// <param name="sender"></param>
  2650. /// <param name="e"></param>
  2651. private void button_Write_Click(object sender, EventArgs e)
  2652. {
  2653. var ConfigParam = new byte[40];
  2654. for (int i = 0; i < 40; i++)
  2655. ConfigParam[i] = 0;
  2656. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2657. short wDataTemp = 0;
  2658. ushort DataTemp = 0;
  2659. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2660. try
  2661. {
  2662. for (int i = 0; i < strDataTemp.Length; i++)
  2663. {
  2664. if (i == 6)
  2665. {
  2666. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2667. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2668. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2669. }
  2670. else
  2671. {
  2672. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2673. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2674. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2675. }
  2676. }
  2677. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2678. }
  2679. catch (Exception)
  2680. {
  2681. timer_500ms.Enabled = false;
  2682. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2683. timer_500ms.Enabled = true;
  2684. }
  2685. }
  2686. /// <summary>
  2687. /// 读取整车信息
  2688. /// </summary>
  2689. /// <param name="sender"></param>
  2690. /// <param name="e"></param>
  2691. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2692. {
  2693. richTextBox_BikeParam.Clear();
  2694. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2695. }
  2696. /// <summary>
  2697. /// 写入整车信息
  2698. /// </summary>
  2699. /// <param name="sender"></param>
  2700. /// <param name="e"></param>
  2701. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2702. {
  2703. var ConfigParam = new byte[28];
  2704. for (int i = 0; i < 28; i++)
  2705. ConfigParam[i] = 0;
  2706. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2707. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2708. try
  2709. {
  2710. for (int i = 0; i < strDataTemp.Length; i++)
  2711. {
  2712. short wDataTemp = 0;
  2713. //前后灯参数修改
  2714. if (i == 8)
  2715. {
  2716. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2717. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2718. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2719. }
  2720. //开关机参数
  2721. else if (i == 11)
  2722. {
  2723. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2724. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2725. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2726. }
  2727. else
  2728. {
  2729. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2730. }
  2731. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2732. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2733. }
  2734. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2735. }
  2736. catch (Exception)
  2737. {
  2738. timer_500ms.Enabled = false;
  2739. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2740. timer_500ms.Enabled = true;
  2741. }
  2742. }
  2743. /// <summary>
  2744. /// 读取控制器参数
  2745. /// </summary>
  2746. /// <param name="sender"></param>
  2747. /// <param name="e"></param>
  2748. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2749. {
  2750. richTextBox_ControlParam.Clear();
  2751. comboBox_Bike_CCS.SelectedIndex = 0;
  2752. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2753. }
  2754. /// <summary>
  2755. /// 写入控制器参数
  2756. /// </summary>
  2757. /// <param name="sender"></param>
  2758. /// <param name="e"></param>
  2759. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2760. {
  2761. var ConfigParam = new byte[34];
  2762. for (int i = 0; i < 34; i++)
  2763. ConfigParam[i] = 0;
  2764. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2765. ushort uwDataTemp = 0;
  2766. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2767. try
  2768. {
  2769. for (int i = 0; i < strDataTemp.Length; i++)
  2770. {
  2771. if (i == 13)
  2772. {
  2773. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2774. }
  2775. else
  2776. {
  2777. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2778. }
  2779. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2780. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2781. }
  2782. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2783. }
  2784. catch (Exception)
  2785. {
  2786. timer_500ms.Enabled = false;
  2787. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2788. timer_500ms.Enabled = true;
  2789. }
  2790. }
  2791. /// <summary>
  2792. /// 读取助力参数
  2793. /// </summary>
  2794. /// <param name="sender"></param>
  2795. /// <param name="e"></param>
  2796. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2797. {
  2798. var ConfigParam = new byte[4];
  2799. int AssistNum = 0;
  2800. try
  2801. {
  2802. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2803. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2804. ConfigParam[1] = (byte)(AssistNum >> 8);
  2805. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2806. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2807. ConfigParam[3] = (byte)(AssistNum >> 8);
  2808. richTextBox_AssistParam.Clear();
  2809. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2810. }
  2811. catch (Exception)
  2812. {
  2813. timer_500ms.Enabled = false;
  2814. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2815. timer_500ms.Enabled = true;
  2816. }
  2817. }
  2818. /// <summary>
  2819. /// 写入助力参数
  2820. /// </summary>
  2821. /// <param name="sender"></param>
  2822. /// <param name="e"></param>
  2823. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2824. {
  2825. var ConfigParam = new byte[80];
  2826. for (int i = 0; i < 80; i++)
  2827. ConfigParam[i] = 0;
  2828. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2829. long lDataTemp = 0;
  2830. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2831. int index_1 = 0, index_2 = 0;
  2832. try
  2833. {
  2834. for (int i = 0; i < strDataTemp.Length; i++)
  2835. {
  2836. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2837. {
  2838. index_1 = i;
  2839. break;
  2840. }
  2841. }
  2842. for (int i = 0; i < strDataTemp.Length; i++)
  2843. {
  2844. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2845. {
  2846. index_2 = i;
  2847. break;
  2848. }
  2849. }
  2850. for (int i = 0; i < strDataTemp.Length; i++)
  2851. {
  2852. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2853. if (i < index_1)
  2854. {
  2855. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2856. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2857. }
  2858. else if (i <= index_2)
  2859. {
  2860. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2861. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2862. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2863. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2864. }
  2865. else
  2866. {
  2867. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2868. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2869. }
  2870. }
  2871. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2872. }
  2873. catch (Exception)
  2874. {
  2875. timer_500ms.Enabled = false;
  2876. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2877. timer_500ms.Enabled = true;
  2878. }
  2879. }
  2880. /// <summary>
  2881. /// 读取调试参数
  2882. /// </summary>
  2883. /// <param name="sender"></param>
  2884. /// <param name="e"></param>
  2885. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2886. {
  2887. richTextBox_DebugParam.Clear();
  2888. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2889. }
  2890. /// <summary>
  2891. /// 写入调试参数
  2892. /// </summary>
  2893. /// <param name="sender"></param>
  2894. /// <param name="e"></param>
  2895. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2896. {
  2897. var ConfigParam = new byte[60];
  2898. for (int i = 0; i < 60; i++)
  2899. ConfigParam[i] = 0;
  2900. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2901. ushort uwDataTemp = 0;
  2902. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2903. try
  2904. {
  2905. for (int i = 0; i < strDataTemp.Length; i++)
  2906. {
  2907. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2908. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2909. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2910. }
  2911. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2912. }
  2913. catch (Exception)
  2914. {
  2915. timer_500ms.Enabled = false;
  2916. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2917. timer_500ms.Enabled = true;
  2918. }
  2919. }
  2920. /// <summary>
  2921. /// 读取历史
  2922. /// </summary>
  2923. /// <param name="sender"></param>
  2924. /// <param name="e"></param>
  2925. private void button_ReadRecord_Click(object sender, EventArgs e)
  2926. {
  2927. richTextBox_Record.Clear();
  2928. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2929. }
  2930. /// <summary>
  2931. /// 读取传感器参数
  2932. /// </summary>
  2933. /// <param name="sender"></param>
  2934. /// <param name="e"></param>
  2935. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2936. {
  2937. richTextBox_SensorParam.Clear();
  2938. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2939. }
  2940. /// <summary>
  2941. /// 写入力矩传感器标定值
  2942. /// </summary>
  2943. /// <param name="sender"></param>
  2944. /// <param name="e"></param>
  2945. private void button_Write_Cal_Click(object sender, EventArgs e)
  2946. {
  2947. var ConfigParam = new byte[4];
  2948. for (int i = 0; i < 4; i++)
  2949. ConfigParam[i] = 0;
  2950. ushort uwDataTemp = 0;
  2951. try
  2952. {
  2953. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2954. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2955. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2956. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2957. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2958. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2959. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2960. }
  2961. catch (Exception)
  2962. {
  2963. timer_500ms.Enabled = false;
  2964. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2965. timer_500ms.Enabled = true;
  2966. }
  2967. }
  2968. /// <summary>
  2969. /// 写入传感器参数
  2970. /// </summary>
  2971. /// <param name="sender"></param>
  2972. /// <param name="e"></param>
  2973. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2974. {
  2975. var ConfigParam = new byte[14];
  2976. for (int i = 0; i < 14; i++)
  2977. ConfigParam[i] = 0;
  2978. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2979. ushort uwDataTemp = 0;
  2980. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2981. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2982. int index = 0;
  2983. try
  2984. {
  2985. for (int i = 0; i < strDataTemp.Length; i++)
  2986. {
  2987. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2988. {
  2989. index = i;
  2990. break;
  2991. }
  2992. }
  2993. for (int i = 0; i < (strDataTemp.Length - index); i++)
  2994. {
  2995. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  2996. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2997. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2998. }
  2999. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3000. }
  3001. catch (Exception)
  3002. {
  3003. timer_500ms.Enabled = false;
  3004. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3005. timer_500ms.Enabled = true;
  3006. }
  3007. }
  3008. /// <summary>
  3009. /// 写入型号
  3010. /// </summary>
  3011. /// <param name="sender"></param>
  3012. /// <param name="e"></param>
  3013. private void button_WriteModel_Click(object sender, EventArgs e)
  3014. {
  3015. string Mode = textBox_Model.Text;
  3016. var ModeArray = new byte[16];
  3017. for (ushort i = 0; i < Mode.Length; i++)
  3018. {
  3019. ModeArray[i] = (byte)Mode[i];
  3020. }
  3021. if (Mode.Length < 16)
  3022. {
  3023. ModeArray[Mode.Length] = (byte)'.';
  3024. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3025. {
  3026. ModeArray[Mode.Length + 1 + i] = 0x20;
  3027. }
  3028. }
  3029. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3030. }
  3031. /// <summary>
  3032. /// 写入SN
  3033. /// </summary>
  3034. /// <param name="sender"></param>
  3035. /// <param name="e"></param>
  3036. private void button_WriteSN_Click(object sender, EventArgs e)
  3037. {
  3038. string SN = textBox_SN.Text;
  3039. var SNArray = new byte[16];
  3040. for (ushort i = 0; i < SN.Length; i++)
  3041. {
  3042. SNArray[i] = (byte)SN[i];
  3043. }
  3044. if (SN.Length < 16)
  3045. {
  3046. SNArray[SN.Length] = (byte)'.';
  3047. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3048. {
  3049. SNArray[SN.Length + 1 + i] = 0x20;
  3050. }
  3051. }
  3052. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3053. }
  3054. /// <summary>
  3055. /// 查询版本信息
  3056. /// </summary>
  3057. /// <param name="sender"></param>
  3058. /// <param name="e"></param>
  3059. private void button_ReadVersion_Click(object sender, EventArgs e)
  3060. {
  3061. textBox_Model.Text = "---";
  3062. textBox_SN.Text = "---";
  3063. textBox_HW.Text = "---";
  3064. textBox_FW.Text = "---";
  3065. textBox_SP.Text = "---";
  3066. textBox_OBC_ReadModel.Text = "---";
  3067. textBox_OBC_ReadSN.Text = "---";
  3068. textBox_OBC_ReadHW.Text = "---";
  3069. textBox_OBC_ReadFW.Text = "---";
  3070. textBox_OBC_ReadSP.Text = "---";
  3071. textBox_FacModeName.Text = "---";
  3072. textBox_FacModeNum.Text = "---";
  3073. textBox_FacModeHW.Text = "---";
  3074. textBox_FacModeFW.Text = "---";
  3075. textBox_FacModeSP.Text = "---";
  3076. Class_Motor_Ver.Mode = "---";
  3077. Class_Motor_Ver.SN = "---";
  3078. Class_Motor_Ver.HW = "---";
  3079. Class_Motor_Ver.FW = "---";
  3080. Class_Motor_Ver.Special = "---";
  3081. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3082. }
  3083. /// <summary>
  3084. /// 查询自定义1
  3085. /// </summary>
  3086. /// <param name="sender"></param>
  3087. /// <param name="e"></param>
  3088. private void button_ReadUser1_Click(object sender, EventArgs e)
  3089. {
  3090. textBox_User1.Text = "---";
  3091. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3092. }
  3093. /// <summary>
  3094. /// 查询自定义2
  3095. /// </summary>
  3096. /// <param name="sender"></param>
  3097. /// <param name="e"></param>
  3098. private void button_ReadUser2_Click(object sender, EventArgs e)
  3099. {
  3100. textBox_User2.Text = "---";
  3101. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3102. }
  3103. /// <summary>
  3104. /// 查询自定义3
  3105. /// </summary>
  3106. /// <param name="sender"></param>
  3107. /// <param name="e"></param>
  3108. private void button_ReadUser3_Click(object sender, EventArgs e)
  3109. {
  3110. textBox_User3.Text = "---";
  3111. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3112. }
  3113. /// <summary>
  3114. /// 写入自定义字符串1
  3115. /// </summary>
  3116. /// <param name="sender"></param>
  3117. /// <param name="e"></param>
  3118. private void button_WriteUser1_Click(object sender, EventArgs e)
  3119. {
  3120. string User = textBox_User1.Text;
  3121. var UserArray = new byte[16];
  3122. for (ushort i = 0; i < User.Length; i++)
  3123. {
  3124. UserArray[i] = (byte)User[i];
  3125. }
  3126. if (User.Length < 16)
  3127. {
  3128. UserArray[User.Length] = (byte)'.';
  3129. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3130. {
  3131. UserArray[User.Length + 1 + i] = 0x20;
  3132. }
  3133. }
  3134. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3135. }
  3136. /// <summary>
  3137. /// 写入自定义字符串2
  3138. /// </summary>
  3139. /// <param name="sender"></param>
  3140. /// <param name="e"></param>
  3141. private void button_WriteUser2_Click(object sender, EventArgs e)
  3142. {
  3143. string User = textBox_User2.Text;
  3144. var UserArray = new byte[16];
  3145. for (ushort i = 0; i < User.Length; i++)
  3146. {
  3147. UserArray[i] = (byte)User[i];
  3148. }
  3149. if (User.Length < 16)
  3150. {
  3151. UserArray[User.Length] = (byte)'.';
  3152. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3153. {
  3154. UserArray[User.Length + 1 + i] = 0x20;
  3155. }
  3156. }
  3157. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3158. }
  3159. /// <summary>
  3160. /// 写入自定义字符串3
  3161. /// </summary>
  3162. /// <param name="sender"></param>
  3163. /// <param name="e"></param>
  3164. private void button_WriteUser3_Click(object sender, EventArgs e)
  3165. {
  3166. string User = textBox_User3.Text;
  3167. var UserArray = new byte[16];
  3168. for (ushort i = 0; i < User.Length; i++)
  3169. {
  3170. UserArray[i] = (byte)User[i];
  3171. }
  3172. if (User.Length < 16)
  3173. {
  3174. UserArray[User.Length] = (byte)'.';
  3175. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3176. {
  3177. UserArray[User.Length + 1 + i] = 0x20;
  3178. }
  3179. }
  3180. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3181. }
  3182. /// <summary>
  3183. /// 查询生产信息
  3184. /// </summary>
  3185. /// <param name="sender"></param>
  3186. /// <param name="e"></param>
  3187. private void button_ReadMAC_Click(object sender, EventArgs e)
  3188. {
  3189. textBox_MAC.Text = "---";
  3190. textBox_MACAdd.Text = "---";
  3191. textBox_MACDate.Text = "---";
  3192. textBox_PP.Text = "---";
  3193. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3194. }
  3195. /// <summary>
  3196. /// 写入生产信息
  3197. /// </summary>
  3198. /// <param name="sender"></param>
  3199. /// <param name="e"></param>
  3200. private void button_WriteMac_Click(object sender, EventArgs e)
  3201. {
  3202. var MACArray = new byte[32];
  3203. //填入生产商
  3204. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3205. {
  3206. MACArray[i] = (byte)textBox_MAC.Text[i];
  3207. }
  3208. if (textBox_MAC.Text.Length < 8)
  3209. {
  3210. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3211. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3212. {
  3213. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3214. }
  3215. }
  3216. //填入生产地
  3217. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3218. {
  3219. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3220. }
  3221. if (textBox_MACAdd.Text.Length < 8)
  3222. {
  3223. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3224. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3225. {
  3226. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3227. }
  3228. }
  3229. //填入生产日期
  3230. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3231. {
  3232. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3233. }
  3234. if (textBox_MACDate.Text.Length < 8)
  3235. {
  3236. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3237. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3238. {
  3239. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3240. }
  3241. }
  3242. //填入品牌
  3243. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3244. {
  3245. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3246. }
  3247. if (textBox_PP.Text.Length < 8)
  3248. {
  3249. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3250. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3251. {
  3252. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3253. }
  3254. }
  3255. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3256. }
  3257. /// <summary>
  3258. /// 查询密钥
  3259. /// </summary>
  3260. /// <param name="sender"></param>
  3261. /// <param name="e"></param>
  3262. private void button_ReadKey_Click(object sender, EventArgs e)
  3263. {
  3264. textBox_Key.Text = "---";
  3265. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3266. }
  3267. /// <summary>
  3268. /// 写入校验密钥
  3269. /// </summary>
  3270. /// <param name="sender"></param>
  3271. /// <param name="e"></param>
  3272. private void button_WriteKey_Click(object sender, EventArgs e)
  3273. {
  3274. string Key = textBox_Key.Text;
  3275. var KeyArray = new byte[8];
  3276. if (Key.Length != 8)
  3277. {
  3278. timer_500ms.Enabled = false;
  3279. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3280. timer_500ms.Enabled = true;
  3281. return;
  3282. }
  3283. for (ushort i = 0; i < Key.Length; i++)
  3284. {
  3285. KeyArray[i] = (byte)Key[i];
  3286. }
  3287. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3288. }
  3289. /// <summary>
  3290. /// 查询在线检测结果
  3291. /// </summary>
  3292. /// <param name="sender"></param>
  3293. /// <param name="e"></param>
  3294. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3295. {
  3296. textBox_Online.Text = "---";
  3297. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3298. }
  3299. /// <summary>
  3300. /// 系统清除
  3301. /// </summary>
  3302. /// <param name="sender"></param>
  3303. /// <param name="e"></param>
  3304. private void button_SystemClear_Click(object sender, EventArgs e)
  3305. {
  3306. var Code = new byte[5];
  3307. Code[0] = (byte)'C';
  3308. Code[1] = (byte)'L';
  3309. Code[2] = (byte)'E';
  3310. Code[3] = (byte)'A';
  3311. Code[4] = (byte)'R';
  3312. timer_500ms.Enabled = false;
  3313. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3314. {
  3315. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3316. {
  3317. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3318. {
  3319. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3320. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3321. }
  3322. }
  3323. }
  3324. timer_500ms.Enabled = true;
  3325. }
  3326. /// <summary>
  3327. /// 参数还原
  3328. /// </summary>
  3329. /// <param name="sender"></param>
  3330. /// <param name="e"></param>
  3331. private void button_Recovery_Click(object sender, EventArgs e)
  3332. {
  3333. var Code = new byte[8];
  3334. Code[0] = (byte)'R';
  3335. Code[1] = (byte)'E';
  3336. Code[2] = (byte)'C';
  3337. Code[3] = (byte)'O';
  3338. Code[4] = (byte)'V';
  3339. Code[5] = (byte)'E';
  3340. Code[6] = (byte)'R';
  3341. Code[7] = (byte)'Y';
  3342. timer_500ms.Enabled = false;
  3343. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3344. {
  3345. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3346. {
  3347. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3348. {
  3349. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3350. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3351. }
  3352. }
  3353. }
  3354. timer_500ms.Enabled = true;
  3355. }
  3356. /// <summary>
  3357. /// 系统复位
  3358. /// </summary>
  3359. /// <param name="sender"></param>
  3360. /// <param name="e"></param>
  3361. private void button_Reset_Click(object sender, EventArgs e)
  3362. {
  3363. var Code_Off = new byte[5];
  3364. var Code_Reset = new byte[5];
  3365. Code_Off[0] = (byte)'O';
  3366. Code_Off[1] = (byte)'F';
  3367. Code_Off[2] = (byte)'F';
  3368. Code_Off[3] = (byte)'.';
  3369. Code_Off[4] = (byte)'.';
  3370. Code_Reset[0] = (byte)'R';
  3371. Code_Reset[1] = (byte)'E';
  3372. Code_Reset[2] = (byte)'S';
  3373. Code_Reset[3] = (byte)'E';
  3374. Code_Reset[4] = (byte)'T';
  3375. timer_500ms.Enabled = false;
  3376. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3377. {
  3378. timer_500ms.Enabled = true;
  3379. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3380. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3381. PowerOffAckStatus = false;
  3382. Delay_ms(250);
  3383. int TryCnt = 3;
  3384. while ((TryCnt--) >= 0)
  3385. {
  3386. if (!PowerOffAckStatus)
  3387. {
  3388. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3389. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3390. PowerOffAckStatus = false;
  3391. Delay_ms(250);
  3392. }
  3393. else break;
  3394. }
  3395. if (PowerOffAckStatus)
  3396. {
  3397. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3398. }
  3399. else
  3400. {
  3401. timer_500ms.Enabled = false;
  3402. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3403. timer_500ms.Enabled = true;
  3404. }
  3405. }
  3406. timer_500ms.Enabled = true;
  3407. }
  3408. /// <summary>
  3409. /// 记录清除
  3410. /// </summary>
  3411. /// <param name="sender"></param>
  3412. /// <param name="e"></param>
  3413. private void button_ClearLog_Click(object sender, EventArgs e)
  3414. {
  3415. var Code = new byte[9];
  3416. Code[0] = (byte)'L';
  3417. Code[1] = (byte)'O';
  3418. Code[2] = (byte)'G';
  3419. Code[3] = (byte)' ';
  3420. Code[4] = (byte)'C';
  3421. Code[5] = (byte)'L';
  3422. Code[6] = (byte)'E';
  3423. Code[7] = (byte)'A';
  3424. Code[8] = (byte)'R';
  3425. timer_500ms.Enabled = false;
  3426. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3427. {
  3428. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3429. {
  3430. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3431. {
  3432. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3433. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3434. }
  3435. }
  3436. }
  3437. timer_500ms.Enabled = true;
  3438. }
  3439. /// <summary>
  3440. /// 打开系统计算器
  3441. /// </summary>
  3442. /// <param name="sender"></param>
  3443. /// <param name="e"></param>
  3444. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3445. {
  3446. System.Diagnostics.Process.Start("calc.exe");
  3447. }
  3448. /// <summary>
  3449. ///故障转换和显示
  3450. /// </summary>
  3451. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3452. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3453. "",""};
  3454. private string ErrorInfoDisplay(UInt32 Code)
  3455. {
  3456. string Result = "";
  3457. if (Code == 0)
  3458. {
  3459. Result = "无故障";
  3460. }
  3461. else
  3462. {
  3463. for (int i = 0; i < 32; i++)
  3464. {
  3465. if ((Code & 0x01) == 0x01)
  3466. {
  3467. Result += ErrorInfo[i] + " ";
  3468. }
  3469. Code >>= 1;
  3470. }
  3471. }
  3472. return Result;
  3473. }
  3474. /// <summary>
  3475. /// 鼠标滑过故障码显示具体内容
  3476. /// </summary>
  3477. /// <param name="sender"></param>
  3478. /// <param name="e"></param>
  3479. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3480. {
  3481. // 创建the ToolTip
  3482. ToolTip toolTip1 = new ToolTip();
  3483. // 设置显示样式
  3484. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3485. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3486. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3487. toolTip1.ShowAlways = true;//是否显示提示框
  3488. // 设置伴随的对象.
  3489. string ErrorCode = this.textBox_ErrorCode.Text;
  3490. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3491. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3492. }
  3493. /// <summary>
  3494. /// 数据记录
  3495. /// </summary>
  3496. private void RunInfoAutoSave()
  3497. {
  3498. if (运行信息记录ToolStripMenuItem.Checked == true)
  3499. {
  3500. if (RunInfoSaveFilename == string.Empty)
  3501. {
  3502. return;
  3503. }
  3504. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3505. foreach (Control c in tabPage_RunInfo.Controls)
  3506. {
  3507. if (c is TextBox)
  3508. {
  3509. SaveData += c.Text + " , ";
  3510. }
  3511. }
  3512. foreach (Control c in tabPage_DebugInfo.Controls)
  3513. {
  3514. if (c is TextBox)
  3515. {
  3516. SaveData += c.Text + " , ";
  3517. }
  3518. }
  3519. SaveData += "\r\n";
  3520. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3521. }
  3522. }
  3523. /// <summary>
  3524. /// 打开或关闭数据记录
  3525. /// </summary>
  3526. /// <param name="sender"></param>
  3527. /// <param name="e"></param>
  3528. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3529. {
  3530. if (运行信息记录ToolStripMenuItem.Checked == false)
  3531. {
  3532. if (mySerialProcess.mySerial.IsOpen == true)
  3533. {
  3534. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3535. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3536. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3537. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3538. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3539. 运行信息记录ToolStripMenuItem.Checked = true;
  3540. }
  3541. else
  3542. {
  3543. timer_500ms.Enabled = false;
  3544. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3545. timer_500ms.Enabled = true;
  3546. }
  3547. }
  3548. else
  3549. {
  3550. 运行信息记录ToolStripMenuItem.Checked = false;
  3551. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3552. }
  3553. }
  3554. /// <summary>
  3555. /// 仪表启动控制档位开关事件
  3556. /// </summary>
  3557. /// <param name="sender"></param>
  3558. /// <param name="e"></param>
  3559. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3560. {
  3561. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3562. {
  3563. //检查串口是否打开
  3564. if (!mySerialProcess.mySerial.IsOpen)
  3565. {
  3566. timer_500ms.Enabled = false;
  3567. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3568. timer_500ms.Enabled = true;
  3569. checkBox_OBC_StartSetGearSt.Checked = false;
  3570. return;
  3571. }
  3572. //检查是否选择档位和打开车灯
  3573. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3574. {
  3575. timer_500ms.Enabled = false;
  3576. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3577. timer_500ms.Enabled = true;
  3578. checkBox_OBC_StartSetGearSt.Checked = false;
  3579. return;
  3580. }
  3581. }
  3582. }
  3583. /// <summary>
  3584. /// OBC查询电机用户参数
  3585. /// </summary>
  3586. /// <param name="sender"></param>
  3587. /// <param name="e"></param>
  3588. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3589. {
  3590. richTextBox_OBC_ReadUserInfo.Clear();
  3591. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3592. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3593. }
  3594. /// <summary>
  3595. /// OBC设置电机用户参数
  3596. /// </summary>
  3597. /// <param name="sender"></param>
  3598. /// <param name="e"></param>
  3599. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3600. {
  3601. var UserInfoCode = new byte[8];
  3602. for (int i = 0; i < UserInfoCode.Length; i++)
  3603. UserInfoCode[i] = 0;
  3604. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3605. {
  3606. timer_500ms.Enabled = false;
  3607. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3608. timer_500ms.Enabled = true;
  3609. return;
  3610. }
  3611. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3612. {
  3613. timer_500ms.Enabled = false;
  3614. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3615. timer_500ms.Enabled = true;
  3616. return;
  3617. }
  3618. //周长微调
  3619. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3620. //启动模式
  3621. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3622. //助力方案
  3623. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3624. //自动关机时间
  3625. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3626. //限速微调
  3627. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3628. //定速巡航开关
  3629. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3630. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3631. }
  3632. /// <summary>
  3633. /// OBC查询电机版本信息
  3634. /// </summary>
  3635. /// <param name="sender"></param>
  3636. /// <param name="e"></param>
  3637. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3638. {
  3639. textBox_Model.Text = "---";
  3640. textBox_SN.Text = "---";
  3641. textBox_HW.Text = "---";
  3642. textBox_FW.Text = "---";
  3643. textBox_SP.Text = "---";
  3644. textBox_OBC_ReadModel.Text = "---";
  3645. textBox_OBC_ReadSN.Text = "---";
  3646. textBox_OBC_ReadHW.Text = "---";
  3647. textBox_OBC_ReadFW.Text = "---";
  3648. textBox_OBC_ReadSP.Text = "---";
  3649. textBox_FacModeName.Text = "---";
  3650. textBox_FacModeNum.Text = "---";
  3651. textBox_FacModeHW.Text = "---";
  3652. textBox_FacModeFW.Text = "---";
  3653. textBox_FacModeSP.Text = "---";
  3654. Class_Motor_Ver.Mode = "---";
  3655. Class_Motor_Ver.SN = "---";
  3656. Class_Motor_Ver.HW = "---";
  3657. Class_Motor_Ver.FW = "---";
  3658. Class_Motor_Ver.Special = "---";
  3659. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3660. }
  3661. /// <summary>
  3662. /// OBC读取骑行历史
  3663. /// </summary>
  3664. /// <param name="sender"></param>
  3665. /// <param name="e"></param>
  3666. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3667. {
  3668. textBox_OBC_TRIP_KM.Text = "";
  3669. textBox_OBC_TRIP_TIME.Text = "";
  3670. textBox_OBC_ODO_KM.Text = "";
  3671. textBox_OBC_ODO_TIME.Text = "";
  3672. textBox_ODO_KM.Text = "---";
  3673. textBox_ODO_TIME.Text = "---";
  3674. textBox_TRIP_KM.Text = "---";
  3675. textBox_TRIP_TIME.Text = "---";
  3676. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3677. }
  3678. /// <summary>
  3679. /// OBC清除TRIP里程
  3680. /// </summary>
  3681. /// <param name="sender"></param>
  3682. /// <param name="e"></param>
  3683. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3684. {
  3685. var Code = new byte[5];
  3686. Code[0] = (byte)'C';
  3687. Code[1] = (byte)'L';
  3688. Code[2] = (byte)'E';
  3689. Code[3] = (byte)'A';
  3690. Code[4] = (byte)'R';
  3691. timer_500ms.Enabled = false;
  3692. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3693. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3694. timer_500ms.Enabled = true;
  3695. }
  3696. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3697. {
  3698. if (checkBox_OBC_StartReadBMS.Checked == true)
  3699. {
  3700. //检查串口是否打开
  3701. if (!mySerialProcess.mySerial.IsOpen)
  3702. {
  3703. timer_500ms.Enabled = false;
  3704. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3705. timer_500ms.Enabled = true;
  3706. checkBox_OBC_StartReadBMS.Checked = false;
  3707. return;
  3708. }
  3709. }
  3710. }
  3711. /// <summary>
  3712. /// 写入力矩传感器参数
  3713. /// </summary>
  3714. /// <param name="sender"></param>
  3715. /// <param name="e"></param>
  3716. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3717. {
  3718. var ConfigParam = new byte[46];
  3719. for (int i = 0; i < 14; i++)
  3720. ConfigParam[i] = 0;
  3721. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3722. ushort uwDataTemp = 0;
  3723. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3724. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3725. int index = 0;
  3726. try
  3727. {
  3728. for (int i = 0; i < strDataTemp.Length; i++)
  3729. {
  3730. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3731. {
  3732. index = i;
  3733. break;
  3734. }
  3735. }
  3736. for (int i = 0; i < (index + 1); i++)
  3737. {
  3738. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3739. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3740. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3741. }
  3742. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3743. }
  3744. catch (Exception)
  3745. {
  3746. timer_500ms.Enabled = false;
  3747. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3748. timer_500ms.Enabled = true;
  3749. }
  3750. }
  3751. /// <summary>
  3752. /// 查询存储标志
  3753. /// </summary>
  3754. /// <param name="sender"></param>
  3755. /// <param name="e"></param>
  3756. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3757. {
  3758. radioButton_EE_SaveYes.Checked = false;
  3759. radioButton_EE_SaveNo.Checked = false;
  3760. radioButton_SIP_SaveYes.Checked = false;
  3761. radioButton_SIP_SaveNo.Checked = false;
  3762. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3763. }
  3764. /// <summary>
  3765. /// 写入存储标志
  3766. /// </summary>
  3767. /// <param name="sender"></param>
  3768. /// <param name="e"></param>
  3769. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3770. {
  3771. var SaveFlag = new byte[6];
  3772. for (int i = 0; i < 6; i++)
  3773. SaveFlag[i] = 0;
  3774. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3775. {
  3776. timer_500ms.Enabled = false;
  3777. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3778. timer_500ms.Enabled = true;
  3779. return;
  3780. }
  3781. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3782. {
  3783. timer_500ms.Enabled = false;
  3784. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3785. timer_500ms.Enabled = true;
  3786. return;
  3787. }
  3788. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3789. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3790. SaveFlag[3] = 0;
  3791. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3792. SaveFlag[5] = 0;
  3793. timer_500ms.Enabled = false;
  3794. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3795. {
  3796. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3797. }
  3798. timer_500ms.Enabled = true;
  3799. }
  3800. /// <summary>
  3801. /// 读取指定地址数据
  3802. /// </summary>
  3803. /// <param name="sender"></param>
  3804. /// <param name="e"></param>
  3805. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3806. {
  3807. var Address = new byte[4];
  3808. UInt32 Address_Begin;
  3809. UInt32 Addres_End;
  3810. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3811. richTextBox_RamFlasgData.Clear();
  3812. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3813. {
  3814. timer_500ms.Enabled = false;
  3815. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3816. timer_500ms.Enabled = true;
  3817. return;
  3818. }
  3819. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3820. {
  3821. timer_500ms.Enabled = false;
  3822. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3823. timer_500ms.Enabled = true;
  3824. return;
  3825. }
  3826. else
  3827. {
  3828. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3829. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3830. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3831. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3832. if (Addres_End < Address_Begin)
  3833. {
  3834. timer_500ms.Enabled = false;
  3835. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3836. timer_500ms.Enabled = true;
  3837. return;
  3838. }
  3839. else
  3840. {
  3841. var SendByte = new byte[8];
  3842. SendByte[0] = (byte)(Address_Begin >> 24);
  3843. SendByte[1] = (byte)(Address_Begin >> 16);
  3844. SendByte[2] = (byte)(Address_Begin >> 8);
  3845. SendByte[3] = (byte)(Address_Begin);
  3846. SendByte[4] = (byte)(Addres_End >> 24);
  3847. SendByte[5] = (byte)(Addres_End >> 16);
  3848. SendByte[6] = (byte)(Addres_End >> 8);
  3849. SendByte[7] = (byte)(Addres_End);
  3850. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3851. }
  3852. }
  3853. }
  3854. /// <summary>
  3855. /// 工作模式选择
  3856. /// </summary>
  3857. /// <param name="sender"></param>
  3858. /// <param name="e"></param>
  3859. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3860. {
  3861. var RunMode = new byte[1];
  3862. if (comboBox_WorkMode.Text == "配置模式")
  3863. RunMode[0] = 0x01;
  3864. else if (comboBox_WorkMode.Text == "调试模式")
  3865. RunMode[0] = 0x02;
  3866. else
  3867. RunMode[0] = 0x00;
  3868. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3869. }
  3870. /// <summary>
  3871. /// 助力档位选择
  3872. /// </summary>
  3873. /// <param name="sender"></param>
  3874. /// <param name="e"></param>
  3875. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3876. {
  3877. var CtrlCode = new byte[2];
  3878. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3879. CtrlCode[0] = 0x33;
  3880. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3881. CtrlCode[0] = 0x22;
  3882. else
  3883. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3884. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3885. CtrlCode[1] = 0xF1;
  3886. else
  3887. CtrlCode[1] = 0xF0;
  3888. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3889. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3890. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3891. Delay_ms(500);
  3892. //设置百分比
  3893. do
  3894. {
  3895. var PercentCode = new byte[1];
  3896. if (comboBox_GearSt.SelectedIndex == 0) //Off
  3897. {
  3898. PercentCode[0] = 0;
  3899. textBox_MotorSpeedPercent.Text = "0";
  3900. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3901. }
  3902. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  3903. {
  3904. if (comboBox_WorkMode.SelectedIndex != 0)
  3905. {
  3906. PercentCode[0] = 100;
  3907. textBox_MotorSpeedPercent.Text = "100";
  3908. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  3909. }
  3910. }
  3911. } while (false);
  3912. }
  3913. /// <summary>
  3914. /// 仪表档位选择
  3915. /// </summary>
  3916. /// <param name="sender"></param>
  3917. /// <param name="e"></param>
  3918. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3919. {
  3920. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3921. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3922. }
  3923. /// <summary>
  3924. /// 生产模式初始化
  3925. /// </summary>
  3926. /// <param name="sender"></param>
  3927. /// <param name="e"></param>
  3928. private void button_FacModeInit_Click(object sender, EventArgs e)
  3929. {
  3930. var Code = new byte[5];
  3931. Code[0] = (byte)'C';
  3932. Code[1] = (byte)'L';
  3933. Code[2] = (byte)'E';
  3934. Code[3] = (byte)'A';
  3935. Code[4] = (byte)'R';
  3936. timer_500ms.Enabled = false;
  3937. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3938. {
  3939. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3940. {
  3941. timer_500ms.Enabled = true;
  3942. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3943. PowerOffAckStatus = false;
  3944. Delay_ms(250);
  3945. int TryCnt = 3;
  3946. while ((TryCnt--) >= 0)
  3947. {
  3948. if (!PowerOffAckStatus)
  3949. {
  3950. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3951. PowerOffAckStatus = false;
  3952. Delay_ms(250);
  3953. }
  3954. else break;
  3955. }
  3956. if (PowerOffAckStatus)
  3957. {
  3958. timer_500ms.Enabled = false;
  3959. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3960. timer_500ms.Enabled = true;
  3961. }
  3962. else
  3963. {
  3964. timer_500ms.Enabled = false;
  3965. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3966. timer_500ms.Enabled = true;
  3967. }
  3968. timer_500ms.Enabled = true;
  3969. }
  3970. }
  3971. timer_500ms.Enabled = true;
  3972. //清除历史测试记录
  3973. textBox_FacModeSensorADC0.Text = "";
  3974. textBox_FacModeSensorADC1.Text = "";
  3975. textBox_FacModeSensorADC2.Text = "";
  3976. textBox_FacModeSensorADC3.Text = "";
  3977. textBox_FacModeSensorADC4.Text = "";
  3978. LightSwitchStatus = false;
  3979. MotorRunStatus = false;
  3980. textBox_MotorSpeedPercent.Text = "5";
  3981. textBox_FacModeName.Text = "";
  3982. textBox_FacModeNum.Text = "";
  3983. textBox_FacModeHW.Text = "";
  3984. textBox_FacModeFW.Text = "";
  3985. }
  3986. /// <summary>
  3987. /// 生产模式读取传感器参数
  3988. /// </summary>
  3989. /// <param name="sender"></param>
  3990. /// <param name="e"></param>
  3991. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3992. {
  3993. richTextBox_SensorParam.Clear();
  3994. textBox_FacModeSensorADC0.Text = "";
  3995. textBox_FacModeSensorADC1.Text = "";
  3996. textBox_FacModeSensorADC2.Text = "";
  3997. textBox_FacModeSensorADC3.Text = "";
  3998. textBox_FacModeSensorADC4.Text = "";
  3999. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4000. //零点判断
  4001. label1_TorqueCal0.BackColor = Color.Red;
  4002. WriteACK = false;
  4003. ACK_WaitCnt = 0;
  4004. Delay_ms(200);
  4005. if (WriteACK == true) //力矩读取正常
  4006. {
  4007. WriteACK = false;
  4008. //获取零点
  4009. ushort ZeroNew;
  4010. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4011. //比较零点
  4012. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4013. {
  4014. label1_TorqueCal0.BackColor = Color.Green;
  4015. }
  4016. else
  4017. {
  4018. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4019. }
  4020. }
  4021. else //力矩读取不正常
  4022. {
  4023. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4024. }
  4025. }
  4026. /// <summary>
  4027. /// 生产模式传感器标定1
  4028. /// </summary>
  4029. /// <param name="sender"></param>
  4030. /// <param name="e"></param>
  4031. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4032. {
  4033. var ConfigParam = new byte[4];
  4034. for (int i = 0; i < 4; i++)
  4035. ConfigParam[i] = 0;
  4036. ushort uwDataTemp = 0;
  4037. try
  4038. {
  4039. uwDataTemp = 1;//负载序号
  4040. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4041. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4042. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4043. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4044. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4045. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4046. Delay_ms(200);
  4047. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4048. //标定1判断
  4049. label1_TorqueCal1.BackColor = Color.Red;
  4050. WriteACK = false;
  4051. ACK_WaitCnt = 0;
  4052. Delay_ms(200);
  4053. if (WriteACK == true) //力矩读取正常
  4054. {
  4055. WriteACK = false;
  4056. //获取标定1
  4057. ushort K1_T, K1;
  4058. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4059. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4060. //比较标定1
  4061. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4062. {
  4063. label1_TorqueCal1.BackColor = Color.Green;
  4064. }
  4065. else
  4066. {
  4067. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4068. }
  4069. }
  4070. else //力矩读取不正常
  4071. {
  4072. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4073. }
  4074. }
  4075. catch (Exception)
  4076. {
  4077. timer_500ms.Enabled = false;
  4078. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4079. timer_500ms.Enabled = true;
  4080. }
  4081. }
  4082. /// <summary>
  4083. /// 生产模式传感器标定2
  4084. /// </summary>
  4085. /// <param name="sender"></param>
  4086. /// <param name="e"></param>
  4087. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4088. {
  4089. var ConfigParam = new byte[4];
  4090. for (int i = 0; i < 4; i++)
  4091. ConfigParam[i] = 0;
  4092. ushort uwDataTemp = 0;
  4093. try
  4094. {
  4095. uwDataTemp = 2;//负载序号
  4096. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4097. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4098. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4099. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4100. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4101. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4102. Delay_ms(200);
  4103. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4104. //标定2判断
  4105. label1_TorqueCal2.BackColor = Color.Red;
  4106. WriteACK = false;
  4107. ACK_WaitCnt = 0;
  4108. Delay_ms(200);
  4109. if (WriteACK == true) //力矩读取正常
  4110. {
  4111. WriteACK = false;
  4112. //获取标定2
  4113. ushort K2_T, K2;
  4114. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4115. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4116. //比较标定1
  4117. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4118. {
  4119. label1_TorqueCal2.BackColor = Color.Green;
  4120. }
  4121. else
  4122. {
  4123. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4124. }
  4125. }
  4126. else //力矩读取不正常
  4127. {
  4128. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4129. }
  4130. }
  4131. catch (Exception)
  4132. {
  4133. timer_500ms.Enabled = false;
  4134. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4135. timer_500ms.Enabled = true;
  4136. }
  4137. }
  4138. /// <summary>
  4139. /// 生产模式传感器标定3
  4140. /// </summary>
  4141. /// <param name="sender"></param>
  4142. /// <param name="e"></param>
  4143. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4144. {
  4145. var ConfigParam = new byte[4];
  4146. for (int i = 0; i < 4; i++)
  4147. ConfigParam[i] = 0;
  4148. ushort uwDataTemp = 0;
  4149. try
  4150. {
  4151. uwDataTemp = 3;//负载序号
  4152. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4153. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4154. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4155. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4156. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4157. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4158. Delay_ms(200);
  4159. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4160. //标定3判断
  4161. label1_TorqueCal3.BackColor = Color.Red;
  4162. WriteACK = false;
  4163. ACK_WaitCnt = 0;
  4164. Delay_ms(200);
  4165. if (WriteACK == true) //力矩读取正常
  4166. {
  4167. WriteACK = false;
  4168. //获取标定3
  4169. ushort K3_T, K3;
  4170. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4171. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4172. //比较标定1
  4173. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4174. {
  4175. label1_TorqueCal3.BackColor = Color.Green;
  4176. }
  4177. else
  4178. {
  4179. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4180. }
  4181. }
  4182. else //力矩读取不正常
  4183. {
  4184. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4185. }
  4186. }
  4187. catch (Exception)
  4188. {
  4189. timer_500ms.Enabled = false;
  4190. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4191. timer_500ms.Enabled = true;
  4192. }
  4193. }
  4194. /// <summary>
  4195. /// 生产模式传感器标定4
  4196. /// </summary>
  4197. /// <param name="sender"></param>
  4198. /// <param name="e"></param>
  4199. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4200. {
  4201. var ConfigParam = new byte[4];
  4202. for (int i = 0; i < 4; i++)
  4203. ConfigParam[i] = 0;
  4204. ushort uwDataTemp = 0;
  4205. try
  4206. {
  4207. WriteACK = false;
  4208. uwDataTemp = 4;//负载序号
  4209. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4210. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4211. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4212. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4213. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4214. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4215. Delay_ms(200);
  4216. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4217. //标定4判断
  4218. label1_TorqueCal4.BackColor = Color.Red;
  4219. WriteACK = false;
  4220. ACK_WaitCnt = 0;
  4221. Delay_ms(200);
  4222. if (WriteACK == true) //力矩读取正常
  4223. {
  4224. //获取标定4
  4225. ushort K4_T, K4;
  4226. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4227. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4228. //比较标定1
  4229. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4230. {
  4231. label1_TorqueCal4.BackColor = Color.Green;
  4232. }
  4233. else
  4234. {
  4235. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4236. }
  4237. }
  4238. else //力矩读取不正常
  4239. {
  4240. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4241. }
  4242. }
  4243. catch (Exception)
  4244. {
  4245. timer_500ms.Enabled = false;
  4246. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4247. timer_500ms.Enabled = true;
  4248. }
  4249. }
  4250. /// <summary>
  4251. /// 生产模式开关灯
  4252. /// </summary>
  4253. /// <param name="sender"></param>
  4254. /// <param name="e"></param>
  4255. bool LightSwitchStatus = false;
  4256. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4257. {
  4258. var CtrlCode = new byte[2];
  4259. CtrlCode[0] = 0x00;
  4260. if (LightSwitchStatus)
  4261. {
  4262. CtrlCode[1] = 0xF0;
  4263. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4264. }
  4265. else
  4266. {
  4267. CtrlCode[1] = 0xF1;
  4268. button_FacModeLightSW.BackColor = Color.Yellow;
  4269. }
  4270. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4271. {
  4272. LightSwitchStatus = !LightSwitchStatus;
  4273. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4274. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4275. }
  4276. }
  4277. /// <summary>
  4278. /// 生产模式电机控制
  4279. /// </summary>
  4280. /// <param name="sender"></param>
  4281. /// <param name="e"></param>
  4282. bool MotorRunStatus = false;
  4283. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4284. {
  4285. string DebugDefaultInfo = "";
  4286. //获取调试信息
  4287. if (richTextBox_DebugParam.Text == string.Empty)
  4288. {
  4289. richTextBox_DebugParam.Clear();
  4290. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4291. }
  4292. Delay_ms(200);
  4293. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4294. //获取参数
  4295. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4296. if (strDataTemp.Length != 29)
  4297. {
  4298. timer_500ms.Enabled = false;
  4299. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4300. timer_500ms.Enabled = true;
  4301. return;
  4302. }
  4303. //设置参数
  4304. var ConfigParam = new byte[60];
  4305. for (int i = 0; i < 60; i++)
  4306. ConfigParam[i] = 0;
  4307. ConfigParam[0] = 0x00;
  4308. ushort uwDataTemp = 0;
  4309. if (!MotorRunStatus) //停止状态
  4310. {
  4311. //设置速度环
  4312. strDataTemp[0] = "整体运行模式=3";
  4313. //发送数据
  4314. try
  4315. {
  4316. for (int i = 0; i < strDataTemp.Length; i++)
  4317. {
  4318. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4319. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4320. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4321. }
  4322. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4323. return;
  4324. }
  4325. catch (Exception)
  4326. {
  4327. timer_500ms.Enabled = false;
  4328. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4329. timer_500ms.Enabled = true;
  4330. }
  4331. Delay_ms(200);
  4332. //设置转速百分比100%
  4333. textBox_MotorSpeedPercent.Text = "100";
  4334. ConfigParam[0] = (byte)100;
  4335. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4336. MotorRunStatus = !MotorRunStatus;
  4337. button_FacModeMotorRun.BackColor = Color.Yellow;
  4338. Delay_ms(200);
  4339. //电机进入配置模式
  4340. var RunMode = new byte[1];
  4341. RunMode[0] = 0x01;
  4342. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4343. }
  4344. else //运转状态
  4345. {
  4346. //设置转速百分比0%
  4347. textBox_MotorSpeedPercent.Text = "0";
  4348. ConfigParam[0] = (byte)0;
  4349. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4350. MotorRunStatus = !MotorRunStatus;
  4351. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4352. Delay_ms(200);
  4353. //还原为原始值
  4354. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4355. try
  4356. {
  4357. for (int i = 0; i < strDataTemp.Length; i++)
  4358. {
  4359. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4360. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4361. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4362. }
  4363. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4364. return;
  4365. }
  4366. catch (Exception)
  4367. {
  4368. timer_500ms.Enabled = false;
  4369. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4370. timer_500ms.Enabled = true;
  4371. }
  4372. Delay_ms(200);
  4373. //电机退出配置模式
  4374. var RunMode = new byte[1];
  4375. RunMode[0] = 0x00;
  4376. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4377. }
  4378. }
  4379. /// <summary>
  4380. /// 生产模式写入型号
  4381. /// </summary>
  4382. /// <param name="sender"></param>
  4383. /// <param name="e"></param>
  4384. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4385. {
  4386. string Mode = textBox_FacModeName.Text;
  4387. var ModeArray = new byte[16];
  4388. for (ushort i = 0; i < Mode.Length; i++)
  4389. {
  4390. ModeArray[i] = (byte)Mode[i];
  4391. }
  4392. if (Mode.Length < 16)
  4393. {
  4394. ModeArray[Mode.Length] = (byte)'.';
  4395. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4396. {
  4397. ModeArray[Mode.Length + 1 + i] = 0x20;
  4398. }
  4399. }
  4400. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4401. }
  4402. /// <summary>
  4403. /// 生产模式写入SN
  4404. /// </summary>
  4405. /// <param name="sender"></param>
  4406. /// <param name="e"></param>
  4407. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4408. {
  4409. string SN = textBox_FacModeNum.Text;
  4410. var SNArray = new byte[16];
  4411. for (ushort i = 0; i < SN.Length; i++)
  4412. {
  4413. SNArray[i] = (byte)SN[i];
  4414. }
  4415. if (SN.Length < 16)
  4416. {
  4417. SNArray[SN.Length] = (byte)'.';
  4418. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4419. {
  4420. SNArray[SN.Length + 1 + i] = 0x20;
  4421. }
  4422. }
  4423. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4424. }
  4425. /// <summary>
  4426. /// 生产模式读取版本信息
  4427. /// </summary>
  4428. /// <param name="sender"></param>
  4429. /// <param name="e"></param>
  4430. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4431. {
  4432. textBox_Model.Text = "---";
  4433. textBox_SN.Text = "---";
  4434. textBox_HW.Text = "---";
  4435. textBox_FW.Text = "---";
  4436. textBox_SP.Text = "---";
  4437. textBox_OBC_ReadModel.Text = "---";
  4438. textBox_OBC_ReadSN.Text = "---";
  4439. textBox_OBC_ReadHW.Text = "---";
  4440. textBox_OBC_ReadFW.Text = "---";
  4441. textBox_OBC_ReadSP.Text = "---";
  4442. textBox_FacModeName.Text = "---";
  4443. textBox_FacModeNum.Text = "---";
  4444. textBox_FacModeHW.Text = "---";
  4445. textBox_FacModeFW.Text = "---";
  4446. textBox_FacModeSP.Text = "---";
  4447. textBox_FacModeGit.Text = "---";
  4448. Class_Motor_Ver.Mode = "---";
  4449. Class_Motor_Ver.SN = "---";
  4450. Class_Motor_Ver.HW = "---";
  4451. Class_Motor_Ver.FW = "---";
  4452. Class_Motor_Ver.Special = "---";
  4453. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4454. }
  4455. /// <summary>
  4456. /// 生产模式写入生产信息
  4457. /// </summary>
  4458. /// <param name="sender"></param>
  4459. /// <param name="e"></param>
  4460. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4461. {
  4462. var MACArray = new byte[32];
  4463. string MacDefaultInfo = "";
  4464. string MacAddDefaultInfo = "";
  4465. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4466. string MacPPDefaultInfo = "";
  4467. do
  4468. {
  4469. //填入生产商
  4470. if (toolStripTextBox_MAC.Text == string.Empty)
  4471. {
  4472. break;
  4473. }
  4474. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4475. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4476. {
  4477. MACArray[i] = (byte)MacDefaultInfo[i];
  4478. }
  4479. if (MacDefaultInfo.Length < 8)
  4480. {
  4481. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4482. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4483. {
  4484. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4485. }
  4486. }
  4487. //填入生产地
  4488. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4489. {
  4490. break;
  4491. }
  4492. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4493. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4494. {
  4495. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4496. }
  4497. if (MacAddDefaultInfo.Length < 8)
  4498. {
  4499. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4500. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4501. {
  4502. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4503. }
  4504. }
  4505. //填入生产日期
  4506. if (toolStripTextBox_MACDate.Text == string.Empty)
  4507. {
  4508. break;
  4509. }
  4510. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4511. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4512. {
  4513. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4514. }
  4515. if (MacDateDefaultInfo.Length < 8)
  4516. {
  4517. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4518. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4519. {
  4520. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4521. }
  4522. }
  4523. //填入产品标识
  4524. if (toolStripTextBox_MACPD.Text == string.Empty)
  4525. {
  4526. break;
  4527. }
  4528. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4529. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4530. {
  4531. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4532. }
  4533. if (MacPPDefaultInfo.Length < 8)
  4534. {
  4535. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4536. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4537. {
  4538. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4539. }
  4540. }
  4541. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4542. return;
  4543. } while (false);
  4544. timer_500ms.Enabled = false;
  4545. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4546. timer_500ms.Enabled = true;
  4547. }
  4548. /// <summary>
  4549. /// 生产模式保存测试页面
  4550. /// </summary>
  4551. /// <param name="sender"></param>
  4552. /// <param name="e"></param>
  4553. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4554. {
  4555. Button_FacModeSaveResult.Text = "存储中…";
  4556. string[] AssistParams = new string[15];
  4557. do
  4558. {
  4559. //读取一次马达参数
  4560. richTextBox_MotorParam.Clear();
  4561. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4562. Delay_ms(100);
  4563. //读取一次整车参数
  4564. richTextBox_BikeParam.Clear();
  4565. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4566. Delay_ms(100);
  4567. //读取一次整车参数2
  4568. richTextBox_BikeParam2.Clear();
  4569. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4570. Delay_ms(100);
  4571. //读取一次控制参数
  4572. richTextBox_ControlParam.Clear();
  4573. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4574. Delay_ms(100);
  4575. //查询传感器
  4576. richTextBox_SensorParam.Clear();
  4577. textBox_FacModeSensorADC0.Text = "";
  4578. textBox_FacModeSensorADC1.Text = "";
  4579. textBox_FacModeSensorADC2.Text = "";
  4580. textBox_FacModeSensorADC3.Text = "";
  4581. textBox_FacModeSensorADC4.Text = "";
  4582. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4583. Delay_ms(100);
  4584. //读取15次助力参数
  4585. for (int i = 1; i <= 15; i++)
  4586. {
  4587. var ConfigParam = new byte[4];
  4588. richTextBox_AssistParam.Clear();
  4589. ConfigParam[0] = (byte)(i & 0xFF);
  4590. ConfigParam[1] = (byte)(i >> 8);
  4591. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4592. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4593. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4594. Delay_ms(200);
  4595. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4596. }
  4597. //读取一次用户骑行参数
  4598. richTextBox_UsrRidesParam.Clear();
  4599. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4600. Delay_ms(100);
  4601. //读取一次调试信息
  4602. richTextBox_DebugParam.Clear();
  4603. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4604. Delay_ms(100);
  4605. //读取一次历史信息
  4606. richTextBox_Record.Clear();
  4607. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4608. Delay_ms(100);
  4609. //读取一次电机运行信息
  4610. var CtrlCode = new byte[2];
  4611. CtrlCode[0] = 0x00;
  4612. CtrlCode[1] = 0xF0;
  4613. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4614. Delay_ms(100);
  4615. //读取一次版本信息
  4616. textBox_Model.Text = "---";
  4617. textBox_SN.Text = "---";
  4618. textBox_HW.Text = "---";
  4619. textBox_FW.Text = "---";
  4620. textBox_OBC_ReadModel.Text = "---";
  4621. textBox_OBC_ReadSN.Text = "---";
  4622. textBox_OBC_ReadHW.Text = "---";
  4623. textBox_OBC_ReadFW.Text = "---";
  4624. textBox_FacModeName.Text = "---";
  4625. textBox_FacModeNum.Text = "---";
  4626. textBox_FacModeHW.Text = "---";
  4627. textBox_FacModeFW.Text = "---";
  4628. Class_Motor_Ver.Mode = "---";
  4629. Class_Motor_Ver.SN = "---";
  4630. Class_Motor_Ver.HW = "---";
  4631. Class_Motor_Ver.FW = "---";
  4632. Class_Motor_Ver.Special = "---";
  4633. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4634. Delay_ms(100);
  4635. //读取一次生产信息
  4636. textBox_MAC.Text = "";
  4637. textBox_MACAdd.Text = "";
  4638. textBox_MACDate.Text = "";
  4639. textBox_PP.Text = "";
  4640. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4641. Delay_ms(100);
  4642. //读取一次自定义信息
  4643. textBox_User1.Text = "---";
  4644. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4645. Delay_ms(100);
  4646. textBox_User2.Text = "---";
  4647. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4648. Delay_ms(100);
  4649. textBox_User3.Text = "---";
  4650. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4651. Delay_ms(100);
  4652. //读取一次密钥
  4653. textBox_Key.Text = "---";
  4654. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4655. Delay_ms(100);
  4656. //读取一次存储标志
  4657. radioButton_EE_SaveYes.Checked = false;
  4658. radioButton_EE_SaveNo.Checked = false;
  4659. radioButton_SIP_SaveYes.Checked = false;
  4660. radioButton_SIP_SaveNo.Checked = false;
  4661. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4662. Delay_ms(100);
  4663. //读取一次MOS内阻校准参数
  4664. foreach (Control c in groupBox21.Controls)
  4665. {
  4666. if (c is TextBox)
  4667. c.Text = "";
  4668. }
  4669. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4670. Delay_ms(100);
  4671. //提示检查
  4672. #if false
  4673. timer_1s.Enabled = false;
  4674. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4675. {
  4676. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4677. timer_1s.Enabled = true;
  4678. return;
  4679. }
  4680. timer_1s.Enabled = true;
  4681. Delay_ms(200);
  4682. #endif
  4683. //判断数据是否有效
  4684. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4685. {
  4686. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4687. break;
  4688. }
  4689. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4690. {
  4691. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4692. break;
  4693. }
  4694. //设置文件存储路径
  4695. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4696. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4697. Save_Path += PD_PathName;
  4698. if (!Directory.Exists(Save_Path))
  4699. Directory.CreateDirectory(Save_Path);
  4700. //保存页面
  4701. string PIC_SaveFileName = "";
  4702. Double scaleX = PrimaryScreen.ScaleX;
  4703. Double scaleY = PrimaryScreen.ScaleY;
  4704. //保存页面
  4705. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4706. Graphics g = Graphics.FromImage(bit);
  4707. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4708. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4709. bit.Save(PIC_SaveFileName);
  4710. //保存数据
  4711. string DataFileName = "";
  4712. string FileInfo = "";
  4713. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4714. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4715. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4716. FileInfo += "\r\n";
  4717. FileInfo += "[电机信息]\r\n";
  4718. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4719. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4720. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4721. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4722. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4723. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4724. FileInfo += "\r\n";
  4725. FileInfo += "[马达参数]\r\n";
  4726. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4727. FileInfo += "\r\n";
  4728. FileInfo += "[整车参数]\r\n";
  4729. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4730. FileInfo += "\r\n";
  4731. FileInfo += "[控制参数]\r\n";
  4732. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4733. FileInfo += "\r\n";
  4734. FileInfo += "[传感器参数]\r\n";
  4735. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4736. FileInfo += "\r\n";
  4737. FileInfo += "[助力参数]\r\n";
  4738. for(int i=0;i<15;i++)
  4739. {
  4740. FileInfo += AssistParams[i] + "\r\n";
  4741. }
  4742. FileInfo += "[调试参数]\r\n";
  4743. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4744. FileInfo += "\r\n";
  4745. FileInfo += "[历史信息]\r\n";
  4746. FileInfo += richTextBox_Record.Text + "\r\n";
  4747. FileInfo += "\r\n";
  4748. FileInfo += "[MOS内阻校准参数]\r\n";
  4749. FileInfo += textBox_MOS_K1.Text + ", ";
  4750. FileInfo += textBox_MOS_K2.Text + ", ";
  4751. FileInfo += textBox_MOS_K3.Text + ", ";
  4752. FileInfo += textBox_MOS_K4.Text + ", ";
  4753. FileInfo += textBox_MOS_K5.Text + ", ";
  4754. FileInfo += textBox_MOS_R1.Text + ", ";
  4755. FileInfo += textBox_MOS_R2.Text + ", ";
  4756. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4757. FileInfo += "\r\n";
  4758. FileInfo += "[整车参数2]\r\n";
  4759. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4760. FileInfo += "\r\n";
  4761. FileInfo += "[用户骑行参数]\r\n";
  4762. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4763. FileInfo += "\r\n";
  4764. FileInfo += "[生产信息]\r\n";
  4765. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4766. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4767. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4768. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4769. FileInfo += "\r\n";
  4770. FileInfo += "[自定义信息]\r\n";
  4771. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4772. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4773. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4774. FileInfo += "\r\n";
  4775. FileInfo += "[校验密钥]\r\n";
  4776. FileInfo += textBox_Key.Text + "\r\n";
  4777. FileInfo += "\r\n";
  4778. FileInfo += "[存储标志]\r\n";
  4779. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4780. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4781. FileInfo += "\r\n";
  4782. FileInfo += Local_HdInformation;
  4783. FileInfo += "\r\n";
  4784. FileInfo += "文件格式: V2.0\r\n";
  4785. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4786. Delay_ms(1000);
  4787. timer_500ms.Enabled = false;
  4788. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4789. timer_500ms.Enabled = true;
  4790. //数据上传
  4791. if (myFtp.IsNetConnected == true)
  4792. {
  4793. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4794. //检查路径
  4795. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4796. {
  4797. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4798. }
  4799. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4800. {
  4801. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4802. }
  4803. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4804. {
  4805. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4806. }
  4807. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4808. {
  4809. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4810. }
  4811. //上传文件
  4812. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4813. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4814. if ((result1 & result2) == true)
  4815. {
  4816. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4817. }
  4818. else
  4819. {
  4820. timer_500ms.Enabled = false;
  4821. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4822. timer_500ms.Enabled = true;
  4823. }
  4824. }
  4825. else
  4826. {
  4827. timer_500ms.Enabled = false;
  4828. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4829. timer_500ms.Enabled = true;
  4830. }
  4831. Button_FacModeSaveResult.Text = "保存数据";
  4832. return;
  4833. } while (false);
  4834. timer_500ms.Enabled = false;
  4835. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4836. timer_500ms.Enabled = true;
  4837. Button_FacModeSaveResult.Text = "保存数据";
  4838. }
  4839. /// <summary>
  4840. /// 工具箱页面保存
  4841. /// </summary>
  4842. /// <param name="sender"></param>
  4843. /// <param name="e"></param>
  4844. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4845. {
  4846. Double scaleX = PrimaryScreen.ScaleX;
  4847. Double scaleY = PrimaryScreen.ScaleY;
  4848. //保存页面
  4849. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4850. Graphics g = Graphics.FromImage(bit);
  4851. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4852. SaveFileDialog sf = new SaveFileDialog();
  4853. sf.Title = "页面保存";
  4854. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4855. sf.Filter = "图片|*.png";
  4856. timer_500ms.Enabled = false;
  4857. if (sf.ShowDialog() == DialogResult.OK)
  4858. {
  4859. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4860. }
  4861. timer_500ms.Enabled = true;
  4862. }
  4863. /// <summary>
  4864. /// 生产模式关机
  4865. /// </summary>
  4866. /// <param name="sender"></param>
  4867. /// <param name="e"></param>
  4868. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4869. {
  4870. var Code_Off = new byte[5];
  4871. var Code_Reset = new byte[5];
  4872. Code_Off[0] = (byte)'O';
  4873. Code_Off[1] = (byte)'F';
  4874. Code_Off[2] = (byte)'F';
  4875. Code_Off[3] = (byte)'.';
  4876. Code_Off[4] = (byte)'.';
  4877. Code_Reset[0] = (byte)'R';
  4878. Code_Reset[1] = (byte)'E';
  4879. Code_Reset[2] = (byte)'S';
  4880. Code_Reset[3] = (byte)'E';
  4881. Code_Reset[4] = (byte)'T';
  4882. timer_500ms.Enabled = false;
  4883. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4884. {
  4885. timer_500ms.Enabled = true;
  4886. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4887. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4888. PowerOffAckStatus = false;
  4889. Delay_ms(250);
  4890. int TryCnt = 3;
  4891. while ((TryCnt--) >= 0)
  4892. {
  4893. if (!PowerOffAckStatus)
  4894. {
  4895. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4896. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4897. PowerOffAckStatus = false;
  4898. Delay_ms(250);
  4899. }
  4900. else break;
  4901. }
  4902. if (PowerOffAckStatus)
  4903. {
  4904. timer_500ms.Enabled = false;
  4905. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4906. timer_500ms.Enabled = true;
  4907. }
  4908. else
  4909. {
  4910. timer_500ms.Enabled = false;
  4911. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4912. timer_500ms.Enabled = true;
  4913. }
  4914. }
  4915. timer_500ms.Enabled = true;
  4916. }
  4917. //仪表电源键按下
  4918. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4919. {
  4920. var Code = new byte[2];
  4921. Code[0] = 0;
  4922. Code[1] = 0b00100000;
  4923. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4924. }
  4925. /// <summary>
  4926. /// 仪表加键按下
  4927. /// </summary>
  4928. /// <param name="sender"></param>
  4929. /// <param name="e"></param>
  4930. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4931. {
  4932. var Code = new byte[2];
  4933. Code[0] = 0;
  4934. Code[1] = 0b00010000;
  4935. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4936. }
  4937. /// <summary>
  4938. /// 仪表减键按下
  4939. /// </summary>
  4940. /// <param name="sender"></param>
  4941. /// <param name="e"></param>
  4942. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4943. {
  4944. var Code = new byte[2];
  4945. Code[0] = 0;
  4946. Code[1] = 0b00001000;
  4947. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4948. }
  4949. /// <summary>
  4950. /// 仪表Walk键按下
  4951. /// </summary>
  4952. /// <param name="sender"></param>
  4953. /// <param name="e"></param>
  4954. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4955. {
  4956. var Code = new byte[2];
  4957. Code[0] = 0;
  4958. Code[1] = 0b00000100;
  4959. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4960. }
  4961. /// <summary>
  4962. /// 仪表Light键按下
  4963. /// </summary>
  4964. /// <param name="sender"></param>
  4965. /// <param name="e"></param>
  4966. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4967. {
  4968. var Code = new byte[2];
  4969. Code[0] = 0;
  4970. Code[1] = 0b00000010;
  4971. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4972. }
  4973. /// <summary>
  4974. /// 仪表Set键按下
  4975. /// </summary>
  4976. /// <param name="sender"></param>
  4977. /// <param name="e"></param>
  4978. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4979. {
  4980. var Code = new byte[2];
  4981. Code[0] = 0;
  4982. Code[1] = 0b00000001;
  4983. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4984. }
  4985. /// <summary>
  4986. /// 导出电机故障日志
  4987. /// </summary>
  4988. /// <param name="sender"></param>
  4989. /// <param name="e"></param>
  4990. private void button_ExportLog_Click(object sender, EventArgs e)
  4991. {
  4992. var Address = new byte[4];
  4993. UInt32 Address_Begin;
  4994. UInt32 Addres_End;
  4995. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4996. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4997. richTextBox_Record.Clear();
  4998. textBox_LogAddrBegin.ReadOnly = true;
  4999. textBox_LogAddrEnd.ReadOnly = true;
  5000. if (!mySerialProcess.mySerial.IsOpen)
  5001. {
  5002. timer_500ms.Enabled = false;
  5003. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5004. timer_500ms.Enabled = true;
  5005. return;
  5006. }
  5007. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5008. {
  5009. timer_500ms.Enabled = false;
  5010. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5011. timer_500ms.Enabled = true;
  5012. return;
  5013. }
  5014. else
  5015. {
  5016. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5017. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5018. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5019. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5020. if (Addres_End <= Address_Begin)
  5021. {
  5022. timer_500ms.Enabled = false;
  5023. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5024. timer_500ms.Enabled = true;
  5025. return;
  5026. }
  5027. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5028. {
  5029. timer_500ms.Enabled = false;
  5030. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5031. timer_500ms.Enabled = true;
  5032. return;
  5033. }
  5034. else
  5035. {
  5036. UInt32 ReadCount = 0;
  5037. button_ExportLog.Text = "导出中...";
  5038. button_ExportLog.Enabled = false;
  5039. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5040. for (ushort i = 0; i < ReadCount; i++)
  5041. {
  5042. var SendByte = new byte[8];
  5043. UInt32 Address_Temp_Begin;
  5044. UInt32 Address_Temp_End;
  5045. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5046. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5047. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5048. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5049. SendByte[3] = (byte)(Address_Temp_Begin);
  5050. Address_Temp_End = Address_Temp_Begin + 127;
  5051. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5052. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5053. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5054. SendByte[7] = (byte)(Address_Temp_End);
  5055. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5056. Delay_ms(200);//Thread.Sleep(200);
  5057. }
  5058. button_ExportLog.Text = "导出日志";
  5059. button_ExportLog.Enabled = true;
  5060. }
  5061. }
  5062. }
  5063. /// <summary>
  5064. /// 保存日志信息
  5065. /// </summary>
  5066. /// <param name="sender"></param>
  5067. /// <param name="e"></param>
  5068. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5069. {
  5070. string SaveInfo = "";
  5071. if (richTextBox_Record.Text == string.Empty)
  5072. {
  5073. timer_500ms.Enabled = false;
  5074. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5075. timer_500ms.Enabled = true;
  5076. return;
  5077. }
  5078. //获取保存信息
  5079. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5080. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5081. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5082. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5083. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5084. SaveInfo += "\r\n";
  5085. SaveInfo += richTextBox_Record.Text;
  5086. //设置保存路径和文件名
  5087. SaveFileDialog sf = new SaveFileDialog();
  5088. sf.Title = "数据保存";
  5089. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5090. sf.FileName.Replace(" ", "");
  5091. sf.Filter = "日志|*.ttlog";
  5092. if (sf.ShowDialog() == DialogResult.OK)
  5093. {
  5094. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5095. }
  5096. }
  5097. /// <summary>
  5098. /// 双击修改日志起始地址
  5099. /// </summary>
  5100. /// <param name="sender"></param>
  5101. /// <param name="e"></param>
  5102. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5103. {
  5104. textBox_LogAddrBegin.ReadOnly = false;
  5105. }
  5106. /// <summary>
  5107. /// 双击修改日志结束地址
  5108. /// </summary>
  5109. /// <param name="sender"></param>
  5110. /// <param name="e"></param>
  5111. private void label88_DoubleClick(object sender, EventArgs e)
  5112. {
  5113. textBox_LogAddrEnd.ReadOnly = false;
  5114. }
  5115. /// <summary>
  5116. /// 存储器自动读取选择
  5117. /// </summary>
  5118. /// <param name="sender"></param>
  5119. /// <param name="e"></param>
  5120. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5121. {
  5122. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5123. {
  5124. //检查串口是否打开
  5125. if (!mySerialProcess.mySerial.IsOpen)
  5126. {
  5127. timer_500ms.Enabled = false;
  5128. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5129. timer_500ms.Enabled = true;
  5130. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5131. return;
  5132. }
  5133. }
  5134. }
  5135. /// <summary>
  5136. /// 系统开机按钮
  5137. /// </summary>
  5138. /// <param name="sender"></param>
  5139. /// <param name="e"></param>
  5140. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5141. {
  5142. byte[] Data = new byte[1];
  5143. Data[0] = 0xF1;
  5144. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5145. }
  5146. /// <summary>
  5147. /// 系统关机按钮
  5148. /// </summary>
  5149. /// <param name="sender"></param>
  5150. /// <param name="e"></param>
  5151. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5152. {
  5153. byte[] Data = new byte[1];
  5154. Data[0] = 0xF0;
  5155. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5156. }
  5157. /// <summary>
  5158. /// 连接开机选择
  5159. /// </summary>
  5160. /// <param name="sender"></param>
  5161. /// <param name="e"></param>
  5162. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5163. {
  5164. //输入用户名
  5165. EnterForm1.ShowDialog();
  5166. try
  5167. {
  5168. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5169. {
  5170. if (EnterForm1.comboBox_User.Text == "管理员")
  5171. {
  5172. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5173. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5174. }
  5175. else
  5176. {
  5177. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5178. }
  5179. }
  5180. else
  5181. {
  5182. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5183. }
  5184. }
  5185. catch (Exception)
  5186. {
  5187. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5188. }
  5189. }
  5190. /// <summary>
  5191. /// 断开关机选择
  5192. /// </summary>
  5193. /// <param name="sender"></param>
  5194. /// <param name="e"></param>
  5195. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5196. {
  5197. //输入用户名
  5198. EnterForm1.ShowDialog();
  5199. try
  5200. {
  5201. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5202. {
  5203. if (EnterForm1.comboBox_User.Text == "管理员")
  5204. {
  5205. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5206. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5207. }
  5208. else
  5209. {
  5210. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5211. }
  5212. }
  5213. else
  5214. {
  5215. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5216. }
  5217. }
  5218. catch (Exception)
  5219. {
  5220. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5221. }
  5222. }
  5223. /// <summary>
  5224. /// 识别通讯盒选择
  5225. /// </summary>
  5226. /// <param name="sender"></param>
  5227. /// <param name="e"></param>
  5228. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5229. {
  5230. //输入用户名
  5231. EnterForm1.ShowDialog();
  5232. try
  5233. {
  5234. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5235. {
  5236. if (EnterForm1.comboBox_User.Text == "管理员")
  5237. {
  5238. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5239. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5240. }
  5241. else
  5242. {
  5243. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5244. }
  5245. }
  5246. else
  5247. {
  5248. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5249. }
  5250. }
  5251. catch (Exception)
  5252. {
  5253. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5254. }
  5255. }
  5256. /// <summary>
  5257. /// 将配置信息导出为cfg文件
  5258. /// </summary>
  5259. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5260. {
  5261. if (DeleteFlag)
  5262. {
  5263. if (File.Exists(FileName))
  5264. File.Delete(FileName);
  5265. }
  5266. string CfgFileInfo = "";
  5267. CfgFileInfo += "[PortSet]" + "\r\n";
  5268. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5269. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5270. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5271. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5272. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5273. CfgFileInfo += "\r\n";
  5274. CfgFileInfo += "[Option]" + "\r\n";
  5275. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5276. CfgFileInfo += "\r\n";
  5277. CfgFileInfo += "[ServerSet]" + "\r\n";
  5278. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5279. CfgFileInfo += "\r\n";
  5280. CfgFileInfo += "[MacInfo]" + "\r\n";
  5281. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5282. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5283. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5284. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5285. CfgFileInfo += "\r\n";
  5286. CfgFileInfo += "[LogAddress]" + "\r\n";
  5287. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5288. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5289. CfgFileInfo += "\r\n";
  5290. CfgFileInfo += "[MotorType]" + "\r\n";
  5291. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5292. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5293. CfgFileInfo += "\r\n";
  5294. CfgFileInfo += "[CheckValue]" + "\r\n";
  5295. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5296. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5297. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5298. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5299. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5300. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5301. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5302. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5303. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5304. CfgFileInfo += "\r\n";
  5305. CfgFileInfo += "[MosCalK]" + "\r\n";
  5306. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5307. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5308. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5309. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5310. CfgFileInfo += "\r\n";
  5311. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5312. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5313. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5314. CfgFileInfo += "\r\n";
  5315. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5316. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5317. CfgFileInfo += "\r\n";
  5318. CfgFileInfo += "[AngleCal]" + "\r\n";
  5319. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5320. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5321. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5322. }
  5323. /// <summary>
  5324. /// 配置状态更新,点击时保存
  5325. /// </summary>
  5326. private void ConfigFileSave_Click(object sender, EventArgs e)
  5327. {
  5328. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5329. }
  5330. /// <summary>
  5331. /// 文本框修改结束,回车保存
  5332. /// </summary>
  5333. /// <param name="sender"></param>
  5334. /// <param name="e"></param>
  5335. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5336. {
  5337. if (e.KeyCode == Keys.Enter)
  5338. {
  5339. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5340. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5341. }
  5342. }
  5343. /// <summary>
  5344. /// 弹出扫码按钮
  5345. /// </summary>
  5346. /// <param name="sender"></param>
  5347. /// <param name="e"></param>
  5348. private void button_ScanCode_Click(object sender, EventArgs e)
  5349. {
  5350. Scan scan_form = new Scan();
  5351. scan_form.ShowDialog();
  5352. do
  5353. {
  5354. if (scan_form.textBox_Scan.Text == string.Empty)
  5355. {
  5356. timer_500ms.Enabled = false;
  5357. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5358. timer_500ms.Enabled = true;
  5359. break;
  5360. }
  5361. string ScanInfo = scan_form.textBox_Scan.Text;
  5362. string regexInfo = "";
  5363. string[] InfoList = { "" };
  5364. try
  5365. {
  5366. if (中置电机ToolStripMenuItem.Checked == true)
  5367. {
  5368. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5369. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5370. }
  5371. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5372. {
  5373. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5374. string Model = InfoList[0];
  5375. string Spec = InfoList[1];
  5376. string Sn = InfoList[2];
  5377. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5378. InfoList[1] = Sn;
  5379. }
  5380. }
  5381. catch (Exception)
  5382. {
  5383. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5384. return;
  5385. }
  5386. if (InfoList.Length >= 2)
  5387. {
  5388. //写入型号
  5389. textBox_FacModeName.Text = InfoList[0];
  5390. string Mode = textBox_FacModeName.Text;
  5391. var ModeArray = new byte[16];
  5392. for (ushort i = 0; i < Mode.Length; i++)
  5393. {
  5394. ModeArray[i] = (byte)Mode[i];
  5395. }
  5396. if (Mode.Length < 16)
  5397. {
  5398. ModeArray[Mode.Length] = (byte)'.';
  5399. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5400. {
  5401. ModeArray[Mode.Length + 1 + i] = 0x20;
  5402. }
  5403. }
  5404. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5405. //写入SN
  5406. textBox_FacModeNum.Text = InfoList[1];
  5407. string SN = textBox_FacModeNum.Text;
  5408. var SNArray = new byte[16];
  5409. for (ushort i = 0; i < SN.Length; i++)
  5410. {
  5411. SNArray[i] = (byte)SN[i];
  5412. }
  5413. if (SN.Length < 16)
  5414. {
  5415. SNArray[SN.Length] = (byte)'.';
  5416. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5417. {
  5418. SNArray[SN.Length + 1 + i] = 0x20;
  5419. }
  5420. }
  5421. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5422. }
  5423. else
  5424. {
  5425. timer_500ms.Enabled = false;
  5426. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5427. timer_500ms.Enabled = true;
  5428. break;
  5429. }
  5430. } while (false);
  5431. scan_form.Dispose();
  5432. }
  5433. /// <summary>
  5434. /// 切换电机类型
  5435. /// </summary>
  5436. /// <param name="sender"></param>
  5437. /// <param name="e"></param>
  5438. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5439. {
  5440. 中置电机ToolStripMenuItem.Checked = true;
  5441. 轮毂电机ToolStripMenuItem.Checked = false;
  5442. toolStripTextBox_MACPD.Text = "MM_MC1";
  5443. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5444. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5445. }
  5446. /// <summary>
  5447. /// 切换电机类型
  5448. /// </summary>
  5449. /// <param name="sender"></param>
  5450. /// <param name="e"></param>
  5451. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5452. {
  5453. 中置电机ToolStripMenuItem.Checked = false;
  5454. 轮毂电机ToolStripMenuItem.Checked = true;
  5455. toolStripTextBox_MACPD.Text = "GF_250_1";
  5456. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5457. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5458. }
  5459. /// <summary>
  5460. /// 获取配置文件日期
  5461. /// </summary>
  5462. /// <param name="DisAll"></param>
  5463. private void GetDateList(bool DisAll)
  5464. {
  5465. string[] DateList = { "" };
  5466. //从服务器更新日期列表
  5467. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5468. {
  5469. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5470. }
  5471. //从本地更新日期列表
  5472. else
  5473. {
  5474. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5475. }
  5476. comboBox_FacModeCfgDate.Items.Clear();
  5477. comboBox_CheckModeCfgDate.Items.Clear();
  5478. //日期列表加载
  5479. if (DisAll == true)
  5480. {
  5481. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5482. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5483. comboBox_FacModeCfgDate.Items.Add("---");
  5484. comboBox_CheckModeCfgDate.Items.Add("---");
  5485. foreach (var file in DateList)
  5486. {
  5487. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5488. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5489. }
  5490. }
  5491. else
  5492. {
  5493. if (DateList.Length > 10)
  5494. {
  5495. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5496. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5497. comboBox_FacModeCfgDate.Items.Add("---");
  5498. comboBox_CheckModeCfgDate.Items.Add("---");
  5499. }
  5500. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5501. {
  5502. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5503. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5504. }
  5505. }
  5506. }
  5507. /// <summary>
  5508. /// 获取配置文件列表
  5509. /// </summary>
  5510. /// <param name="date"></param>
  5511. private void GetFileListFrom(string date)
  5512. {
  5513. string[] FileList = { "" };
  5514. //从服务器更新文件列表
  5515. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5516. {
  5517. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5518. }
  5519. else
  5520. {
  5521. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5522. }
  5523. comboBox_CheckModeCfgFile.Items.Clear();
  5524. comboBox_FacModeCfgFile.Items.Clear();
  5525. foreach (var file in FileList)
  5526. {
  5527. if (file.Contains(".ttcfg"))
  5528. {
  5529. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5530. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5531. }
  5532. }
  5533. }
  5534. /// <summary>
  5535. /// 检验模式选择文件日期
  5536. /// </summary>
  5537. /// <param name="sender"></param>
  5538. /// <param name="e"></param>
  5539. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5540. {
  5541. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5542. {
  5543. GetDateList(true);
  5544. }
  5545. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5546. {
  5547. GetDateList(false);
  5548. }
  5549. else
  5550. {
  5551. comboBox_CheckModeCfgFile.Text = "";
  5552. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5553. }
  5554. }
  5555. /// <summary>
  5556. /// 配置模式选择文件日期
  5557. /// </summary>
  5558. /// <param name="sender"></param>
  5559. /// <param name="e"></param>
  5560. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5561. {
  5562. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5563. {
  5564. GetDateList(true);
  5565. }
  5566. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5567. {
  5568. GetDateList(false);
  5569. }
  5570. else
  5571. {
  5572. comboBox_FacModeCfgFile.Text = "";
  5573. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5574. }
  5575. }
  5576. /// <summary>
  5577. /// 选中量产模式
  5578. /// </summary>
  5579. /// <param name="sender"></param>
  5580. /// <param name="e"></param>
  5581. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5582. {
  5583. //更新生产配置文件目录
  5584. GetDateList(false);
  5585. }
  5586. /// <summary>
  5587. /// 量产测试结束
  5588. /// </summary>
  5589. /// <param name=""></param>
  5590. private void FacMode_Stop(bool OK_Flag)
  5591. {
  5592. //打开开始按钮
  5593. button__FacMode_Start.Enabled = true;
  5594. //系统关机
  5595. var Code = new byte[32];//发送的指令数据
  5596. Code[0] = 0xF0;
  5597. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5598. //关闭串口
  5599. //mySerialProcess.SerialClose(false);
  5600. //路径设置
  5601. string LocalSavePath = "";
  5602. string ServerSavePath = "";
  5603. if (OK_Flag)
  5604. {
  5605. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5606. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5607. }
  5608. else
  5609. {
  5610. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5611. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5612. }
  5613. if (Directory.Exists(LocalSavePath) == false)
  5614. {
  5615. Directory.CreateDirectory(LocalSavePath);
  5616. }
  5617. //保存和上传
  5618. string LogSavePath = "";
  5619. string LogSaveFileName = "";
  5620. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_");
  5621. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5622. if (Directory.Exists(LogSavePath) == false)
  5623. {
  5624. Directory.CreateDirectory(LogSavePath);
  5625. }
  5626. //测试页面
  5627. Double scaleX = PrimaryScreen.ScaleX;
  5628. Double scaleY = PrimaryScreen.ScaleY;
  5629. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5630. Graphics g = Graphics.FromImage(bit);
  5631. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5632. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5633. bit.Save(LogSaveFileName);
  5634. //上传测试页面到服务器
  5635. if (myFtp.IsNetConnected == true)
  5636. {
  5637. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5638. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5639. {
  5640. myFtp.MakeDir(ServerSavePath + DateNow);
  5641. }
  5642. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5643. {
  5644. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5645. }
  5646. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5647. if (result == true)
  5648. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5649. }
  5650. else
  5651. {
  5652. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5653. }
  5654. //测试记录
  5655. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5656. string file_str = "";
  5657. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5658. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5659. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5660. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5661. file_str += Local_HdInformation;
  5662. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5663. //上传测试记录到服务器
  5664. if (myFtp.IsNetConnected == true)
  5665. {
  5666. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5667. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5668. {
  5669. myFtp.MakeDir(ServerSavePath + DateNow);
  5670. }
  5671. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5672. {
  5673. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5674. }
  5675. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5676. if (result == true)
  5677. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5678. }
  5679. else
  5680. {
  5681. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5682. }
  5683. //扫码框清空
  5684. textBox_FacModeScan.Text = "";
  5685. }
  5686. /// <summary>
  5687. /// 量产测试开始
  5688. /// </summary>
  5689. /// <param name="sender"></param>
  5690. /// <param name="e"></param>
  5691. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5692. {
  5693. //关闭测试项目编辑
  5694. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5695. foreach (Control c in groupBox2.Controls)
  5696. {
  5697. if (c is CheckBox)
  5698. c.Enabled = false;
  5699. }
  5700. WriteLockStatus = true;
  5701. //检查配置文件
  5702. if (comboBox_FacModeCfgFile.Text == "")
  5703. {
  5704. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5705. return;
  5706. }
  5707. //开始测试
  5708. TestStart();
  5709. }
  5710. /// <summary>
  5711. /// 测试子函数
  5712. /// </summary>
  5713. private void TestStart()
  5714. {
  5715. //初始化标签
  5716. FacModelLabelInit();
  5717. richTextBox_FacModeLog.Clear();
  5718. //按钮禁止操作
  5719. button__FacMode_Start.Enabled = false;
  5720. //记录配置文件
  5721. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5722. //检查打标信息格式
  5723. label_FacModeStatus.Text = "检查扫码信息";
  5724. Delay_ms(500);
  5725. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5726. if (textBox_FacModeScan.Text == string.Empty)
  5727. {
  5728. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5729. button__FacMode_Start.Enabled = true;
  5730. return;
  5731. }
  5732. try
  5733. {
  5734. if (中置电机ToolStripMenuItem.Checked == true)
  5735. {
  5736. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5737. {
  5738. label_FacModeStatus.Text = "存在故障!";
  5739. label_FacModeResult.BackColor = Color.Red;
  5740. label_FacModeResult.Text = "标签格式错误";
  5741. button__FacMode_Start.Enabled = true;
  5742. return;
  5743. }
  5744. }
  5745. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5746. {
  5747. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5748. {
  5749. label_FacModeStatus.Text = "存在故障!";
  5750. label_FacModeResult.BackColor = Color.Red;
  5751. label_FacModeResult.Text = "标签格式错误";
  5752. button__FacMode_Start.Enabled = true;
  5753. return;
  5754. }
  5755. }
  5756. }
  5757. catch (System.Exception)
  5758. {
  5759. label_FacModeStatus.Text = "存在故障!";
  5760. label_FacModeResult.BackColor = Color.Red;
  5761. label_FacModeResult.Text = "标签格式错误";
  5762. button__FacMode_Start.Enabled = true;
  5763. return;
  5764. }
  5765. //打开串口
  5766. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5767. if (!mySerialProcess.mySerial.IsOpen)
  5768. {
  5769. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5770. //按钮禁止操作
  5771. button__FacMode_Start.Enabled = true;
  5772. return;
  5773. }
  5774. //流水号计数
  5775. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5776. serial += 1;
  5777. label_FacModeSerial.Text = serial.ToString();
  5778. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5779. //创建线程,执行测试任务
  5780. Thread th = new Thread(FacModeTest_Task);
  5781. th.Start();
  5782. }
  5783. /// <summary>
  5784. /// 执行一次测试任务
  5785. /// </summary>
  5786. private void FacModeTest_Task()
  5787. {
  5788. //开始测试
  5789. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5790. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5791. //变量定义
  5792. var Code = new byte[255];//发送的指令数据
  5793. label_FacModeStatus.Text = "开始测试";
  5794. BootInfo = "";
  5795. Delay_ms(500);
  5796. label_FacModeStatus.Text = "系统开机";
  5797. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5798. if (uARTToolStripMenuItem.Checked)
  5799. {
  5800. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5801. Code[0] = (byte)'R';
  5802. Code[1] = (byte)'E';
  5803. Code[2] = (byte)'S';
  5804. Code[3] = (byte)'E';
  5805. Code[4] = (byte)'T';
  5806. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5807. Delay_ms(500);
  5808. }
  5809. //发送开机指令
  5810. //确保测试前先关机,发送关机指令再发送开机指令
  5811. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5812. Code[0] = 0xF0;
  5813. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5814. Delay_ms(1500);
  5815. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5816. Code[0] = 0xF1;
  5817. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5818. ACK_WaitCnt = 0;
  5819. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5820. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5821. //检查BOOT版本
  5822. if (BootInfo != string.Empty)
  5823. {
  5824. label_FacModeBootVer.BackColor = Color.Green;
  5825. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5826. Delay_ms(500);
  5827. }
  5828. else
  5829. {
  5830. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5831. label_FacModeStatus.Text = "存在故障!";
  5832. label_FacModeResult.BackColor = Color.Red;
  5833. label_FacModeResult.Text = "测试异常";
  5834. Delay_ms(500);
  5835. //存储异常并上传
  5836. FacMode_Stop(false);
  5837. return;
  5838. }
  5839. //系统清除
  5840. if (checkBox_FacModeSysClear.Checked)
  5841. {
  5842. do
  5843. {
  5844. #if false
  5845. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5846. {
  5847. Code[0] = 0x00;//5S协议
  5848. Code[1] = 0x00;
  5849. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5850. Delay_ms(500);
  5851. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5852. Delay_ms(500);
  5853. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5854. }
  5855. #endif
  5856. //发送系统清除指令
  5857. label_FacModeStatus.Text = "系统清除";
  5858. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5859. Code[0] = (byte)'C';
  5860. Code[1] = (byte)'L';
  5861. Code[2] = (byte)'E';
  5862. Code[3] = (byte)'A';
  5863. Code[4] = (byte)'R';
  5864. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5865. WriteACK = false;
  5866. ACK_WaitCnt = 0;
  5867. while (ACK_WaitCnt <= 6); //3s
  5868. //等待系统清除完成指令
  5869. if (WriteACK == true)
  5870. {
  5871. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5872. label_FacModeSysClear.BackColor = Color.Green;
  5873. }
  5874. else
  5875. {
  5876. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5877. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5878. ACK_WaitCnt = 0;
  5879. while (ACK_WaitCnt <= 6) ; //3s
  5880. //等待系统清除完成指令
  5881. if (WriteACK == true)
  5882. {
  5883. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5884. label_FacModeSysClear.BackColor = Color.Green;
  5885. }
  5886. else
  5887. {
  5888. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5889. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5890. ACK_WaitCnt = 0;
  5891. while (ACK_WaitCnt <= 6) ; //3s
  5892. //等待系统清除完成指令
  5893. if (WriteACK == true)
  5894. {
  5895. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5896. label_FacModeSysClear.BackColor = Color.Green;
  5897. }
  5898. else
  5899. {
  5900. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5901. label_FacModeStatus.Text = "存在故障!";
  5902. label_FacModeResult.BackColor = Color.Red;
  5903. label_FacModeResult.Text = "测试异常";
  5904. Delay_ms(500);
  5905. //存储异常并上传
  5906. FacMode_Stop(false);
  5907. return;
  5908. }
  5909. }
  5910. }
  5911. BootInfo = "";
  5912. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5913. if (uARTToolStripMenuItem.Checked)
  5914. {
  5915. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5916. Code[0] = (byte)'R';
  5917. Code[1] = (byte)'E';
  5918. Code[2] = (byte)'S';
  5919. Code[3] = (byte)'E';
  5920. Code[4] = (byte)'T';
  5921. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5922. Delay_ms(500);
  5923. }
  5924. //系统清除后需重新开机
  5925. label_FacModeStatus.Text = "重新开机";
  5926. //确保测试前先关机,发送关机指令再发送开机指令
  5927. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  5928. Code[0] = 0xF0;
  5929. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5930. Delay_ms(1500);
  5931. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  5932. Code[0] = 0xF1;
  5933. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5934. ACK_WaitCnt = 0;
  5935. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5936. while (ACK_WaitCnt <= 20); //10s
  5937. //获取Boot版本信息
  5938. if (BootInfo != string.Empty)
  5939. {
  5940. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5941. Delay_ms(500);
  5942. }
  5943. else
  5944. {
  5945. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5946. label_FacModeStatus.Text = "存在故障!";
  5947. label_FacModeResult.BackColor = Color.Red;
  5948. label_FacModeResult.Text = "测试异常";
  5949. Delay_ms(500);
  5950. //存储异常并上传
  5951. FacMode_Stop(false);
  5952. return;
  5953. }
  5954. } while (false);
  5955. }
  5956. else
  5957. {
  5958. label_FacModeSysClear.BackColor = Color.Yellow;
  5959. label_FacModeStatus.Text = "跳过系统清除!";
  5960. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5961. Delay_ms(500);
  5962. }
  5963. #if false
  5964. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5965. {
  5966. Code[0] = 0x00;//5S协议
  5967. Code[1] = 0x00;
  5968. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5969. Delay_ms(500);
  5970. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5971. Delay_ms(500);
  5972. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5973. }
  5974. #endif
  5975. //检查是否有故障
  5976. if (textBox_ErrorCode.Text.Contains("H"))
  5977. {
  5978. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5979. label_FacModeStatus.Text = "电机存在故障!";
  5980. label_FacModeResult.BackColor = Color.Red;
  5981. label_FacModeResult.Text = "测试异常";
  5982. Delay_ms(500);
  5983. //存储异常并上传
  5984. FacMode_Stop(false);
  5985. return;
  5986. }
  5987. //MOS内阻校准
  5988. if (checkBox_FacMode_MosCal.Checked)
  5989. {
  5990. label_FacModeStatus.Text = "MOS内阻校准";
  5991. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  5992. Delay_ms(500);
  5993. //提示进行负载切换
  5994. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  5995. {
  5996. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  5997. label_FacModeStatus.Text = "存在故障!";
  5998. label_FacModeResult.BackColor = Color.Red;
  5999. label_FacModeResult.Text = "测试异常";
  6000. Delay_ms(500);
  6001. //存储异常并上传
  6002. FacMode_Stop(false);
  6003. return;
  6004. }
  6005. //确认后发送校准指令
  6006. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6007. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6008. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6009. ushort uwDataTemp = 0;
  6010. uwDataTemp = Convert.ToUInt16(K[0]);
  6011. Code[2] = (byte)(uwDataTemp & 0xFF);
  6012. Code[3] = (byte)(uwDataTemp >> 8);
  6013. uwDataTemp = Convert.ToUInt16(K[1]);
  6014. Code[4] = (byte)(uwDataTemp & 0xFF);
  6015. Code[5] = (byte)(uwDataTemp >> 8);
  6016. uwDataTemp = Convert.ToUInt16(K[2]);
  6017. Code[6] = (byte)(uwDataTemp & 0xFF);
  6018. Code[7] = (byte)(uwDataTemp >> 8);
  6019. uwDataTemp = Convert.ToUInt16(K[3]);
  6020. Code[8] = (byte)(uwDataTemp & 0xFF);
  6021. Code[9] = (byte)(uwDataTemp >> 8);
  6022. uwDataTemp = Convert.ToUInt16(K[4]);
  6023. Code[10] = (byte)(uwDataTemp & 0xFF);
  6024. Code[11] = (byte)(uwDataTemp >> 8);
  6025. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6026. WriteACK = false;
  6027. ACK_WaitCnt = 0;
  6028. while (ACK_WaitCnt <= 6) ; //3s
  6029. if (WriteACK == true)
  6030. {
  6031. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6032. }
  6033. else
  6034. {
  6035. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6036. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6037. ACK_WaitCnt = 0;
  6038. while (ACK_WaitCnt <= 6) ; //3s
  6039. if (WriteACK == true)
  6040. {
  6041. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6042. }
  6043. else
  6044. {
  6045. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6046. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6047. ACK_WaitCnt = 0;
  6048. while (ACK_WaitCnt <= 6) ; //3s
  6049. if (WriteACK == true)
  6050. {
  6051. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6052. }
  6053. else
  6054. {
  6055. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6056. label_FacModeStatus.Text = "存在故障!";
  6057. label_FacModeResult.BackColor = Color.Red;
  6058. label_FacModeResult.Text = "测试异常";
  6059. Delay_ms(500);
  6060. //存储异常并上传
  6061. FacMode_Stop(false);
  6062. return;
  6063. }
  6064. }
  6065. }
  6066. #if false
  6067. //因控制器复位需发送指令重新进入5S协议
  6068. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6069. {
  6070. Code[0] = 0x00;//5S协议
  6071. Code[1] = 0x00;
  6072. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6073. Delay_ms(500);
  6074. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6075. Delay_ms(500);
  6076. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6077. }
  6078. #endif
  6079. //读取显示校准返回数据
  6080. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  6081. foreach (Control c in groupBox21.Controls)
  6082. {
  6083. if (c is TextBox)
  6084. c.Text = "";
  6085. }
  6086. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6087. ACK_WaitCnt = 0;
  6088. while (ACK_WaitCnt <= 2) ; //1s
  6089. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6090. {
  6091. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  6092. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6093. ACK_WaitCnt = 0;
  6094. while (ACK_WaitCnt <= 2) ; //1s
  6095. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6096. {
  6097. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  6098. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6099. ACK_WaitCnt = 0;
  6100. while (ACK_WaitCnt <= 2) ; //1s
  6101. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6102. {
  6103. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6104. label_FacModeStatus.Text = "存在故障!";
  6105. label_FacModeResult.BackColor = Color.Red;
  6106. label_FacModeResult.Text = "测试异常";
  6107. Delay_ms(500);
  6108. //存储异常并上传
  6109. FacMode_Stop(false);
  6110. return;
  6111. }
  6112. }
  6113. }
  6114. else
  6115. {
  6116. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  6117. }
  6118. //与校准返回数据对比
  6119. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6120. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6121. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6122. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  6123. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6124. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6125. )
  6126. {
  6127. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6128. label_FacModeMosCal.BackColor = Color.Green;
  6129. //提示切换负载
  6130. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6131. }
  6132. else
  6133. {
  6134. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6135. label_FacModeStatus.Text = "存在故障!";
  6136. label_FacModeResult.BackColor = Color.Red;
  6137. label_FacModeResult.Text = "测试异常";
  6138. Delay_ms(500);
  6139. //存储异常并上传
  6140. FacMode_Stop(false);
  6141. //提示切换负载
  6142. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6143. return;
  6144. }
  6145. }
  6146. else
  6147. {
  6148. label_FacModeMosCal.BackColor = Color.Yellow;
  6149. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6150. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6151. Delay_ms(500);
  6152. }
  6153. //位置校准
  6154. if (checkBox_FacMode_AngleCal.Checked)
  6155. {
  6156. //校准前进行一次开关机保存初始化数据
  6157. BootInfo = "";
  6158. label_FacModeStatus.Text = "位置校准";
  6159. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6160. //确保测试前先关机,发送关机指令再发送开机指令
  6161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6162. Code[0] = 0xF0;
  6163. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6164. Delay_ms(1500);
  6165. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6166. Code[0] = 0xF1;
  6167. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6168. ACK_WaitCnt = 0;
  6169. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6170. while (ACK_WaitCnt <= 10) ; //5s
  6171. //获取Boot版本信息
  6172. if (BootInfo != string.Empty)
  6173. {
  6174. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6175. Delay_ms(500);
  6176. }
  6177. else
  6178. {
  6179. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6180. label_FacModeStatus.Text = "存在故障!";
  6181. label_FacModeResult.BackColor = Color.Red;
  6182. label_FacModeResult.Text = "测试异常";
  6183. Delay_ms(500);
  6184. //存储异常并上传
  6185. FacMode_Stop(false);
  6186. return;
  6187. }
  6188. //发送位置校准指令
  6189. for (int i = 0; i < 7; i++)
  6190. for (int j = 0; j < 6; j++)
  6191. {
  6192. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6193. }
  6194. foreach (Control cr in tabPage_AngleCal.Controls)
  6195. {
  6196. if (cr is TextBox)
  6197. {
  6198. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6199. cr.Text = "";
  6200. }
  6201. }
  6202. Code[0] = 0;
  6203. Code[1] = 0;
  6204. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6205. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6206. ACK_WaitCnt = 0;
  6207. while (ACK_WaitCnt <= 50) ; //25s
  6208. //读取位置校准数据
  6209. if (textBox_AngleDiffAvg.Text == string.Empty)
  6210. {
  6211. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6212. label_FacModeStatus.Text = "存在故障!";
  6213. label_FacModeResult.BackColor = Color.Red;
  6214. label_FacModeResult.Text = "测试异常";
  6215. Delay_ms(500);
  6216. //存储异常并上传
  6217. FacMode_Stop(false);
  6218. return;
  6219. }
  6220. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6221. for (int i = 0; i < 7; i++)
  6222. {
  6223. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6224. for (int j = 0; j < 6; j++)
  6225. {
  6226. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6227. }
  6228. richTextBox_FacModeLog.AppendText("\r\n");
  6229. Delay_ms(200);
  6230. }
  6231. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6232. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6233. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6234. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6235. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6236. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6237. //比较位置偏差
  6238. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6239. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6240. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6241. )
  6242. {
  6243. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6244. label_FacModeStatus.Text = "存在故障!";
  6245. label_FacModeResult.BackColor = Color.Red;
  6246. label_FacModeResult.Text = "测试异常";
  6247. Delay_ms(500);
  6248. //存储异常并上传
  6249. FacMode_Stop(false);
  6250. return;
  6251. }
  6252. //写入校准偏差值
  6253. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6254. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6255. if (data1 > 360)
  6256. {
  6257. data1 -= 360;
  6258. }
  6259. else if (data1 < -360)
  6260. {
  6261. data1 += 360;
  6262. }
  6263. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6264. Code[0] = 0x01;
  6265. Code[1] = 0x00;
  6266. Code[2] = (byte)(data2);
  6267. Code[3] = (byte)(data2 >> 8);
  6268. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6269. WriteACK = false;
  6270. ACK_WaitCnt = 0;
  6271. while (ACK_WaitCnt <= 2) ; //1s
  6272. if (WriteACK == true)
  6273. {
  6274. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6275. }
  6276. else
  6277. {
  6278. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6279. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6280. WriteACK = false;
  6281. ACK_WaitCnt = 0;
  6282. while (ACK_WaitCnt <= 2) ; //1s
  6283. if (WriteACK == true)
  6284. {
  6285. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6286. }
  6287. else
  6288. {
  6289. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6290. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6291. WriteACK = false;
  6292. ACK_WaitCnt = 0;
  6293. while (ACK_WaitCnt <= 2) ; //1s
  6294. if (WriteACK == true)
  6295. {
  6296. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6297. }
  6298. else
  6299. {
  6300. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6301. label_FacModeStatus.Text = "存在故障!";
  6302. label_FacModeResult.BackColor = Color.Red;
  6303. label_FacModeResult.Text = "测试异常";
  6304. Delay_ms(500);
  6305. //存储异常并上传
  6306. FacMode_Stop(false);
  6307. return;
  6308. }
  6309. }
  6310. }
  6311. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6312. label_FacModeAngleCal.BackColor = Color.Green;
  6313. }
  6314. else
  6315. {
  6316. label_FacModeAngleCal.BackColor = Color.Yellow;
  6317. label_FacModeStatus.Text = "跳过位置校准!";
  6318. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6319. Delay_ms(500);
  6320. }
  6321. //参数写入
  6322. if (checkBox_FacModeCfgWrite.Checked)
  6323. {
  6324. label_FacModeStatus.Text = "参数写入";
  6325. //写入产品型号和SN
  6326. do
  6327. {
  6328. //根据扫码信息获取型号和SN
  6329. string ScanInfo = textBox_FacModeScan.Text;
  6330. string regexInfo = "";
  6331. string[] InfoList = { "" };
  6332. try
  6333. {
  6334. if (中置电机ToolStripMenuItem.Checked == true)
  6335. {
  6336. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6337. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6338. }
  6339. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6340. {
  6341. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6342. string Model = InfoList[0];
  6343. string Spec = InfoList[1];
  6344. string Sn = InfoList[2];
  6345. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6346. InfoList[1] = Sn;
  6347. }
  6348. }
  6349. catch
  6350. {
  6351. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6352. label_FacModeStatus.Text = "存在故障!";
  6353. label_FacModeResult.BackColor = Color.Red;
  6354. label_FacModeResult.Text = "标签格式错误";
  6355. Delay_ms(500);
  6356. //存储异常并上传
  6357. FacMode_Stop(false);
  6358. return;
  6359. }
  6360. if (InfoList.Length >= 2)
  6361. {
  6362. //检查配置文件是否与打标信息一致
  6363. //...
  6364. //写入型号
  6365. label_FacModeStatus.Text = "写入型号";
  6366. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6367. textBox_FacModeName.Text = InfoList[0];
  6368. string Mode = textBox_FacModeName.Text;
  6369. var ModeArray = new byte[16];
  6370. for (ushort i = 0; i < Mode.Length; i++)
  6371. {
  6372. ModeArray[i] = (byte)Mode[i];
  6373. }
  6374. if (Mode.Length < 16)
  6375. {
  6376. ModeArray[Mode.Length] = (byte)'.';
  6377. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6378. {
  6379. ModeArray[Mode.Length + 1 + i] = 0x20;
  6380. }
  6381. }
  6382. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6383. WriteACK = false;
  6384. ACK_WaitCnt = 0;
  6385. while (ACK_WaitCnt <= 2); //1s
  6386. if (WriteACK == true)
  6387. {
  6388. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6389. }
  6390. else
  6391. {
  6392. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6393. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6394. ACK_WaitCnt = 0;
  6395. while (ACK_WaitCnt <= 2) ; //1s
  6396. if (WriteACK == true)
  6397. {
  6398. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6399. }
  6400. else
  6401. {
  6402. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6403. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6404. ACK_WaitCnt = 0;
  6405. while (ACK_WaitCnt <= 2) ; //1s
  6406. if (WriteACK == true)
  6407. {
  6408. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6409. }
  6410. else
  6411. {
  6412. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6413. label_FacModeStatus.Text = "存在故障!";
  6414. label_FacModeResult.BackColor = Color.Red;
  6415. label_FacModeResult.Text = "测试异常";
  6416. Delay_ms(500);
  6417. //存储异常并上传
  6418. FacMode_Stop(false);
  6419. return;
  6420. }
  6421. }
  6422. }
  6423. //写入SN
  6424. label_FacModeStatus.Text = "写入SN";
  6425. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6426. textBox_FacModeNum.Text = InfoList[1];
  6427. string SN = textBox_FacModeNum.Text;
  6428. var SNArray = new byte[16];
  6429. for (ushort i = 0; i < SN.Length; i++)
  6430. {
  6431. SNArray[i] = (byte)SN[i];
  6432. }
  6433. if (SN.Length < 16)
  6434. {
  6435. SNArray[SN.Length] = (byte)'.';
  6436. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6437. {
  6438. SNArray[SN.Length + 1 + i] = 0x20;
  6439. }
  6440. }
  6441. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6442. WriteACK = false;
  6443. ACK_WaitCnt = 0;
  6444. while (ACK_WaitCnt <= 2); //1s
  6445. if (WriteACK == true)
  6446. {
  6447. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6448. }
  6449. else
  6450. {
  6451. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6452. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6453. ACK_WaitCnt = 0;
  6454. while (ACK_WaitCnt <= 2) ; //1s
  6455. if (WriteACK == true)
  6456. {
  6457. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6458. }
  6459. else
  6460. {
  6461. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6462. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6463. ACK_WaitCnt = 0;
  6464. while (ACK_WaitCnt <= 2) ; //1s
  6465. if (WriteACK == true)
  6466. {
  6467. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6468. }
  6469. else
  6470. {
  6471. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6472. label_FacModeStatus.Text = "存在故障!";
  6473. label_FacModeResult.BackColor = Color.Red;
  6474. label_FacModeResult.Text = "测试异常";
  6475. Delay_ms(500);
  6476. //存储异常并上传
  6477. FacMode_Stop(false);
  6478. return;
  6479. }
  6480. }
  6481. }
  6482. }
  6483. else
  6484. {
  6485. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6486. return;
  6487. }
  6488. } while (false);
  6489. //写入配置文件
  6490. do
  6491. {
  6492. label_FacModeStatus.Text = "写入配置文件";
  6493. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6494. //配置文件
  6495. List<byte[]> CmdList = new List<byte[]>();
  6496. //从服务器下载文件
  6497. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6498. {
  6499. string SelectFile = "";
  6500. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6501. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6502. {
  6503. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6504. }
  6505. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6506. //打开文件
  6507. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6508. CmdList.Clear();
  6509. while (streamReader.Peek() != -1)
  6510. {
  6511. string fileLineInfo = streamReader.ReadLine();
  6512. if (fileLineInfo.IndexOf("[") != -1)
  6513. {
  6514. continue;
  6515. }
  6516. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6517. }
  6518. streamReader.Close();
  6519. }
  6520. //加载本地文件
  6521. else
  6522. {
  6523. string SelectFile = "";
  6524. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6525. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6526. CmdList.Clear();
  6527. while (streamReader.Peek() != -1)
  6528. {
  6529. string fileLineInfo = streamReader.ReadLine();
  6530. if (fileLineInfo.IndexOf("[") != -1)
  6531. {
  6532. continue;
  6533. }
  6534. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6535. }
  6536. streamReader.Close();
  6537. }
  6538. int CmdNum = CmdList.Count(); //指令个数
  6539. Delay_ms(500);
  6540. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6541. Delay_ms(500);
  6542. //开始写入
  6543. for (int i = 0; i < CmdList.Count; i++)
  6544. {
  6545. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6546. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6547. WriteACK = false;
  6548. ACK_WaitCnt = 0;
  6549. while (ACK_WaitCnt <= 2) ; //1s
  6550. if (WriteACK == true)
  6551. {
  6552. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6553. }
  6554. else
  6555. {
  6556. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6557. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6558. WriteACK = false;
  6559. ACK_WaitCnt = 0;
  6560. while (ACK_WaitCnt <= 2) ; //1s
  6561. if (WriteACK == true)
  6562. {
  6563. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6564. }
  6565. else
  6566. {
  6567. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6568. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6569. WriteACK = false;
  6570. ACK_WaitCnt = 0;
  6571. while (ACK_WaitCnt <= 2) ; //1s
  6572. if (WriteACK == true)
  6573. {
  6574. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6575. }
  6576. else
  6577. {
  6578. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6579. label_FacModeStatus.Text = "存在故障!";
  6580. label_FacModeResult.BackColor = Color.Red;
  6581. label_FacModeResult.Text = "测试异常";
  6582. Delay_ms(500);
  6583. //存储异常并上传
  6584. FacMode_Stop(false);
  6585. return;
  6586. }
  6587. }
  6588. }
  6589. }
  6590. //写入完成
  6591. label_FacMode_CfgWrite.BackColor = Color.Green;
  6592. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6593. Delay_ms(500);
  6594. } while (false);
  6595. }
  6596. else
  6597. {
  6598. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6599. label_FacModeStatus.Text = "跳过参数写入!";
  6600. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6601. Delay_ms(500);
  6602. }
  6603. //BMS通讯
  6604. if (checkBox_FacModeBMS.Checked)
  6605. {
  6606. if (label_FacModeBMS.BackColor == Color.Red)
  6607. {
  6608. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6609. label_FacModeStatus.Text = "存在故障!";
  6610. label_FacModeResult.BackColor = Color.Red;
  6611. label_FacModeResult.Text = "测试异常";
  6612. Delay_ms(500);
  6613. //存储异常并上传
  6614. FacMode_Stop(false);
  6615. return;
  6616. }
  6617. }
  6618. else
  6619. {
  6620. label_FacModeBMS.BackColor = Color.Yellow;
  6621. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6622. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6623. Delay_ms(500);
  6624. }
  6625. //基础功能检测
  6626. if (checkBox_FacBaseFucTest.Checked)
  6627. {
  6628. label_FacModeStatus.Text = "基础功能检测";
  6629. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6630. //确认负载位置
  6631. if (checkBox_FacMode_MosCal.Checked)
  6632. {
  6633. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6634. {
  6635. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6636. }
  6637. else
  6638. {
  6639. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6640. label_FacModeStatus.Text = "存在故障!";
  6641. label_FacModeResult.BackColor = Color.Red;
  6642. label_FacModeResult.Text = "测试异常";
  6643. Delay_ms(500);
  6644. //存储异常并上传
  6645. FacMode_Stop(false);
  6646. return;
  6647. }
  6648. }
  6649. //发送指令进入配置模式
  6650. do
  6651. {
  6652. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6653. Code[0] = 0x01;
  6654. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6655. WriteACK = false;
  6656. ACK_WaitCnt = 0;
  6657. while (ACK_WaitCnt <= 2); //1s
  6658. if (textBox_RunInfo_Vol.Text != "---")
  6659. {
  6660. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6661. }
  6662. else
  6663. {
  6664. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6665. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6666. ACK_WaitCnt = 0;
  6667. while (ACK_WaitCnt <= 2) ; //1s
  6668. if (textBox_RunInfo_Vol.Text != "---")
  6669. {
  6670. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6671. }
  6672. else
  6673. {
  6674. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6675. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6676. ACK_WaitCnt = 0;
  6677. while (ACK_WaitCnt <= 2) ; //1s
  6678. if (textBox_RunInfo_Vol.Text != "---")
  6679. {
  6680. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6681. }
  6682. else
  6683. {
  6684. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6685. label_FacModeStatus.Text = "存在故障!";
  6686. label_FacModeResult.BackColor = Color.Red;
  6687. label_FacModeResult.Text = "测试异常";
  6688. Delay_ms(500);
  6689. //存储异常并上传
  6690. FacMode_Stop(false);
  6691. return;
  6692. }
  6693. }
  6694. }
  6695. } while (false);
  6696. //发送指令启动电机
  6697. do
  6698. {
  6699. #if false //通过运行模式3启动电机
  6700. //发送指令读取调试信息
  6701. richTextBox_DebugParam.Clear();
  6702. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6703. WriteACK = false;
  6704. ACK_WaitCnt = 0;
  6705. while (ACK_WaitCnt <= 2); //1s
  6706. //获取调试信息
  6707. string DebugDefaultInfo = "";
  6708. if (richTextBox_DebugParam.Text == string.Empty)
  6709. {
  6710. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6711. label_FacModeStatus.Text = "存在故障!";
  6712. label_FacModeResult.BackColor = Color.Red;
  6713. label_FacModeResult.Text = "测试异常";
  6714. Delay_ms(500);
  6715. //存储异常并上传
  6716. FacMode_Stop(false);
  6717. return;
  6718. }
  6719. else
  6720. {
  6721. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6722. }
  6723. //设置模式
  6724. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6725. strDataTemp[0] = "整体运行模式=3";
  6726. //发送数据
  6727. Code[0] = 0;
  6728. Code[1] = 0;
  6729. for (int i = 0; i < strDataTemp.Length; i++)
  6730. {
  6731. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6732. Code[2 * i + 2] = (byte)uwDataTemp;
  6733. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6734. }
  6735. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6736. label_FacModeStatus.Text = "启动电机";
  6737. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6738. #else //通过Walk模式启动电机
  6739. //设置转速100%
  6740. var Data = new byte[1];
  6741. Data[0] = (byte)100;
  6742. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6743. Delay_ms(500);
  6744. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6745. Delay_ms(500);
  6746. //启动电机进入WALK模式
  6747. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6748. Code[0] = 0x22;
  6749. Code[1] = 0xF0;
  6750. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6751. WriteACK = false;
  6752. ACK_WaitCnt = 0;
  6753. while (ACK_WaitCnt <= 2) ; //1s
  6754. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6755. {
  6756. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6757. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6758. ACK_WaitCnt = 0;
  6759. while (ACK_WaitCnt <= 2) ; //1s
  6760. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6761. {
  6762. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6763. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6764. ACK_WaitCnt = 0;
  6765. while (ACK_WaitCnt <= 2) ; //1s
  6766. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6767. {
  6768. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6769. label_FacModeStatus.Text = "存在故障!";
  6770. label_FacModeResult.BackColor = Color.Red;
  6771. label_FacModeResult.Text = "测试异常";
  6772. Delay_ms(500);
  6773. //存储异常并上传
  6774. FacMode_Stop(false);
  6775. return;
  6776. }
  6777. }
  6778. }
  6779. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6780. #endif
  6781. Delay_ms(3000);
  6782. } while (false);
  6783. //判断车速
  6784. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6785. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6786. {
  6787. label_FacModeSpeed.BackColor = Color.Green;
  6788. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6789. }
  6790. else
  6791. {
  6792. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6793. label_FacModeStatus.Text = "存在故障!";
  6794. label_FacModeResult.BackColor = Color.Red;
  6795. label_FacModeResult.Text = "测试异常";
  6796. Delay_ms(500);
  6797. //存储异常并上传
  6798. FacMode_Stop(false);
  6799. return;
  6800. }
  6801. //判断电压
  6802. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6803. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6804. {
  6805. label_FacModeVolTest.BackColor = Color.Green;
  6806. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6807. }
  6808. else
  6809. {
  6810. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6811. label_FacModeStatus.Text = "存在故障!";
  6812. label_FacModeResult.BackColor = Color.Red;
  6813. label_FacModeResult.Text = "测试异常";
  6814. Delay_ms(500);
  6815. //存储异常并上传
  6816. FacMode_Stop(false);
  6817. return;
  6818. }
  6819. //判断电流
  6820. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6821. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6822. {
  6823. label_FacModeCurrentTest.BackColor = Color.Green;
  6824. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6825. }
  6826. else
  6827. {
  6828. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6829. label_FacModeStatus.Text = "存在故障!";
  6830. label_FacModeResult.BackColor = Color.Red;
  6831. label_FacModeResult.Text = "测试异常";
  6832. Delay_ms(500);
  6833. //存储异常并上传
  6834. FacMode_Stop(false);
  6835. return;
  6836. }
  6837. //判断温度
  6838. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6839. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6840. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6841. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6842. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6843. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6844. {
  6845. label_FacModeNTC.BackColor = Color.Green;
  6846. 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");
  6847. }
  6848. else
  6849. {
  6850. 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");
  6851. label_FacModeStatus.Text = "存在故障!";
  6852. label_FacModeResult.BackColor = Color.Red;
  6853. label_FacModeResult.Text = "测试异常";
  6854. Delay_ms(500);
  6855. //存储异常并上传
  6856. FacMode_Stop(false);
  6857. return;
  6858. }
  6859. //判断转速
  6860. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6861. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6862. {
  6863. label_FacModeMotorSpeed.BackColor = Color.Green;
  6864. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6865. }
  6866. else
  6867. {
  6868. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6869. label_FacModeStatus.Text = "存在故障!";
  6870. label_FacModeResult.BackColor = Color.Red;
  6871. label_FacModeResult.Text = "测试异常";
  6872. Delay_ms(500);
  6873. //存储异常并上传
  6874. FacMode_Stop(false);
  6875. return;
  6876. }
  6877. //发送指令停止电机
  6878. do
  6879. {
  6880. //设置转速0%
  6881. var Data = new byte[1];
  6882. Data[0] = (byte)0;
  6883. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6884. Delay_ms(500);
  6885. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6886. Delay_ms(500);
  6887. #if false //通过修改调试模式停止电机
  6888. //获取调试信息
  6889. string DebugDefaultInfo = "";
  6890. if (richTextBox_DebugParam.Text == string.Empty)
  6891. {
  6892. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6893. label_FacModeStatus.Text = "存在故障!";
  6894. label_FacModeResult.BackColor = Color.Red;
  6895. label_FacModeResult.Text = "测试异常";
  6896. Delay_ms(500);
  6897. //存储异常并上传
  6898. FacMode_Stop(false);
  6899. return;
  6900. }
  6901. else
  6902. {
  6903. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6904. }
  6905. //设置模式
  6906. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6907. //发送数据
  6908. Code[0] = 0;
  6909. Code[1] = 0;
  6910. for (int i = 0; i < strDataTemp.Length; i++)
  6911. {
  6912. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6913. Code[2 * i + 2] = (byte)uwDataTemp;
  6914. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6915. }
  6916. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6917. label_FacModeStatus.Text = "停止电机";
  6918. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6919. #else //通过调整档位停止电机
  6920. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6921. Code[0] = 0x00;
  6922. Code[1] = 0xF0;
  6923. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6924. WriteACK = false;
  6925. ACK_WaitCnt = 0;
  6926. while (ACK_WaitCnt <= 2) ; //1s
  6927. if (textBox_RunInfo_GearSt.Text != "OFF")
  6928. {
  6929. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  6930. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6931. ACK_WaitCnt = 0;
  6932. while (ACK_WaitCnt <= 2) ; //1s
  6933. if (textBox_RunInfo_GearSt.Text != "OFF")
  6934. {
  6935. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  6936. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6937. ACK_WaitCnt = 0;
  6938. while (ACK_WaitCnt <= 2) ; //1s
  6939. if (textBox_RunInfo_GearSt.Text != "OFF")
  6940. {
  6941. }
  6942. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6943. label_FacModeStatus.Text = "存在故障!";
  6944. label_FacModeResult.BackColor = Color.Red;
  6945. label_FacModeResult.Text = "测试异常";
  6946. Delay_ms(500);
  6947. //存储异常并上传
  6948. FacMode_Stop(false);
  6949. return;
  6950. }
  6951. }
  6952. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6953. #endif
  6954. Delay_ms(2000);
  6955. } while (false);
  6956. }
  6957. else
  6958. {
  6959. label_FacModeSpeed.BackColor = Color.Yellow;
  6960. label_FacModeVolTest.BackColor = Color.Yellow;
  6961. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6962. label_FacModeNTC.BackColor = Color.Yellow;
  6963. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6964. label_FacModeStatus.Text = "跳过基础功能检测!";
  6965. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6966. Delay_ms(500);
  6967. }
  6968. //力矩检测
  6969. if (checkBox_FacTor.Checked)
  6970. {
  6971. label_FacModeStatus.Text = "力矩传感器检测!";
  6972. //发送指令进入配置模式
  6973. do
  6974. {
  6975. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6976. {
  6977. break;
  6978. }
  6979. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6980. Code[0] = 0x01;
  6981. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6982. WriteACK = false;
  6983. ACK_WaitCnt = 0;
  6984. while (ACK_WaitCnt <= 2) ; //1s
  6985. if (textBox_RunInfo_Vol.Text != "---")
  6986. {
  6987. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6988. Delay_ms(500);
  6989. }
  6990. else
  6991. {
  6992. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6993. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6994. ACK_WaitCnt = 0;
  6995. while (ACK_WaitCnt <= 2) ; //1s
  6996. if (textBox_RunInfo_Vol.Text != "---")
  6997. {
  6998. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6999. Delay_ms(500);
  7000. }
  7001. else
  7002. {
  7003. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7004. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7005. ACK_WaitCnt = 0;
  7006. while (ACK_WaitCnt <= 2) ; //1s
  7007. if (textBox_RunInfo_Vol.Text != "---")
  7008. {
  7009. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7010. Delay_ms(500);
  7011. }
  7012. else
  7013. {
  7014. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7015. label_FacModeStatus.Text = "存在故障!";
  7016. label_FacModeResult.BackColor = Color.Red;
  7017. label_FacModeResult.Text = "测试异常";
  7018. Delay_ms(500);
  7019. //存储异常并上传
  7020. FacMode_Stop(false);
  7021. return;
  7022. }
  7023. }
  7024. }
  7025. } while (false);
  7026. ushort Max = 0, Torque = 0;
  7027. //提示输入力矩信号
  7028. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  7029. ACK_WaitCnt = 0;
  7030. while (ACK_WaitCnt <= 20) //10s
  7031. {
  7032. //获取力矩值
  7033. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  7034. if (Torque > Max)
  7035. Max = Torque;
  7036. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  7037. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  7038. (ACK_WaitCnt >= 6))
  7039. {
  7040. label_FacModeTq.BackColor = Color.Green;
  7041. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7042. break;
  7043. }
  7044. }
  7045. if (ACK_WaitCnt >= 20)
  7046. {
  7047. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7048. label_FacModeStatus.Text = "存在故障!";
  7049. label_FacModeResult.BackColor = Color.Red;
  7050. label_FacModeResult.Text = "测试异常";
  7051. Delay_ms(500);
  7052. //存储异常并上传
  7053. FacMode_Stop(false);
  7054. return;
  7055. }
  7056. }
  7057. else
  7058. {
  7059. label_FacModeTq.BackColor = Color.Yellow;
  7060. label_FacModeStatus.Text = "跳过力矩检测!";
  7061. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  7062. Delay_ms(500);
  7063. }
  7064. //踏频检测
  7065. if (checkBox_FacCad.Checked)
  7066. {
  7067. label_FacModeStatus.Text = "踏频传感器检测!";
  7068. //发送指令进入配置模式
  7069. do
  7070. {
  7071. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7072. {
  7073. break;
  7074. }
  7075. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7076. Code[0] = 0x01;
  7077. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7078. WriteACK = false;
  7079. ACK_WaitCnt = 0;
  7080. while (ACK_WaitCnt <= 2) ; //1s
  7081. if (textBox_RunInfo_Vol.Text != "---")
  7082. {
  7083. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7084. Delay_ms(500);
  7085. }
  7086. else
  7087. {
  7088. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7089. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7090. ACK_WaitCnt = 0;
  7091. while (ACK_WaitCnt <= 2) ; //1s
  7092. if (textBox_RunInfo_Vol.Text != "---")
  7093. {
  7094. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7095. Delay_ms(500);
  7096. }
  7097. else
  7098. {
  7099. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7100. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7101. ACK_WaitCnt = 0;
  7102. while (ACK_WaitCnt <= 2) ; //1s
  7103. if (textBox_RunInfo_Vol.Text != "---")
  7104. {
  7105. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7106. Delay_ms(500);
  7107. }
  7108. else
  7109. {
  7110. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7111. label_FacModeStatus.Text = "存在故障!";
  7112. label_FacModeResult.BackColor = Color.Red;
  7113. label_FacModeResult.Text = "测试异常";
  7114. Delay_ms(500);
  7115. //存储异常并上传
  7116. FacMode_Stop(false);
  7117. return;
  7118. }
  7119. }
  7120. }
  7121. } while (false);
  7122. ushort Max = 0, Cadence = 0;
  7123. //提示输入踏频信号
  7124. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7125. ACK_WaitCnt = 0;
  7126. while (ACK_WaitCnt <= 20) //10s
  7127. {
  7128. //获取踏频
  7129. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7130. if (Cadence > Max)
  7131. Max = Cadence;
  7132. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7133. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7134. (ACK_WaitCnt >= 6))
  7135. {
  7136. label_FacModeCad.BackColor = Color.Green;
  7137. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7138. break;
  7139. }
  7140. }
  7141. if (ACK_WaitCnt >= 20)
  7142. {
  7143. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7144. label_FacModeStatus.Text = "存在故障!";
  7145. label_FacModeResult.BackColor = Color.Red;
  7146. label_FacModeResult.Text = "测试异常";
  7147. Delay_ms(500);
  7148. //存储异常并上传
  7149. FacMode_Stop(false);
  7150. return;
  7151. }
  7152. }
  7153. else
  7154. {
  7155. label_FacModeCad.BackColor = Color.Yellow;
  7156. label_FacModeStatus.Text = "跳过踏频检测!";
  7157. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7158. Delay_ms(500);
  7159. }
  7160. //转把检测
  7161. if (checkBox_FacThrrotleTest.Checked)
  7162. {
  7163. label_FacModeStatus.Text = "转把检测";
  7164. //发送指令进入配置模式
  7165. do
  7166. {
  7167. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7168. {
  7169. break;
  7170. }
  7171. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7172. Code[0] = 0x01;
  7173. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7174. WriteACK = false;
  7175. ACK_WaitCnt = 0;
  7176. while (ACK_WaitCnt <= 2) ; //1s
  7177. if (textBox_RunInfo_Vol.Text != "---")
  7178. {
  7179. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7180. Delay_ms(500);
  7181. }
  7182. else
  7183. {
  7184. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7185. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7186. ACK_WaitCnt = 0;
  7187. while (ACK_WaitCnt <= 2) ; //1s
  7188. if (textBox_RunInfo_Vol.Text != "---")
  7189. {
  7190. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7191. Delay_ms(500);
  7192. }
  7193. else
  7194. {
  7195. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7196. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7197. ACK_WaitCnt = 0;
  7198. while (ACK_WaitCnt <= 2) ; //1s
  7199. if (textBox_RunInfo_Vol.Text != "---")
  7200. {
  7201. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7202. Delay_ms(500);
  7203. }
  7204. else
  7205. {
  7206. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7207. label_FacModeStatus.Text = "存在故障!";
  7208. label_FacModeResult.BackColor = Color.Red;
  7209. label_FacModeResult.Text = "测试异常";
  7210. Delay_ms(500);
  7211. //存储异常并上传
  7212. FacMode_Stop(false);
  7213. return;
  7214. }
  7215. }
  7216. }
  7217. } while (false);
  7218. //进入TURBO档
  7219. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7220. Code[0] = 0x04;
  7221. Code[1] = 0xF0;
  7222. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7223. WriteACK = false;
  7224. ACK_WaitCnt = 0;
  7225. while (ACK_WaitCnt <= 2) ; //1s
  7226. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7227. {
  7228. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7229. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7230. ACK_WaitCnt = 0;
  7231. while (ACK_WaitCnt <= 2) ; //1s
  7232. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7233. {
  7234. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7235. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7236. ACK_WaitCnt = 0;
  7237. while (ACK_WaitCnt <= 2) ; //1s
  7238. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7239. {
  7240. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7241. label_FacModeStatus.Text = "存在故障!";
  7242. label_FacModeResult.BackColor = Color.Red;
  7243. label_FacModeResult.Text = "测试异常";
  7244. Delay_ms(500);
  7245. //存储异常并上传
  7246. FacMode_Stop(false);
  7247. return;
  7248. }
  7249. }
  7250. }
  7251. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7252. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7253. Delay_ms(3000);
  7254. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7255. {
  7256. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7257. label_FacModeStatus.Text = "存在故障!";
  7258. label_FacModeResult.BackColor = Color.Red;
  7259. label_FacModeResult.Text = "测试异常";
  7260. Delay_ms(500);
  7261. //存储异常并上传
  7262. FacMode_Stop(false);
  7263. return;
  7264. }
  7265. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7266. Delay_ms(500);
  7267. //提示转动转把
  7268. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7269. ACK_WaitCnt = 0;
  7270. while (ACK_WaitCnt <= 20)
  7271. {
  7272. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7273. {
  7274. label_FacModeGas.BackColor = Color.Green;
  7275. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7276. break;
  7277. }
  7278. }
  7279. if (ACK_WaitCnt >= 20) //转把超时
  7280. {
  7281. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7282. label_FacModeStatus.Text = "存在故障!";
  7283. label_FacModeResult.BackColor = Color.Red;
  7284. label_FacModeResult.Text = "测试异常";
  7285. Delay_ms(500);
  7286. //存储异常并上传
  7287. FacMode_Stop(false);
  7288. return;
  7289. }
  7290. }
  7291. else
  7292. {
  7293. label_FacModeGas.BackColor = Color.Yellow;
  7294. label_FacModeStatus.Text = "跳过转把检测!";
  7295. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7296. Delay_ms(500);
  7297. }
  7298. //刹车检测
  7299. if (checkBox_FacBreakTest.Checked)
  7300. {
  7301. label_FacModeStatus.Text = "刹把检测";
  7302. //发送指令进入配置模式
  7303. do
  7304. {
  7305. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7306. {
  7307. break;
  7308. }
  7309. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7310. Code[0] = 0x01;
  7311. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7312. WriteACK = false;
  7313. ACK_WaitCnt = 0;
  7314. while (ACK_WaitCnt <= 2) ; //1s
  7315. if (textBox_RunInfo_Vol.Text != "---")
  7316. {
  7317. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7318. Delay_ms(500);
  7319. }
  7320. else
  7321. {
  7322. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7323. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7324. ACK_WaitCnt = 0;
  7325. while (ACK_WaitCnt <= 2) ; //1s
  7326. if (textBox_RunInfo_Vol.Text != "---")
  7327. {
  7328. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7329. Delay_ms(500);
  7330. }
  7331. else
  7332. {
  7333. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7334. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7335. ACK_WaitCnt = 0;
  7336. while (ACK_WaitCnt <= 2) ; //1s
  7337. if (textBox_RunInfo_Vol.Text != "---")
  7338. {
  7339. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7340. Delay_ms(500);
  7341. }
  7342. else
  7343. {
  7344. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7345. label_FacModeStatus.Text = "存在故障!";
  7346. label_FacModeResult.BackColor = Color.Red;
  7347. label_FacModeResult.Text = "测试异常";
  7348. Delay_ms(500);
  7349. //存储异常并上传
  7350. FacMode_Stop(false);
  7351. return;
  7352. }
  7353. }
  7354. }
  7355. } while (false);
  7356. //测试前先确定电机已停止
  7357. UInt16 WaitTime = 10;
  7358. do
  7359. {
  7360. WaitTime--;
  7361. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7362. {
  7363. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7364. break;
  7365. }
  7366. if (WaitTime == 0)
  7367. {
  7368. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7369. label_FacModeStatus.Text = "存在故障!";
  7370. label_FacModeResult.BackColor = Color.Red;
  7371. label_FacModeResult.Text = "测试异常";
  7372. Delay_ms(500);
  7373. //存储异常并上传
  7374. FacMode_Stop(false);
  7375. return;
  7376. }
  7377. Delay_ms(500);
  7378. } while (true);
  7379. //设置转速100%
  7380. var Data = new byte[1];
  7381. Data[0] = (byte)100;
  7382. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7383. Delay_ms(500);
  7384. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7385. Delay_ms(500);
  7386. //启动电机进入WALK模式
  7387. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7388. Code[0] = 0x22;
  7389. Code[1] = 0xF0;
  7390. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7391. WriteACK = false;
  7392. ACK_WaitCnt = 0;
  7393. while (ACK_WaitCnt <= 2) ; //1s
  7394. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7395. {
  7396. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7397. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7398. ACK_WaitCnt = 0;
  7399. while (ACK_WaitCnt <= 2) ; //1s
  7400. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7401. {
  7402. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7403. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7404. ACK_WaitCnt = 0;
  7405. while (ACK_WaitCnt <= 2) ; //1s
  7406. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7407. {
  7408. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7409. label_FacModeStatus.Text = "存在故障!";
  7410. label_FacModeResult.BackColor = Color.Red;
  7411. label_FacModeResult.Text = "测试异常";
  7412. Delay_ms(500);
  7413. //存储异常并上传
  7414. FacMode_Stop(false);
  7415. return;
  7416. }
  7417. }
  7418. }
  7419. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7420. ACK_WaitCnt = 0;
  7421. while (ACK_WaitCnt <= 20)
  7422. {
  7423. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7424. {
  7425. label_FacModeBreak.BackColor = Color.Green;
  7426. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7427. break;
  7428. }
  7429. }
  7430. if (ACK_WaitCnt >= 20) //剎把超时
  7431. {
  7432. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7433. label_FacModeStatus.Text = "存在故障!";
  7434. label_FacModeResult.BackColor = Color.Red;
  7435. label_FacModeResult.Text = "测试异常";
  7436. Delay_ms(500);
  7437. //存储异常并上传
  7438. FacMode_Stop(false);
  7439. return;
  7440. }
  7441. //停止电机
  7442. Code[0] = 0x00;
  7443. Code[1] = 0xF0;
  7444. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7445. WriteACK = false;
  7446. ACK_WaitCnt = 0;
  7447. while (ACK_WaitCnt <= 2) ; //1s
  7448. if (textBox_RunInfo_GearSt.Text != "OFF")
  7449. {
  7450. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7451. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7452. ACK_WaitCnt = 0;
  7453. while (ACK_WaitCnt <= 2) ; //1s
  7454. if (textBox_RunInfo_GearSt.Text != "OFF")
  7455. {
  7456. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7457. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7458. ACK_WaitCnt = 0;
  7459. while (ACK_WaitCnt <= 2) ; //1s
  7460. if (textBox_RunInfo_GearSt.Text != "OFF")
  7461. {
  7462. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7463. label_FacModeStatus.Text = "存在故障!";
  7464. label_FacModeResult.BackColor = Color.Red;
  7465. label_FacModeResult.Text = "测试异常";
  7466. Delay_ms(500);
  7467. //存储异常并上传
  7468. FacMode_Stop(false);
  7469. return;
  7470. }
  7471. }
  7472. }
  7473. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7474. Delay_ms(500);
  7475. }
  7476. else
  7477. {
  7478. label_FacModeBreak.BackColor = Color.Yellow;
  7479. label_FacModeStatus.Text = "跳过刹车检测!";
  7480. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7481. Delay_ms(500);
  7482. }
  7483. //前后灯检测
  7484. if (checkBox_FacLightTest.Checked)
  7485. {
  7486. //前后灯检测
  7487. label_FacModeStatus.Text = "前后灯检测";
  7488. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7489. //发送指令打开车灯
  7490. Code[0] = 0x00;
  7491. Code[1] = 0xF1;
  7492. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7493. WriteACK = false;
  7494. ACK_WaitCnt = 0;
  7495. while (ACK_WaitCnt <= 2) ; //1s
  7496. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7497. {
  7498. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7499. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7500. ACK_WaitCnt = 0;
  7501. while (ACK_WaitCnt <= 2); //1s
  7502. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7503. {
  7504. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7505. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7506. ACK_WaitCnt = 0;
  7507. while (ACK_WaitCnt <= 2) ; //1s
  7508. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7509. {
  7510. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7511. label_FacModeStatus.Text = "存在故障!";
  7512. label_FacModeResult.BackColor = Color.Red;
  7513. label_FacModeResult.Text = "测试异常";
  7514. Delay_ms(500);
  7515. //存储异常并上传
  7516. FacMode_Stop(false);
  7517. return;
  7518. }
  7519. }
  7520. }
  7521. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7522. Delay_ms(500);
  7523. //提示检查灯压是否正确
  7524. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7525. {
  7526. label_FacModeLightF.BackColor = Color.Green;
  7527. label_FacModeLightB.BackColor = Color.Green;
  7528. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7529. Delay_ms(500);
  7530. }
  7531. else
  7532. {
  7533. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7534. label_FacModeStatus.Text = "存在故障!";
  7535. label_FacModeResult.BackColor = Color.Red;
  7536. label_FacModeResult.Text = "测试异常";
  7537. Delay_ms(500);
  7538. //存储异常并上传
  7539. FacMode_Stop(false);
  7540. return;
  7541. }
  7542. //发送指令关闭车灯
  7543. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7544. Code[0] = 0x00;
  7545. Code[1] = 0xF0;
  7546. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7547. WriteACK = false;
  7548. ACK_WaitCnt = 0;
  7549. while (ACK_WaitCnt <= 2) ; //1s
  7550. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7551. {
  7552. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7553. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7554. ACK_WaitCnt = 0;
  7555. while (ACK_WaitCnt <= 2) ; //1s
  7556. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7557. {
  7558. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7559. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7560. ACK_WaitCnt = 0;
  7561. while (ACK_WaitCnt <= 2) ; //1s
  7562. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7563. {
  7564. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7565. label_FacModeStatus.Text = "存在故障!";
  7566. label_FacModeResult.BackColor = Color.Red;
  7567. label_FacModeResult.Text = "测试异常";
  7568. Delay_ms(500);
  7569. //存储异常并上传
  7570. FacMode_Stop(false);
  7571. return;
  7572. }
  7573. }
  7574. }
  7575. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7576. Delay_ms(500);
  7577. }
  7578. else
  7579. {
  7580. label_FacModeLightF.BackColor = Color.Yellow;
  7581. label_FacModeLightB.BackColor = Color.Yellow;
  7582. label_FacModeStatus.Text = "跳过前后灯检测!";
  7583. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7584. Delay_ms(500);
  7585. }
  7586. //软件版本检测
  7587. do
  7588. {
  7589. label_FacModeStatus.Text = "软件版本确认";
  7590. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7591. //发送指令读取版本
  7592. Class_Motor_Ver.Mode = "---";
  7593. Class_Motor_Ver.SN = "---";
  7594. Class_Motor_Ver.HW = "---";
  7595. Class_Motor_Ver.FW = "---";
  7596. Class_Motor_Ver.Special = "---";
  7597. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7598. ACK_WaitCnt = 0;
  7599. while (ACK_WaitCnt <= 2) ; //1s
  7600. if (Class_Motor_Ver.Mode == "---")
  7601. {
  7602. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7603. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7604. ACK_WaitCnt = 0;
  7605. while (ACK_WaitCnt <= 2) ; //1s
  7606. if (Class_Motor_Ver.Mode == "---")
  7607. {
  7608. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7609. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7610. ACK_WaitCnt = 0;
  7611. while (ACK_WaitCnt <= 2) ; //1s
  7612. if (Class_Motor_Ver.Mode == "---")
  7613. {
  7614. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7615. label_FacModeStatus.Text = "存在故障!";
  7616. label_FacModeResult.BackColor = Color.Red;
  7617. label_FacModeResult.Text = "测试异常";
  7618. Delay_ms(500);
  7619. //存储异常并上传
  7620. FacMode_Stop(false);
  7621. return;
  7622. }
  7623. }
  7624. }
  7625. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7626. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7627. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7628. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7629. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7630. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7631. //判断版本是否正确
  7632. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7633. string VerRead = "";
  7634. try
  7635. {
  7636. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7637. }
  7638. catch (System.Exception)
  7639. {
  7640. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7641. label_FacModeStatus.Text = "存在故障!";
  7642. label_FacModeResult.BackColor = Color.Red;
  7643. label_FacModeResult.Text = "测试异常";
  7644. Delay_ms(500);
  7645. //存储异常并上传
  7646. FacMode_Stop(false);
  7647. return;
  7648. }
  7649. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7650. {
  7651. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7652. label_FacModeStatus.Text = "存在故障!";
  7653. label_FacModeResult.BackColor = Color.Red;
  7654. label_FacModeResult.Text = "测试异常";
  7655. Delay_ms(500);
  7656. //存储异常并上传
  7657. FacMode_Stop(false);
  7658. return;
  7659. }
  7660. label_FacModeFWVersion.BackColor = Color.Green;
  7661. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7662. Delay_ms(500);
  7663. } while (false);
  7664. //测试合格
  7665. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7666. label_FacModeStatus.Text = "测试结束!";
  7667. label_FacModeResult.BackColor = Color.Green;
  7668. label_FacModeResult.Text = "测试合格";
  7669. Delay_ms(500);
  7670. //存储并上传
  7671. FacMode_Stop(true);
  7672. return;
  7673. }
  7674. private void FacModelLabelInit()
  7675. {
  7676. //测试状态标签
  7677. label_FacModeResult.BackColor = Color.Yellow;
  7678. label_FacModeResult.Text = "测试中";
  7679. //测试过程标签
  7680. label_FacModeStatus.Text = "测试就绪";
  7681. //测试结果标签
  7682. foreach (Control c in groupBox28.Controls)
  7683. {
  7684. if (c is Label)
  7685. {
  7686. if (c.Text == string.Empty)
  7687. c.BackColor = Color.Red;
  7688. }
  7689. }
  7690. }
  7691. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7692. {
  7693. //更新生产配置文件目录
  7694. GetDateList(false);
  7695. }
  7696. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7697. {
  7698. //更新生产配置文件目录
  7699. GetDateList(false);
  7700. }
  7701. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7702. {
  7703. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7704. richTextBox_FacModeLog.ScrollToCaret();
  7705. }
  7706. /// <summary>
  7707. /// 参数检验测试停止
  7708. /// </summary>
  7709. /// <param name="OK_Flag"></param>
  7710. private void CheckMode_Stop(bool OK_Flag)
  7711. {
  7712. //打开开始按钮
  7713. button_CheckModeStart.Enabled = true;
  7714. //导出电机参数
  7715. string Params = "";
  7716. do
  7717. {
  7718. if (!OK_Flag)
  7719. {
  7720. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7721. break;
  7722. }
  7723. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7724. //读取一次马达参数
  7725. richTextBox_MotorParam.Clear();
  7726. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7727. Delay_ms(100);
  7728. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7729. Params += "\r\n";
  7730. //读取一次整车参数
  7731. richTextBox_BikeParam.Clear();
  7732. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7733. Delay_ms(100);
  7734. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7735. Params += "\r\n";
  7736. //读取一次控制参数
  7737. richTextBox_ControlParam.Clear();
  7738. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7739. Delay_ms(100);
  7740. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7741. Params += "\r\n";
  7742. //查询传感器
  7743. richTextBox_SensorParam.Clear();
  7744. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7745. Delay_ms(100);
  7746. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7747. Params += "\r\n";
  7748. //读取15次助力参数
  7749. Params += "[助力参数]" + "\r\n";
  7750. for (int i = 1; i <= 15; i++)
  7751. {
  7752. var ConfigParam = new byte[4];
  7753. richTextBox_AssistParam.Clear();
  7754. ConfigParam[0] = (byte)(i & 0xFF);
  7755. ConfigParam[1] = (byte)(i >> 8);
  7756. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7757. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7758. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7759. Delay_ms(200);
  7760. Params += richTextBox_AssistParam.Text + "\r\n";
  7761. Params += "\r\n";
  7762. }
  7763. //读取一次调试信息
  7764. richTextBox_DebugParam.Clear();
  7765. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7766. Delay_ms(100);
  7767. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7768. Params += "\r\n";
  7769. //读取一次历史信息
  7770. richTextBox_Record.Clear();
  7771. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7772. Delay_ms(100);
  7773. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7774. Params += "\r\n";
  7775. //读取一次MOS内阻校准参数
  7776. foreach (Control c in groupBox21.Controls)
  7777. {
  7778. if (c is TextBox)
  7779. c.Text = "";
  7780. }
  7781. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7782. Delay_ms(100);
  7783. Params += "[MOS内阻校准参数]" + "\r\n";
  7784. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7785. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7786. Params += "\r\n";
  7787. //读取一次整车参数2
  7788. richTextBox_BikeParam2.Clear();
  7789. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7790. Delay_ms(100);
  7791. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  7792. Params += "\r\n";
  7793. //读取一次用户骑行参数
  7794. richTextBox_UsrRidesParam.Clear();
  7795. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  7796. Delay_ms(100);
  7797. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  7798. Params += "\r\n";
  7799. //读取一次生产信息
  7800. textBox_MAC.Text = "";
  7801. textBox_MACAdd.Text = "";
  7802. textBox_MACDate.Text = "";
  7803. textBox_PP.Text = "";
  7804. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  7805. Delay_ms(100);
  7806. Params += "[生产信息]" + "\r\n";
  7807. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  7808. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  7809. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  7810. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  7811. Params += "\r\n";
  7812. //读取一次自定义信息
  7813. textBox_User1.Text = "---";
  7814. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  7815. Delay_ms(100);
  7816. textBox_User2.Text = "---";
  7817. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  7818. Delay_ms(100);
  7819. textBox_User3.Text = "---";
  7820. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  7821. Delay_ms(100);
  7822. Params += "[自定义信息]" + "\r\n";
  7823. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  7824. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  7825. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  7826. Params += "\r\n";
  7827. //读取一次密钥
  7828. textBox_Key.Text = "---";
  7829. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  7830. Delay_ms(100);
  7831. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  7832. Params += "\r\n";
  7833. //读取一次存储标志
  7834. radioButton_EE_SaveYes.Checked = false;
  7835. radioButton_EE_SaveNo.Checked = false;
  7836. radioButton_SIP_SaveYes.Checked = false;
  7837. radioButton_SIP_SaveNo.Checked = false;
  7838. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  7839. Delay_ms(100);
  7840. Params += "[存储标志]" + "\r\n";
  7841. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7842. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7843. Params += "\r\n";
  7844. } while (false);
  7845. //系统关机
  7846. var Code = new byte[32];//发送的指令数据
  7847. Code[0] = 0xF0;
  7848. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7849. //关闭串口
  7850. //mySerialProcess.SerialClose(false);
  7851. //路径设置
  7852. string LocalSavePath = "";
  7853. string ServerSavePath = "";
  7854. if (OK_Flag)
  7855. {
  7856. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7857. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7858. }
  7859. else
  7860. {
  7861. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  7862. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  7863. }
  7864. if (Directory.Exists(LocalSavePath) == false)
  7865. {
  7866. Directory.CreateDirectory(LocalSavePath);
  7867. }
  7868. //保存和上传
  7869. string LogSavePath = "";
  7870. string LogSaveFileName = "";
  7871. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_"); ;
  7872. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  7873. if (Directory.Exists(LogSavePath) == false)
  7874. {
  7875. Directory.CreateDirectory(LogSavePath);
  7876. }
  7877. //测试页面
  7878. Double scaleX = PrimaryScreen.ScaleX;
  7879. Double scaleY = PrimaryScreen.ScaleY;
  7880. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  7881. Graphics g = Graphics.FromImage(bit);
  7882. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  7883. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  7884. bit.Save(LogSaveFileName);
  7885. //上传测试页面到服务器
  7886. if (myFtp.IsNetConnected == true)
  7887. {
  7888. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7889. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7890. {
  7891. myFtp.MakeDir(ServerSavePath + DateNow);
  7892. }
  7893. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7894. {
  7895. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7896. }
  7897. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7898. if (result == true)
  7899. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7900. }
  7901. //测试记录
  7902. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7903. string file_str = "";
  7904. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7905. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7906. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7907. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7908. file_str += Local_HdInformation;
  7909. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  7910. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7911. //上传测试记录到服务器
  7912. if (myFtp.IsNetConnected == true)
  7913. {
  7914. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7915. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7916. {
  7917. myFtp.MakeDir(ServerSavePath + DateNow);
  7918. }
  7919. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7920. {
  7921. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7922. }
  7923. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7924. if (result == true)
  7925. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7926. }
  7927. //扫码框清空
  7928. textBox_CheckModeScan.Text = "";
  7929. }
  7930. /// <summary>
  7931. /// 参数检验开始
  7932. /// </summary>
  7933. /// <param name="sender"></param>
  7934. /// <param name="e"></param>
  7935. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7936. {
  7937. //测试项目关闭编辑
  7938. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7939. foreach (Control c in groupBox29.Controls)
  7940. {
  7941. if (c is CheckBox)
  7942. c.Enabled = false;
  7943. }
  7944. ReadLockStatus = true;
  7945. //检查配置文件
  7946. if (comboBox_CheckModeCfgFile.Text == "")
  7947. {
  7948. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7949. return;
  7950. }
  7951. //开始测试
  7952. CheckTestStart();
  7953. }
  7954. /// <summary>
  7955. /// 参数检验测试子函数
  7956. /// </summary>
  7957. private void CheckTestStart()
  7958. {
  7959. //初始化标签
  7960. CheckModeLabelInit();
  7961. richTextBox_CheckModeLog.Clear();
  7962. //按钮禁止操作
  7963. button_CheckModeStart.Enabled = false;
  7964. //记录配置文件
  7965. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7966. //检查打标信息
  7967. label_CheckModeStatus.Text = "检查扫码信息";
  7968. Delay_ms(500);
  7969. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7970. if (textBox_CheckModeScan.Text == string.Empty)
  7971. {
  7972. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7973. button__FacMode_Start.Enabled = false;
  7974. return;
  7975. }
  7976. try
  7977. {
  7978. if (中置电机ToolStripMenuItem.Checked == true)
  7979. {
  7980. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7981. {
  7982. label_CheckModeStatus.Text = "存在故障!";
  7983. label_CheckModeResult.BackColor = Color.Red;
  7984. label_CheckModeResult.Text = "标签格式错误";
  7985. button_CheckModeStart.Enabled = true;
  7986. return;
  7987. }
  7988. }
  7989. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7990. {
  7991. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  7992. {
  7993. label_CheckModeStatus.Text = "存在故障!";
  7994. label_CheckModeResult.BackColor = Color.Red;
  7995. label_CheckModeResult.Text = "标签格式错误";
  7996. button_CheckModeStart.Enabled = true;
  7997. return;
  7998. }
  7999. }
  8000. }
  8001. catch (System.Exception)
  8002. {
  8003. label_CheckModeStatus.Text = "存在故障!";
  8004. label_CheckModeResult.BackColor = Color.Red;
  8005. label_CheckModeResult.Text = "标签格式错误";
  8006. button_CheckModeStart.Enabled = true;
  8007. return;
  8008. }
  8009. //打开串口
  8010. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  8011. if (!mySerialProcess.mySerial.IsOpen)
  8012. {
  8013. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8014. button__FacMode_Start.Enabled = false;
  8015. return;
  8016. }
  8017. //流水号计数
  8018. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  8019. serial += 1;
  8020. label_CheckModeSerial.Text = serial.ToString();
  8021. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  8022. //创建线程,执行测试任务
  8023. Thread th = new Thread(CheckModeTest_Task);
  8024. th.Start();
  8025. }
  8026. /// <summary>
  8027. /// 执行一次测试任务
  8028. /// </summary>
  8029. private void CheckModeTest_Task()
  8030. {
  8031. //开始测试
  8032. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  8033. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  8034. //变量定义
  8035. var Code = new byte[255];//发送的指令数据
  8036. ushort DataTemp;
  8037. short DataTemp_Int16;
  8038. string ResultPathName = "";
  8039. label_CheckModeStatus.Text = "开始测试";
  8040. BootInfo = "";
  8041. Delay_ms(500);
  8042. label_CheckModeStatus.Text = "系统开机";
  8043. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  8044. if (uARTToolStripMenuItem.Checked)
  8045. {
  8046. Code[0] = (byte)'R';
  8047. Code[1] = (byte)'E';
  8048. Code[2] = (byte)'S';
  8049. Code[3] = (byte)'E';
  8050. Code[4] = (byte)'T';
  8051. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  8052. Delay_ms(500);
  8053. }
  8054. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  8055. //确保测试前先关机,发送关机指令再发送开机指令
  8056. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  8057. Code[0] = 0xF0;
  8058. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8059. Delay_ms(1500);
  8060. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  8061. Code[0] = 0xF1;
  8062. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8063. ACK_WaitCnt = 0;
  8064. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  8065. while (ACK_WaitCnt <= 20) ; //10s
  8066. //检查BOOT版本
  8067. if (BootInfo != string.Empty)
  8068. {
  8069. label_CheckModeBoot.BackColor = Color.Green;
  8070. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  8071. Delay_ms(500);
  8072. }
  8073. else
  8074. {
  8075. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  8076. label_CheckModeStatus.Text = "存在故障!";
  8077. label_CheckModeResult.BackColor = Color.Red;
  8078. label_CheckModeResult.Text = "测试异常";
  8079. Delay_ms(500);
  8080. //存储异常并上传
  8081. CheckMode_Stop(false);
  8082. return;
  8083. }
  8084. #if false
  8085. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  8086. {
  8087. Code[0] = 0x00;//5S协议
  8088. Code[1] = 0x00;
  8089. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8090. Delay_ms(500);
  8091. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8092. Delay_ms(500);
  8093. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8094. }
  8095. #endif
  8096. //发送指令读取版本信息
  8097. do
  8098. {
  8099. label_CheckModeStatus.Text = "读取版本信息";
  8100. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8101. //发送指令读取版本
  8102. Class_Motor_Ver.Mode = "---";
  8103. Class_Motor_Ver.SN = "---";
  8104. Class_Motor_Ver.HW = "---";
  8105. Class_Motor_Ver.FW = "---";
  8106. Class_Motor_Ver.Special = "---";
  8107. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8108. ACK_WaitCnt = 0;
  8109. while (ACK_WaitCnt <= 2) ; //1s
  8110. if (Class_Motor_Ver.Mode == "---")
  8111. {
  8112. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8113. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8114. ACK_WaitCnt = 0;
  8115. while (ACK_WaitCnt <= 2) ; //1s
  8116. if (Class_Motor_Ver.Mode == "---")
  8117. {
  8118. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8119. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8120. ACK_WaitCnt = 0;
  8121. while (ACK_WaitCnt <= 2) ; //1s
  8122. if (Class_Motor_Ver.Mode == "---")
  8123. {
  8124. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8125. label_CheckModeStatus.Text = "存在故障!";
  8126. label_CheckModeResult.BackColor = Color.Red;
  8127. label_CheckModeResult.Text = "测试异常";
  8128. Delay_ms(500);
  8129. //存储异常并上传
  8130. CheckMode_Stop(false);
  8131. return;
  8132. }
  8133. }
  8134. }
  8135. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8136. Delay_ms(500);
  8137. } while (false);
  8138. //软件版本检查
  8139. if (checkBox_CheckModeFWVer.Checked)
  8140. {
  8141. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8142. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8143. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8144. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8145. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8146. //判断版本是否正确
  8147. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8148. string VerRead = "";
  8149. try
  8150. {
  8151. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8152. }
  8153. catch (System.Exception)
  8154. {
  8155. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8156. label_CheckModeStatus.Text = "存在故障!";
  8157. label_CheckModeResult.BackColor = Color.Red;
  8158. label_CheckModeResult.Text = "测试异常";
  8159. Delay_ms(500);
  8160. //存储异常并上传
  8161. CheckMode_Stop(false);
  8162. return;
  8163. }
  8164. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8165. {
  8166. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8167. label_CheckModeStatus.Text = "存在故障!";
  8168. label_CheckModeResult.BackColor = Color.Red;
  8169. label_CheckModeResult.Text = "测试异常";
  8170. Delay_ms(500);
  8171. //存储异常并上传
  8172. CheckMode_Stop(false);
  8173. return;
  8174. }
  8175. label_CheckModeFWVer.BackColor = Color.Green;
  8176. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8177. Delay_ms(500);
  8178. }
  8179. else
  8180. {
  8181. label_CheckModeFWVer.BackColor = Color.Yellow;
  8182. label_CheckModeStatus.Text = "跳过软件版本查询";
  8183. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8184. Delay_ms(500);
  8185. }
  8186. //打标信息核对
  8187. if (checkBox_CheckModeSN.Checked)
  8188. {
  8189. label_CheckModeStatus.Text = "核对打标信息";
  8190. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8191. //根据扫码信息获取型号和SN
  8192. string ScanInfo = textBox_CheckModeScan.Text;
  8193. string regexInfo = "";
  8194. string[] InfoList = { "" };
  8195. try
  8196. {
  8197. if (中置电机ToolStripMenuItem.Checked == true)
  8198. {
  8199. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8200. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8201. }
  8202. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8203. {
  8204. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8205. string Model = InfoList[0];
  8206. string Spec = InfoList[1];
  8207. string Sn = InfoList[2];
  8208. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8209. InfoList[1] = Sn;
  8210. }
  8211. }
  8212. catch
  8213. {
  8214. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8215. label_FacModeStatus.Text = "存在故障!";
  8216. label_FacModeResult.BackColor = Color.Red;
  8217. label_FacModeResult.Text = "标签格式错误";
  8218. Delay_ms(500);
  8219. //存储异常并上传
  8220. CheckMode_Stop(false);
  8221. return;
  8222. }
  8223. //核对型号
  8224. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8225. {
  8226. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8227. label_CheckModeStatus.Text = "存在故障!";
  8228. label_CheckModeResult.BackColor = Color.Red;
  8229. label_CheckModeResult.Text = "测试异常";
  8230. Delay_ms(500);
  8231. //存储异常并上传
  8232. CheckMode_Stop(false);
  8233. return;
  8234. }
  8235. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8236. Delay_ms(500);
  8237. //核对SN
  8238. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8239. {
  8240. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8241. label_CheckModeStatus.Text = "存在故障!";
  8242. label_CheckModeResult.BackColor = Color.Red;
  8243. label_CheckModeResult.Text = "测试异常";
  8244. Delay_ms(500);
  8245. //存储异常并上传
  8246. CheckMode_Stop(false);
  8247. return;
  8248. }
  8249. label_CheckModeSN.BackColor = Color.Green;
  8250. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8251. Delay_ms(500);
  8252. }
  8253. else
  8254. {
  8255. label_CheckModeSN.BackColor = Color.Yellow;
  8256. label_CheckModeStatus.Text = "跳过打标信息确认";
  8257. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8258. Delay_ms(500);
  8259. }
  8260. //参数检验
  8261. if (checkBox_CheckModeCfg.Checked)
  8262. {
  8263. //读取配置文件信息
  8264. label_CheckModeStatus.Text = "参数检查";
  8265. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8266. //配置文件
  8267. List<byte[]> CmdList = new List<byte[]>();
  8268. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8269. //从服务器下载文件
  8270. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8271. {
  8272. string SelectFile = "";
  8273. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8274. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8275. {
  8276. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8277. }
  8278. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8279. //打开文件
  8280. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8281. ConfigCmd.Clear();
  8282. while (streamReader.Peek() != -1)
  8283. {
  8284. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8285. if (fileLineInfo.Contains("["))
  8286. {
  8287. if (fileLineInfo.Contains("助力参数"))
  8288. {
  8289. fileLineInfo = streamReader.ReadLine();
  8290. }
  8291. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8292. }
  8293. }
  8294. streamReader.Close();
  8295. }
  8296. //从本地加载文件
  8297. else
  8298. {
  8299. string SelectFile = "";
  8300. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8301. //打开文件
  8302. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8303. ConfigCmd.Clear();
  8304. while (streamReader.Peek() != -1)
  8305. {
  8306. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8307. if (fileLineInfo.Contains("["))
  8308. {
  8309. if (fileLineInfo.Contains("助力参数"))
  8310. {
  8311. fileLineInfo = streamReader.ReadLine();
  8312. }
  8313. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8314. }
  8315. }
  8316. streamReader.Close();
  8317. }
  8318. int CmdNum = ConfigCmd.Count(); //指令个数
  8319. Delay_ms(500);
  8320. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8321. Delay_ms(500);
  8322. //逐条读取比较
  8323. try
  8324. {
  8325. foreach (string key in ConfigCmd.Keys)
  8326. {
  8327. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8328. CmdRevStrTemp = "";
  8329. if (key.Contains("曲线"))
  8330. {
  8331. byte LineNum = 0;
  8332. var code = new byte[4];
  8333. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8334. if (LineNum <= 5)
  8335. {
  8336. code[0] = (byte)(LineNum & 0xFF);
  8337. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8338. code[2] = (byte)(LineNum & 0xFF);
  8339. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8340. }
  8341. else
  8342. {
  8343. code[0] = (byte)(LineNum & 0xFF);
  8344. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8345. code[2] = (byte)(5 & 0xFF);
  8346. code[3] = (byte)((5 >> 8) & 0xFF);
  8347. }
  8348. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8349. }
  8350. else
  8351. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8352. Delay_ms(500);
  8353. if (CmdRevStrTemp == string.Empty)
  8354. {
  8355. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8356. if (key.Contains("曲线"))
  8357. {
  8358. byte LineNum = 0;
  8359. var code = new byte[4];
  8360. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8361. if (LineNum <= 5)
  8362. {
  8363. code[0] = (byte)(LineNum & 0xFF);
  8364. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8365. code[2] = (byte)(LineNum & 0xFF);
  8366. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8367. }
  8368. else
  8369. {
  8370. code[0] = (byte)(LineNum & 0xFF);
  8371. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8372. code[2] = (byte)(5 & 0xFF);
  8373. code[3] = (byte)((5 >> 8) & 0xFF);
  8374. }
  8375. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8376. }
  8377. else
  8378. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8379. Delay_ms(500);
  8380. if (CmdRevStrTemp == string.Empty)
  8381. {
  8382. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8383. if (key.Contains("曲线"))
  8384. {
  8385. byte LineNum = 0;
  8386. var code = new byte[4];
  8387. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8388. if (LineNum <= 5)
  8389. {
  8390. code[0] = (byte)(LineNum & 0xFF);
  8391. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8392. code[2] = (byte)(LineNum & 0xFF);
  8393. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8394. }
  8395. else
  8396. {
  8397. code[0] = (byte)(LineNum & 0xFF);
  8398. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8399. code[2] = (byte)(5 & 0xFF);
  8400. code[3] = (byte)((5 >> 8) & 0xFF);
  8401. }
  8402. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8403. }
  8404. else
  8405. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8406. Delay_ms(500);
  8407. if (CmdRevStrTemp == string.Empty)
  8408. {
  8409. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8410. label_CheckModeStatus.Text = "存在故障!";
  8411. label_CheckModeResult.BackColor = Color.Red;
  8412. label_CheckModeResult.Text = "测试异常";
  8413. Delay_ms(500);
  8414. //存储异常并上传
  8415. CheckMode_Stop(false);
  8416. return;
  8417. }
  8418. }
  8419. }
  8420. //比较当前指令,读取的配置文件和返回数据比较
  8421. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8422. string ParamRead = "";
  8423. ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
  8424. ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
  8425. if (CmdGet != CmdRev)
  8426. {
  8427. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
  8428. richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
  8429. richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
  8430. label_CheckModeStatus.Text = "存在故障!";
  8431. label_CheckModeResult.BackColor = Color.Red;
  8432. label_CheckModeResult.Text = "测试异常";
  8433. Delay_ms(500);
  8434. //存储异常并上传
  8435. CheckMode_Stop(false);
  8436. return;
  8437. }
  8438. if (string.Compare(key, "[其它传感器参数]") == 0)
  8439. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
  8440. else if (string.Compare(key, "[控制参数]") == 0)
  8441. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
  8442. else
  8443. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8444. if (ParamWrite.Contains(ParamRead))
  8445. {
  8446. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8447. continue;
  8448. }
  8449. else
  8450. {
  8451. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8452. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8453. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8454. label_CheckModeStatus.Text = "存在故障!";
  8455. label_CheckModeResult.BackColor = Color.Red;
  8456. label_CheckModeResult.Text = "测试异常";
  8457. Delay_ms(500);
  8458. //存储异常并上传
  8459. CheckMode_Stop(false);
  8460. return;
  8461. }
  8462. }
  8463. }
  8464. catch (System.Exception)
  8465. {
  8466. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  8467. label_CheckModeStatus.Text = "存在故障!";
  8468. label_CheckModeResult.BackColor = Color.Red;
  8469. label_CheckModeResult.Text = "测试异常";
  8470. Delay_ms(500);
  8471. //存储异常并上传
  8472. CheckMode_Stop(false);
  8473. return;
  8474. }
  8475. label_CheckModeCfg.BackColor = Color.Green;
  8476. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8477. Delay_ms(500);
  8478. }
  8479. else
  8480. {
  8481. label_CheckModeCfg.BackColor = Color.Yellow;
  8482. label_CheckModeStatus.Text = "跳过参数检验";
  8483. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8484. Delay_ms(500);
  8485. }
  8486. //读取力矩传感器
  8487. do
  8488. {
  8489. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8490. //发送指令读取力矩传感器标定数据
  8491. CmdRevStrTemp = "";
  8492. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8493. ACK_WaitCnt = 0;
  8494. while (ACK_WaitCnt <= 2) ; //1s
  8495. if (CmdRevStrTemp == string.Empty)
  8496. {
  8497. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8498. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8499. ACK_WaitCnt = 0;
  8500. while (ACK_WaitCnt <= 2) ; //1s
  8501. if (CmdRevStrTemp == string.Empty)
  8502. {
  8503. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8504. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8505. ACK_WaitCnt = 0;
  8506. while (ACK_WaitCnt <= 2) ; //1s
  8507. if (CmdRevStrTemp == string.Empty)
  8508. {
  8509. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8510. label_CheckModeStatus.Text = "存在故障!";
  8511. label_CheckModeResult.BackColor = Color.Red;
  8512. label_CheckModeResult.Text = "测试异常";
  8513. Delay_ms(500);
  8514. //存储异常并上传
  8515. CheckMode_Stop(false);
  8516. return;
  8517. }
  8518. }
  8519. }
  8520. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8521. //取力矩传感器数据
  8522. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8523. ushort MaxTorque;
  8524. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8525. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8526. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8527. if (Cmd != 0xB528)
  8528. {
  8529. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8530. label_CheckModeStatus.Text = "存在故障!";
  8531. label_CheckModeResult.BackColor = Color.Red;
  8532. label_CheckModeResult.Text = "测试异常";
  8533. Delay_ms(500);
  8534. //存储异常并上传
  8535. CheckMode_Stop(false);
  8536. return;
  8537. }
  8538. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8539. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8540. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8541. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8542. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8543. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8544. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8545. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8546. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8547. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8548. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8549. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8550. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8551. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8552. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8553. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8554. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8555. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8556. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8557. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8558. //传感器标定检验
  8559. if (checkBox_CheckModeTorque.Checked)
  8560. {
  8561. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8562. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8563. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8564. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8565. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8566. //与设置值比较
  8567. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8568. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8569. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8570. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8571. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8572. )
  8573. {
  8574. label_CheckModeTorque.BackColor = Color.Green;
  8575. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8576. Delay_ms(500);
  8577. }
  8578. else
  8579. {
  8580. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8581. label_CheckModeStatus.Text = "存在故障!";
  8582. label_CheckModeResult.BackColor = Color.Red;
  8583. label_CheckModeResult.Text = "测试异常";
  8584. Delay_ms(500);
  8585. //存储异常并上传
  8586. CheckMode_Stop(false);
  8587. return;
  8588. }
  8589. }
  8590. else
  8591. {
  8592. label_CheckModeTorque.BackColor = Color.Yellow;
  8593. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8594. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8595. Delay_ms(500);
  8596. }
  8597. } while (false);
  8598. //读取MOS内阻校准参数
  8599. do
  8600. {
  8601. if (checkBox_CheckModeMos.Checked)
  8602. {
  8603. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8604. //读取显示校准返回数据
  8605. foreach (Control c in groupBox21.Controls)
  8606. {
  8607. if (c is TextBox)
  8608. c.Text = "";
  8609. }
  8610. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8611. ACK_WaitCnt = 0;
  8612. while (ACK_WaitCnt <= 2) ; //1s
  8613. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8614. {
  8615. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8616. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8617. ACK_WaitCnt = 0;
  8618. while (ACK_WaitCnt <= 2) ; //1s
  8619. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8620. {
  8621. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8622. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8623. ACK_WaitCnt = 0;
  8624. while (ACK_WaitCnt <= 2) ; //1s
  8625. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8626. {
  8627. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8628. label_CheckModeStatus.Text = "存在故障!";
  8629. label_CheckModeResult.BackColor = Color.Red;
  8630. label_CheckModeResult.Text = "测试异常";
  8631. Delay_ms(500);
  8632. //存储异常并上传
  8633. CheckMode_Stop(false);
  8634. return;
  8635. }
  8636. }
  8637. }
  8638. else
  8639. {
  8640. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  8641. }
  8642. //与校准返回数据对比
  8643. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8644. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8645. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8646. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  8647. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8648. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8649. )
  8650. {
  8651. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8652. label_CheckModeMos.BackColor = Color.Green;
  8653. }
  8654. else
  8655. {
  8656. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8657. label_CheckModeStatus.Text = "存在故障!";
  8658. label_CheckModeResult.BackColor = Color.Red;
  8659. label_CheckModeResult.Text = "测试异常";
  8660. Delay_ms(500);
  8661. //存储异常并上传
  8662. CheckMode_Stop(false);
  8663. return;
  8664. }
  8665. }
  8666. else
  8667. {
  8668. label_CheckModeMos.BackColor = Color.Yellow;
  8669. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8670. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8671. Delay_ms(500);
  8672. }
  8673. } while (false);
  8674. //读取位置校准参数
  8675. do
  8676. {
  8677. if (checkBox_CheckModeAngle.Checked)
  8678. {
  8679. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  8680. //发送指令读取位置
  8681. CmdRevStrTemp = "";
  8682. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  8683. ACK_WaitCnt = 0;
  8684. while (ACK_WaitCnt <= 2) ; //1s
  8685. if (CmdRevStrTemp == string.Empty)
  8686. {
  8687. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  8688. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8689. ACK_WaitCnt = 0;
  8690. while (ACK_WaitCnt <= 2) ; //1s
  8691. if (CmdRevStrTemp == string.Empty)
  8692. {
  8693. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  8694. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8695. ACK_WaitCnt = 0;
  8696. while (ACK_WaitCnt <= 2) ; //1s
  8697. if (CmdRevStrTemp == string.Empty)
  8698. {
  8699. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  8700. label_CheckModeStatus.Text = "存在故障!";
  8701. label_CheckModeResult.BackColor = Color.Red;
  8702. label_CheckModeResult.Text = "测试异常";
  8703. Delay_ms(500);
  8704. //存储异常并上传
  8705. CheckMode_Stop(false);
  8706. return;
  8707. }
  8708. }
  8709. }
  8710. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  8711. //取零点数据
  8712. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  8713. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8714. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8715. if (Cmd != 0xB420)
  8716. {
  8717. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8718. label_CheckModeStatus.Text = "存在故障!";
  8719. label_CheckModeResult.BackColor = Color.Red;
  8720. label_CheckModeResult.Text = "测试异常";
  8721. Delay_ms(500);
  8722. //存储异常并上传
  8723. CheckMode_Stop(false);
  8724. return;
  8725. }
  8726. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8727. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8728. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  8729. int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
  8730. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  8731. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  8732. //判断
  8733. if (AngleZeroDiff <= AngleZeroTH)
  8734. {
  8735. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  8736. label_CheckModeAngle.BackColor = Color.Green;
  8737. }
  8738. else
  8739. {
  8740. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  8741. label_CheckModeStatus.Text = "存在故障!";
  8742. label_CheckModeResult.BackColor = Color.Red;
  8743. label_CheckModeResult.Text = "测试异常";
  8744. Delay_ms(500);
  8745. //存储异常并上传
  8746. CheckMode_Stop(false);
  8747. return;
  8748. }
  8749. }
  8750. else
  8751. {
  8752. label_CheckModeAngle.BackColor = Color.Yellow;
  8753. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  8754. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  8755. Delay_ms(500);
  8756. }
  8757. } while (false);
  8758. //测试合格
  8759. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8760. label_CheckModeStatus.Text = "测试结束!";
  8761. label_CheckModeResult.BackColor = Color.Green;
  8762. label_CheckModeResult.Text = "测试合格";
  8763. Delay_ms(500);
  8764. //存储并上传
  8765. CheckMode_Stop(true);
  8766. return;
  8767. }
  8768. private void CheckModeLabelInit()
  8769. {
  8770. //测试状态标签
  8771. label_CheckModeResult.BackColor = Color.Yellow;
  8772. label_CheckModeResult.Text = "测试中";
  8773. //测试过程标签
  8774. label_CheckModeStatus.Text = "测试就绪";
  8775. //测试结果标签
  8776. foreach (Control c in groupBox31.Controls)
  8777. {
  8778. if (c is Label)
  8779. {
  8780. if (c.Text == string.Empty)
  8781. c.BackColor = Color.Red;
  8782. }
  8783. }
  8784. }
  8785. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8786. {
  8787. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8788. }
  8789. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8790. {
  8791. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8792. }
  8793. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8794. {
  8795. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8796. UInt32 hour = Time / 3600;
  8797. UInt32 min = (Time % 3600) / 60;
  8798. UInt32 s = (Time % 60);
  8799. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8800. }
  8801. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8802. {
  8803. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8804. richTextBox_CheckModeLog.ScrollToCaret();
  8805. }
  8806. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8807. {
  8808. TorqueParamsForm.ShowDialog();
  8809. }
  8810. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8811. {
  8812. if (e.KeyCode == Keys.Enter)
  8813. CheckTestStart();
  8814. }
  8815. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8816. {
  8817. if (e.KeyCode == Keys.Enter)
  8818. TestStart();
  8819. }
  8820. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8821. {
  8822. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8823. if (Percent <= 10)
  8824. Percent = 0;
  8825. else
  8826. Percent -= 10;
  8827. //生产模式转速设置值更新
  8828. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8829. //设置转速百分比
  8830. var Data = new byte[1];
  8831. Data[0] = (byte)Percent;
  8832. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8833. }
  8834. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  8835. {
  8836. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8837. if (Percent >= 90)
  8838. Percent = 100;
  8839. else
  8840. Percent += 10;
  8841. //生产模式转速设置值更新
  8842. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8843. //设置转速百分比
  8844. var Data = new byte[1];
  8845. Data[0] = (byte)Percent;
  8846. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8847. }
  8848. private void button_SpeedDec1_Click(object sender, EventArgs e)
  8849. {
  8850. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8851. if (Percent <= 1)
  8852. Percent = 0;
  8853. else
  8854. Percent -= 1;
  8855. //生产模式转速设置值更新
  8856. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8857. //设置转速百分比
  8858. var Data = new byte[1];
  8859. Data[0] = (byte)Percent;
  8860. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8861. }
  8862. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  8863. {
  8864. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8865. if (Percent >= 99)
  8866. Percent = 100;
  8867. else
  8868. Percent += 1;
  8869. //生产模式转速设置值更新
  8870. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8871. //设置转速百分比
  8872. var Data = new byte[1];
  8873. Data[0] = (byte)Percent;
  8874. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8875. }
  8876. bool WriteLockStatus = true;
  8877. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  8878. {
  8879. if (WriteLockStatus == true)
  8880. {
  8881. EnterForm1.ShowDialog();
  8882. try
  8883. {
  8884. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8885. {
  8886. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8887. {
  8888. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8889. foreach (Control c in groupBox2.Controls)
  8890. {
  8891. if (c is CheckBox)
  8892. c.Enabled = true;
  8893. }
  8894. WriteLockStatus = !WriteLockStatus;
  8895. }
  8896. else
  8897. {
  8898. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8899. }
  8900. }
  8901. else
  8902. {
  8903. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8904. }
  8905. }
  8906. catch (Exception)
  8907. {
  8908. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8909. }
  8910. }
  8911. else
  8912. {
  8913. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8914. foreach (Control c in groupBox2.Controls)
  8915. {
  8916. if (c is CheckBox)
  8917. c.Enabled = false;
  8918. }
  8919. WriteLockStatus = !WriteLockStatus;
  8920. }
  8921. }
  8922. bool ReadLockStatus = true;
  8923. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  8924. {
  8925. if (ReadLockStatus == true)
  8926. {
  8927. EnterForm1.ShowDialog();
  8928. try
  8929. {
  8930. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8931. {
  8932. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8933. {
  8934. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8935. foreach (Control c in groupBox29.Controls)
  8936. {
  8937. if (c is CheckBox)
  8938. c.Enabled = true;
  8939. }
  8940. ReadLockStatus = !ReadLockStatus;
  8941. }
  8942. else
  8943. {
  8944. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8945. }
  8946. }
  8947. else
  8948. {
  8949. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8950. }
  8951. }
  8952. catch (Exception)
  8953. {
  8954. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8955. }
  8956. }
  8957. else
  8958. {
  8959. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8960. foreach (Control c in groupBox29.Controls)
  8961. {
  8962. if (c is CheckBox)
  8963. c.Enabled = false;
  8964. }
  8965. ReadLockStatus = !ReadLockStatus;
  8966. }
  8967. }
  8968. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  8969. {
  8970. System.Diagnostics.Process.Start("osk.exe");
  8971. }
  8972. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  8973. {
  8974. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  8975. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  8976. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  8977. }
  8978. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  8979. {
  8980. comboBox_FacModeCfgDate.SelectedIndex = -1;
  8981. comboBox_FacModeCfgFile.SelectedIndex = -1;
  8982. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  8983. }
  8984. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  8985. {
  8986. VersionForm.ShowDialog();
  8987. }
  8988. private void button_MOS_Cal_Click(object sender, EventArgs e)
  8989. {
  8990. textBox_MOS_R1.Text = "";
  8991. textBox_MOS_R2.Text = "";
  8992. textBox_MOS_R3.Text = "";
  8993. try
  8994. {
  8995. var Code = new byte[18];
  8996. for (int i = 0; i < 18; i++)
  8997. Code[i] = 0;
  8998. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8999. ushort uwDataTemp = 0;
  9000. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9001. Code[2] = (byte)(uwDataTemp & 0xFF);
  9002. Code[3] = (byte)(uwDataTemp >> 8);
  9003. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9004. Code[4] = (byte)(uwDataTemp & 0xFF);
  9005. Code[5] = (byte)(uwDataTemp >> 8);
  9006. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9007. Code[6] = (byte)(uwDataTemp & 0xFF);
  9008. Code[7] = (byte)(uwDataTemp >> 8);
  9009. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9010. Code[8] = (byte)(uwDataTemp & 0xFF);
  9011. Code[9] = (byte)(uwDataTemp >> 8);
  9012. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9013. Code[10] = (byte)(uwDataTemp & 0xFF);
  9014. Code[11] = (byte)(uwDataTemp >> 8);
  9015. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  9016. }
  9017. catch (Exception)
  9018. {
  9019. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9020. }
  9021. }
  9022. private void button_MOS_Read_Click(object sender, EventArgs e)
  9023. {
  9024. foreach (Control c in groupBox21.Controls)
  9025. {
  9026. if (c is TextBox)
  9027. c.Text = "";
  9028. }
  9029. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9030. }
  9031. private void button_MOS_Write_Click(object sender, EventArgs e)
  9032. {
  9033. try
  9034. {
  9035. var Code = new byte[34];
  9036. for (int i = 0; i < 34; i++)
  9037. Code[i] = 0;
  9038. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9039. ushort uwDataTemp = 0;
  9040. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  9041. Code[2] = (byte)(uwDataTemp & 0xFF);
  9042. Code[3] = (byte)(uwDataTemp >> 8);
  9043. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  9044. Code[4] = (byte)(uwDataTemp & 0xFF);
  9045. Code[5] = (byte)(uwDataTemp >> 8);
  9046. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  9047. Code[6] = (byte)(uwDataTemp & 0xFF);
  9048. Code[7] = (byte)(uwDataTemp >> 8);
  9049. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9050. Code[8] = (byte)(uwDataTemp & 0xFF);
  9051. Code[9] = (byte)(uwDataTemp >> 8);
  9052. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9053. Code[10] = (byte)(uwDataTemp & 0xFF);
  9054. Code[11] = (byte)(uwDataTemp >> 8);
  9055. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9056. Code[12] = (byte)(uwDataTemp & 0xFF);
  9057. Code[13] = (byte)(uwDataTemp >> 8);
  9058. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9059. Code[14] = (byte)(uwDataTemp & 0xFF);
  9060. Code[15] = (byte)(uwDataTemp >> 8);
  9061. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9062. Code[16] = (byte)(uwDataTemp & 0xFF);
  9063. Code[17] = (byte)(uwDataTemp >> 8);
  9064. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  9065. }
  9066. catch (Exception)
  9067. {
  9068. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9069. }
  9070. }
  9071. /// <summary>
  9072. /// 测试模式点击文本框自动全选
  9073. /// </summary>
  9074. /// <param name="sender"></param>
  9075. /// <param name="e"></param>
  9076. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  9077. {
  9078. textBox_FacModeScan.SelectAll();
  9079. }
  9080. /// <summary>
  9081. /// 检验模式点击文本框自动全选
  9082. /// </summary>
  9083. /// <param name="sender"></param>
  9084. /// <param name="e"></param>
  9085. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  9086. {
  9087. textBox_CheckModeScan.SelectAll();
  9088. }
  9089. /// <summary>
  9090. /// 鼠标放置显示连接服务器信息
  9091. /// </summary>
  9092. /// <param name="sender"></param>
  9093. /// <param name="e"></param>
  9094. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  9095. {
  9096. // 创建the ToolTip
  9097. ToolTip toolTip1 = new ToolTip();
  9098. // 设置显示样式
  9099. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  9100. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9101. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9102. toolTip1.ShowAlways = true;//是否显示提示框
  9103. if (myFtp.IsNetConnected)
  9104. {
  9105. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  9106. }
  9107. else
  9108. {
  9109. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  9110. }
  9111. }
  9112. /// <summary>
  9113. /// UART协议类型修改
  9114. /// </summary>
  9115. /// <param name="sender"></param>
  9116. /// <param name="e"></param>
  9117. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  9118. {
  9119. var Code = new byte[2];
  9120. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  9121. Code[1] = 0x00;
  9122. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9123. }
  9124. /// <summary>
  9125. /// 显示本机信息
  9126. /// </summary>
  9127. /// <param name="sender"></param>
  9128. /// <param name="e"></param>
  9129. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  9130. {
  9131. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9132. }
  9133. /// <summary>
  9134. /// 量产模式删除当前选中文件
  9135. /// </summary>
  9136. /// <param name="sender"></param>
  9137. /// <param name="e"></param>
  9138. private void label112_DoubleClick(object sender, EventArgs e)
  9139. {
  9140. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9141. {
  9142. EnterForm1.ShowDialog();
  9143. try
  9144. {
  9145. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9146. {
  9147. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9148. {
  9149. try
  9150. {
  9151. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  9152. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  9153. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  9154. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9155. }
  9156. catch (Exception)
  9157. {
  9158. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9159. }
  9160. }
  9161. else
  9162. {
  9163. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9164. }
  9165. }
  9166. }
  9167. catch (Exception)
  9168. {
  9169. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9170. }
  9171. }
  9172. }
  9173. /// <summary>
  9174. /// 检验模式删除当前选中文件
  9175. /// </summary>
  9176. /// <param name="sender"></param>
  9177. /// <param name="e"></param>
  9178. private void label138_DoubleClick(object sender, EventArgs e)
  9179. {
  9180. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9181. {
  9182. EnterForm1.ShowDialog();
  9183. try
  9184. {
  9185. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9186. {
  9187. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9188. {
  9189. try
  9190. {
  9191. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  9192. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  9193. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  9194. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9195. }
  9196. catch (Exception)
  9197. {
  9198. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9199. }
  9200. }
  9201. else
  9202. {
  9203. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9204. }
  9205. }
  9206. }
  9207. catch (Exception)
  9208. {
  9209. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9210. }
  9211. }
  9212. }
  9213. /// <summary>
  9214. /// 读取整车信息2
  9215. /// </summary>
  9216. /// <param name="sender"></param>
  9217. /// <param name="e"></param>
  9218. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9219. {
  9220. richTextBox_BikeParam2.Clear();
  9221. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9222. }
  9223. /// <summary>
  9224. /// 写入整车信息2
  9225. /// </summary>
  9226. /// <param name="sender"></param>
  9227. /// <param name="e"></param>
  9228. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9229. {
  9230. var ConfigParam = new byte[34];
  9231. for (int i = 0; i < 34; i++)
  9232. ConfigParam[i] = 0;
  9233. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9234. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9235. try
  9236. {
  9237. for (int i = 0; i < strDataTemp.Length; i++)
  9238. {
  9239. short wDataTemp = 0;
  9240. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9241. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9242. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9243. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9244. }
  9245. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9246. }
  9247. catch (Exception)
  9248. {
  9249. timer_500ms.Enabled = false;
  9250. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9251. timer_500ms.Enabled = true;
  9252. }
  9253. }
  9254. /// <summary>
  9255. /// 读取用户骑行参数
  9256. /// </summary>
  9257. /// <param name="sender"></param>
  9258. /// <param name="e"></param>
  9259. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9260. {
  9261. richTextBox_UsrRidesParam.Clear();
  9262. if (checkBox_UserRideParam_OBC.Checked)
  9263. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9264. else
  9265. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9266. }
  9267. /// <summary>
  9268. /// 写入用户骑行参数
  9269. /// </summary>
  9270. /// <param name="sender"></param>
  9271. /// <param name="e"></param>
  9272. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9273. {
  9274. var ConfigParam = new byte[34];
  9275. for (int i = 0; i < 34; i++)
  9276. ConfigParam[i] = 0;
  9277. if (checkBox_UserRideParam_OBC.Checked)
  9278. {
  9279. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9280. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9281. try
  9282. {
  9283. for (int i = 0; i < strDataTemp.Length; i++)
  9284. {
  9285. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9286. }
  9287. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9288. }
  9289. catch (Exception)
  9290. {
  9291. timer_500ms.Enabled = false;
  9292. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9293. timer_500ms.Enabled = true;
  9294. }
  9295. }
  9296. else
  9297. {
  9298. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9299. try
  9300. {
  9301. for (int i = 0; i < strDataTemp.Length; i++)
  9302. {
  9303. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9304. }
  9305. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9306. }
  9307. catch (Exception)
  9308. {
  9309. timer_500ms.Enabled = false;
  9310. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9311. timer_500ms.Enabled = true;
  9312. }
  9313. }
  9314. }
  9315. /// <summary>
  9316. /// 读取产品标签
  9317. /// </summary>
  9318. /// <param name="sender"></param>
  9319. /// <param name="e"></param>
  9320. private void button_ReadTag_Click(object sender, EventArgs e)
  9321. {
  9322. textBox_TagInfo.Text = "---";
  9323. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9324. }
  9325. /// <summary>
  9326. /// 写入产品标签
  9327. /// </summary>
  9328. /// <param name="sender"></param>
  9329. /// <param name="e"></param>
  9330. private void button_WriteTag_Click(object sender, EventArgs e)
  9331. {
  9332. string User = textBox_TagInfo.Text;
  9333. var UserArray = new byte[32];
  9334. for (ushort i = 0; i < User.Length; i++)
  9335. {
  9336. UserArray[i] = (byte)User[i];
  9337. }
  9338. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9339. }
  9340. /// <summary>
  9341. /// 上位机读取骑行历史
  9342. /// </summary>
  9343. /// <param name="sender"></param>
  9344. /// <param name="e"></param>
  9345. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9346. {
  9347. textBox_ODO_KM.Text = "---";
  9348. textBox_ODO_TIME.Text = "---";
  9349. textBox_TRIP_KM.Text = "---";
  9350. textBox_TRIP_TIME.Text = "---";
  9351. textBox_OBC_TRIP_KM.Text = "";
  9352. textBox_OBC_TRIP_TIME.Text = "";
  9353. textBox_OBC_ODO_KM.Text = "";
  9354. textBox_OBC_ODO_TIME.Text = "";
  9355. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9356. }
  9357. /// <summary>
  9358. /// 上位机写入骑行历史
  9359. /// </summary>
  9360. /// <param name="sender"></param>
  9361. /// <param name="e"></param>
  9362. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9363. {
  9364. UInt32 Data;
  9365. var UserArray = new byte[16];
  9366. try
  9367. {
  9368. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9369. UserArray[0] = (byte)(Data & 0xFF);
  9370. UserArray[1] = (byte)(Data >> 8);
  9371. UserArray[2] = (byte)(Data >> 16);
  9372. UserArray[3] = (byte)(Data >> 24);
  9373. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9374. UserArray[4] = (byte)(Data & 0xFF);
  9375. UserArray[5] = (byte)(Data >> 8);
  9376. UserArray[6] = (byte)(Data >> 16);
  9377. UserArray[7] = (byte)(Data >> 24);
  9378. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9379. UserArray[8] = (byte)(Data & 0xFF);
  9380. UserArray[9] = (byte)(Data >> 8);
  9381. UserArray[10] = (byte)(Data >> 16);
  9382. UserArray[11] = (byte)(Data >> 24);
  9383. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9384. UserArray[12] = (byte)(Data & 0xFF);
  9385. UserArray[13] = (byte)(Data >> 8);
  9386. UserArray[14] = (byte)(Data >> 16);
  9387. UserArray[15] = (byte)(Data >> 24);
  9388. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9389. }
  9390. catch (Exception ex)
  9391. {
  9392. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9393. }
  9394. }
  9395. /// <summary>
  9396. /// 获取删除配置文件日期列表
  9397. /// </summary>
  9398. /// <param name="sender"></param>
  9399. /// <param name="e"></param>
  9400. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9401. {
  9402. string[] DateList = { "" };
  9403. //网络断开时直接退出
  9404. if (!myFtp.IsNetConnected)
  9405. return;
  9406. //从服务器更新日期列表
  9407. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9408. toolStripTextBox_DelCfgFile.Items.Clear();
  9409. //日期列表加载,显示最近30条
  9410. if (DateList.Length > 30)
  9411. {
  9412. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9413. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9414. }
  9415. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9416. {
  9417. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9418. }
  9419. }
  9420. /// <summary>
  9421. /// 删除指定配置文件
  9422. /// </summary>
  9423. /// <param name="sender"></param>
  9424. /// <param name="e"></param>
  9425. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9426. {
  9427. //提示输入文件名
  9428. Scan scan_form = new Scan();
  9429. scan_form.ShowDialog();
  9430. do
  9431. {
  9432. if (scan_form.textBox_Scan.Text == string.Empty)
  9433. {
  9434. timer_500ms.Enabled = false;
  9435. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9436. timer_500ms.Enabled = true;
  9437. break;
  9438. }
  9439. string DelFile = scan_form.textBox_Scan.Text;
  9440. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9441. {
  9442. EnterForm1.ShowDialog();
  9443. try
  9444. {
  9445. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9446. {
  9447. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9448. {
  9449. try
  9450. {
  9451. if (DelFile.Contains("."))
  9452. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9453. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9454. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9455. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9456. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9457. }
  9458. catch (Exception)
  9459. {
  9460. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9461. }
  9462. }
  9463. else
  9464. {
  9465. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9466. }
  9467. }
  9468. }
  9469. catch (Exception)
  9470. {
  9471. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9472. }
  9473. }
  9474. } while (false);
  9475. }
  9476. /// <summary>
  9477. /// 获取删除样机测试记录日期列表
  9478. /// </summary>
  9479. /// <param name="sender"></param>
  9480. /// <param name="e"></param>
  9481. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9482. {
  9483. string[] DateList = { "" };
  9484. //网络断开时直接退出
  9485. if (!myFtp.IsNetConnected)
  9486. return;
  9487. //从服务器更新日期列表
  9488. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9489. toolStripTextBox_DelLogFile.Items.Clear();
  9490. //日期列表加载,显示最近30天
  9491. if (DateList.Length > 30)
  9492. {
  9493. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9494. toolStripTextBox_DelLogFile.Items.Add("-----");
  9495. }
  9496. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9497. {
  9498. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9499. }
  9500. }
  9501. /// <summary>
  9502. /// 删除指定的样机测试记录
  9503. /// </summary>
  9504. /// <param name="sender"></param>
  9505. /// <param name="e"></param>
  9506. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9507. {
  9508. //提示输入文件名
  9509. Scan scan_form = new Scan();
  9510. scan_form.ShowDialog();
  9511. do
  9512. {
  9513. if (scan_form.textBox_Scan.Text == string.Empty)
  9514. {
  9515. timer_500ms.Enabled = false;
  9516. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9517. timer_500ms.Enabled = true;
  9518. break;
  9519. }
  9520. string DelFile = scan_form.textBox_Scan.Text;
  9521. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9522. {
  9523. EnterForm1.ShowDialog();
  9524. try
  9525. {
  9526. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9527. {
  9528. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9529. {
  9530. try
  9531. {
  9532. //删除指定目录下面所有文件和文件夹
  9533. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9534. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9535. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9536. }
  9537. catch (Exception)
  9538. {
  9539. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9540. }
  9541. }
  9542. else
  9543. {
  9544. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9545. }
  9546. }
  9547. }
  9548. catch (Exception)
  9549. {
  9550. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9551. }
  9552. }
  9553. } while (false);
  9554. }
  9555. /// <summary>
  9556. /// CAN协议选择
  9557. /// </summary>
  9558. /// <param name="sender"></param>
  9559. /// <param name="e"></param>
  9560. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9561. {
  9562. cANToolStripMenuItem.Checked= true;
  9563. uARTToolStripMenuItem.Checked = false;
  9564. UART协议ToolStripMenuItem.Visible = false;
  9565. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9566. }
  9567. /// <summary>
  9568. /// UART协议选择
  9569. /// </summary>
  9570. /// <param name="sender"></param>
  9571. /// <param name="e"></param>
  9572. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9573. {
  9574. cANToolStripMenuItem.Checked = false;
  9575. uARTToolStripMenuItem.Checked = true;
  9576. UART协议ToolStripMenuItem.Visible = true;
  9577. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9578. }
  9579. /// <summary>
  9580. /// 清除流水号
  9581. /// </summary>
  9582. /// <param name="sender"></param>
  9583. /// <param name="e"></param>
  9584. private void label131_DoubleClick(object sender, EventArgs e)
  9585. {
  9586. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9587. {
  9588. label_FacModeSerial.Text = "0";
  9589. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9590. }
  9591. }
  9592. /// <summary>
  9593. /// 清除流水号
  9594. /// </summary>
  9595. /// <param name="sender"></param>
  9596. /// <param name="e"></param>
  9597. private void label135_DoubleClick(object sender, EventArgs e)
  9598. {
  9599. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9600. {
  9601. label_CheckModeSerial.Text = "0";
  9602. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9603. }
  9604. }
  9605. /// <summary>
  9606. /// 打开自动更新
  9607. /// </summary>
  9608. /// <param name="sender"></param>
  9609. /// <param name="e"></param>
  9610. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9611. {
  9612. 打开ToolStripMenuItem.Checked = true;
  9613. 关闭ToolStripMenuItem.Checked = false;
  9614. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9615. }
  9616. /// <summary>
  9617. /// 关闭自动更新
  9618. /// </summary>
  9619. /// <param name="sender"></param>
  9620. /// <param name="e"></param>
  9621. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9622. {
  9623. 打开ToolStripMenuItem.Checked = false;
  9624. 关闭ToolStripMenuItem.Checked = true;
  9625. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9626. }
  9627. /// <summary>
  9628. /// 显示完整配置文件
  9629. /// </summary>
  9630. /// <param name="sender"></param>
  9631. /// <param name="e"></param>
  9632. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9633. {
  9634. // 创建the ToolTip
  9635. ToolTip toolTip1 = new ToolTip();
  9636. // 设置显示样式
  9637. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9638. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9639. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9640. toolTip1.ShowAlways = true;//是否显示提示框
  9641. // 设置伴随的对象.
  9642. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9643. }
  9644. /// <summary>
  9645. /// 显示完整配置文件
  9646. /// </summary>
  9647. /// <param name="sender"></param>
  9648. /// <param name="e"></param>
  9649. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9650. {
  9651. // 创建the ToolTip
  9652. ToolTip toolTip1 = new ToolTip();
  9653. // 设置显示样式
  9654. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9655. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9656. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9657. toolTip1.ShowAlways = true;//是否显示提示框
  9658. // 设置伴随的对象.
  9659. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9660. }
  9661. /// <summary>
  9662. /// 手动发送指令
  9663. /// </summary>
  9664. /// <param name="sender"></param>
  9665. /// <param name="e"></param>
  9666. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9667. {
  9668. //提示
  9669. Scan scan_form = new Scan();
  9670. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9671. scan_form.ShowDialog();
  9672. //发送写入的指令,填写ID、类型、命令字、数据
  9673. do
  9674. {
  9675. if (scan_form.textBox_Scan.Text == string.Empty)
  9676. {
  9677. timer_500ms.Enabled = false;
  9678. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9679. timer_500ms.Enabled = true;
  9680. break;
  9681. }
  9682. //输入文本转换为字节流
  9683. var InputData = new byte[256];
  9684. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9685. //ID
  9686. ushort ID;
  9687. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9688. //Mode
  9689. byte Mode;
  9690. Mode = InputData[2];
  9691. //Cmd
  9692. ushort Cmd;
  9693. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9694. //Data
  9695. var Data = new byte[Cmd & 0x00FF];
  9696. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9697. Data[i] = InputData[5 + i];
  9698. //发送数据
  9699. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9700. } while (false);
  9701. }
  9702. /// <summary>
  9703. /// 启动位置传感器校准
  9704. /// </summary>
  9705. /// <param name="sender"></param>
  9706. /// <param name="e"></param>
  9707. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9708. {
  9709. for (int i = 0; i < 7; i++)
  9710. for (int j = 0; j < 6; j++)
  9711. {
  9712. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9713. }
  9714. foreach (Control cr in tabPage_AngleCal.Controls)
  9715. {
  9716. if (cr is TextBox)
  9717. {
  9718. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9719. cr.Text = "";
  9720. }
  9721. }
  9722. var Data = new byte[2];
  9723. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9724. }
  9725. /// <summary>
  9726. /// 导出位置传感器校准数据
  9727. /// </summary>
  9728. /// <param name="sender"></param>
  9729. /// <param name="e"></param>
  9730. private void button_AngleExportData_Click(object sender, EventArgs e)
  9731. {
  9732. //读出产品信息
  9733. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9734. Delay_ms(200);
  9735. SaveFileDialog sfd = new SaveFileDialog
  9736. {
  9737. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9738. Filter = "文本文档(*.txt)|*.txt",
  9739. Title = "Save"
  9740. };
  9741. if (sfd.ShowDialog() != DialogResult.OK)
  9742. {
  9743. return;
  9744. }
  9745. string filepath = sfd.FileName;
  9746. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9747. using (StreamWriter sw = new StreamWriter(fs))
  9748. {
  9749. sw.Write("标准值 ");
  9750. sw.Write("60.00 ");
  9751. sw.Write("120.00 ");
  9752. sw.Write("180.00 ");
  9753. sw.Write("240.00 ");
  9754. sw.Write("300.00 ");
  9755. sw.Write("360.00 ");
  9756. for (int i = 0; i < 42; i++)
  9757. {
  9758. if ((i % 6 == 0))
  9759. {
  9760. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  9761. }
  9762. sw.Write(AngledataRecord[i] + " ");
  9763. }
  9764. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  9765. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  9766. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  9767. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  9768. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  9769. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  9770. sw.Flush();
  9771. }
  9772. fs.Close();
  9773. }
  9774. /// <summary>
  9775. /// 写入校准数据
  9776. /// </summary>
  9777. /// <param name="sender"></param>
  9778. /// <param name="e"></param>
  9779. private void button_AngleWrite_Click(object sender, EventArgs e)
  9780. {
  9781. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  9782. {
  9783. timer_500ms.Enabled = false;
  9784. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9785. timer_500ms.Enabled = true;
  9786. return;
  9787. }
  9788. timer_500ms.Enabled = false;
  9789. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  9790. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9791. {
  9792. var SaveFlag = new byte[4];
  9793. for (int i = 0; i < 4; i++)
  9794. SaveFlag[i] = 0;
  9795. SaveFlag[0] = (byte)(1);
  9796. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  9797. if (data1 > 360)
  9798. {
  9799. data1 -= 360;
  9800. }
  9801. else if (data1 < -360)
  9802. {
  9803. data1 += 360;
  9804. }
  9805. Int16 data2 = (Int16)(data1 * 32768 / 360);
  9806. SaveFlag[2] = (byte)(data2);
  9807. SaveFlag[3] = (byte)(data2 >> 8);
  9808. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  9809. timer_500ms.Enabled = true;
  9810. }
  9811. else
  9812. {
  9813. timer_500ms.Enabled = true;
  9814. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9815. }
  9816. }
  9817. /// <summary>
  9818. /// 存储允许偏差
  9819. /// </summary>
  9820. /// <param name="sender"></param>
  9821. /// <param name="e"></param>
  9822. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  9823. {
  9824. if (e.KeyCode == Keys.Enter)
  9825. {
  9826. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9827. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9828. }
  9829. }
  9830. /// <summary>
  9831. /// 存储零点允许偏差
  9832. /// </summary>
  9833. /// <param name="sender"></param>
  9834. /// <param name="e"></param>
  9835. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  9836. {
  9837. if (e.KeyCode == Keys.Enter)
  9838. {
  9839. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9840. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9841. }
  9842. }
  9843. /// <summary>
  9844. /// 删除服务器配置文件
  9845. /// </summary>
  9846. /// <param name="sender"></param>
  9847. /// <param name="e"></param>
  9848. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  9849. {
  9850. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9851. {
  9852. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  9853. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  9854. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  9855. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  9856. System.Environment.Exit(0);
  9857. }
  9858. }
  9859. /// <summary>
  9860. /// 按下Enter保存数据
  9861. /// </summary>
  9862. /// <param name="sender"></param>
  9863. /// <param name="e"></param>
  9864. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  9865. {
  9866. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  9867. if (e.KeyCode == Keys.Enter)
  9868. {
  9869. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9870. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9871. }
  9872. }
  9873. /// <summary>
  9874. /// 按下Enter保存数据
  9875. /// </summary>
  9876. /// <param name="sender"></param>
  9877. /// <param name="e"></param>
  9878. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  9879. {
  9880. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  9881. if (e.KeyCode == Keys.Enter)
  9882. {
  9883. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9884. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9885. }
  9886. }
  9887. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  9888. {
  9889. //检查本地文件
  9890. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  9891. {
  9892. if (!OfflineFlag)
  9893. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  9894. else
  9895. {
  9896. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9897. return;
  9898. }
  9899. }
  9900. //调用本地浏览器打开帮助文件
  9901. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  9902. }
  9903. /// <summary>
  9904. /// 打开或关闭指令窗口
  9905. /// </summary>
  9906. /// <param name="sender"></param>
  9907. /// <param name="e"></param>
  9908. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  9909. {
  9910. if (指令调试ToolStripMenuItem.Checked == false)
  9911. {
  9912. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  9913. {
  9914. DebugForm.debug1 = new DebugForm();
  9915. DebugForm.debug1.Show();
  9916. this.DebugWindowIsOpen = true;
  9917. }
  9918. else
  9919. {
  9920. DebugForm.debug1.Activate();
  9921. this.DebugWindowIsOpen = true;
  9922. }
  9923. 指令调试ToolStripMenuItem.Checked = true;
  9924. }
  9925. else
  9926. {
  9927. if (this.DebugWindowIsOpen == true)
  9928. {
  9929. DebugForm.debug1.Close();
  9930. this.DebugWindowIsOpen = false;
  9931. this.DebugDataDisplayEnable = false;
  9932. }
  9933. 指令调试ToolStripMenuItem.Checked = false;
  9934. }
  9935. }
  9936. }
  9937. }