mainForm.cs 519 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940
  1. using NPOI.POIFS.Crypt.Dsig;
  2. using NPOI.SS.Formula.Functions;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Diagnostics.Eventing.Reader;
  8. using System.Drawing;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.IO.Ports;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Runtime.InteropServices;
  15. using System.Runtime.InteropServices.ComTypes;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading;
  19. using System.Web;
  20. using System.Windows.Forms;
  21. using System.Xml.Linq;
  22. namespace Welling_Motor_Debug_Tool
  23. {
  24. public partial class mainForm : Form
  25. {
  26. #region 变量定义
  27. //版本号
  28. public static string Version = "2.5.1";
  29. //串口实例
  30. Serial_Process mySerialProcess = new Serial_Process();
  31. string PortNumSave = "";
  32. string PortBaudrateSave = "";
  33. //本地信息定义
  34. LocalInfo localInfo = new LocalInfo();
  35. //FTP实例
  36. ftp myFtp = new ftp();
  37. public string ServerIP = "";
  38. public string ServerPort = "";
  39. public string ServerUser = "";
  40. public string ServerPassWd = "";
  41. public bool OfflineFlag = false;
  42. //MC运行信息超时计数
  43. bool MC_RunInfo_Refresh = false;
  44. ushort MC_RunInfo_Refresh_Cnt = 0;
  45. //MC调试信息超时计数
  46. bool MC_DebugInfo_Refresh = false;
  47. ushort MC_DebugInfo_Refresh_Cnt = 0;
  48. //MC故障码超时计数
  49. bool MC_ErrorCode_Refresh = false;
  50. ushort MC_ErrorCode_Refresh_Cnt = 0;
  51. //配置参数实例
  52. Params myParams = new Params();
  53. //记录文件名称
  54. string RunInfoSaveFilename = "";
  55. //BMS运行信息超时计数
  56. bool BMS_RunInfo_Refresh = false;
  57. ushort BMS_RunInfo_Refresh_Cnt = 0;
  58. //生产模式关机指令反馈状态
  59. bool PowerOffAckStatus = false;
  60. //登录窗口
  61. public static Login EnterForm1 = new Login();
  62. //生产配置文件信息
  63. ArrayList array_CfgInfo = new ArrayList();
  64. //写入参数返回标志和计数
  65. public bool WriteACK = false;
  66. public ushort ACK_WaitCnt = 0;
  67. //写入参数返回提示标志
  68. public bool ACK_DisFlag = true;
  69. //Boot版本信息
  70. public string BootInfo = "";
  71. //接收指令临时缓存,转string
  72. public string CmdRevStrTemp = "";
  73. //计时器,用于统计运行时间
  74. public Stopwatch stopwatch = new Stopwatch();
  75. //力矩传感器检验参数窗口
  76. public static TorqueParams TorqueParamsForm = new TorqueParams();
  77. //参数生成窗口
  78. public static GenerateParams GenerateParamsForm = new GenerateParams();
  79. //版本信息窗口
  80. public static Version VersionForm = new Version();
  81. //本机硬件信息
  82. public string Local_HdInformation = "";
  83. //指令窗口显示
  84. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  85. //位置传感器数据记录
  86. string[] AngledataRecord = new string[42];
  87. //服务器设置窗口
  88. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  89. #endregion
  90. #region 故障日志结构体定义
  91. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  92. [StructLayout(LayoutKind.Sequential)]
  93. public struct MC_ErrorLogSaveInfo_Struct_t
  94. {
  95. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  96. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  97. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  98. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  99. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  100. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  101. //电机运行信息,占用空间32bytes
  102. [StructLayout(LayoutKind.Sequential)]
  103. public struct MC_RunInfo_Struct_t
  104. {
  105. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  106. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  107. public ushort Power; //电功率 1W,地址偏移4
  108. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  109. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  110. public byte Cadence; //踏频 1rpm,地址偏移10
  111. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  112. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  113. public byte GearSt; //助力档位,地址偏移13
  114. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  115. public byte SOC; //剩余电量 1%,地址偏移15
  116. public ushort RemainDistance; //续航里程 1km,地址偏移16
  117. public ushort Torque_AD; //力矩寄存器,地址偏移18
  118. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  119. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  120. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  121. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  122. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  123. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  124. public UInt32 RS; //预留 4bytes
  125. };
  126. [MarshalAs(UnmanagedType.Struct)]
  127. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  128. //控制变量
  129. public Int16 IqCurrent; //Pu, 地址偏移 48
  130. public Int16 IqVoltage; //Pu, 地址偏移 50
  131. public Int16 IdCurrent; //Pu, 地址偏移 52
  132. public Int16 IdVoltage; //Pu, 地址偏移 54
  133. //状态机
  134. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  135. //预留
  136. public UInt16 RS1;
  137. public UInt16 RS2;
  138. public UInt16 RS3;
  139. };
  140. #endregion
  141. #region 屏幕缩放比例获取
  142. public class PrimaryScreen
  143. {
  144. #region Win32 API
  145. [DllImport("user32.dll")]
  146. static extern IntPtr GetDC(IntPtr ptr);
  147. [DllImport("gdi32.dll")]
  148. static extern int GetDeviceCaps(
  149. IntPtr hdc, // handle to DC
  150. int nIndex // index of capability
  151. );
  152. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  153. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  154. #endregion
  155. #region DeviceCaps常量
  156. const int HORZRES = 8;
  157. const int VERTRES = 10;
  158. const int LOGPIXELSX = 88;
  159. const int LOGPIXELSY = 90;
  160. const int DESKTOPVERTRES = 117;
  161. const int DESKTOPHORZRES = 118;
  162. #endregion
  163. #region 属性
  164. /// <summary>
  165. /// 获取屏幕分辨率当前物理大小
  166. /// </summary>
  167. public static Size WorkingArea
  168. {
  169. get
  170. {
  171. IntPtr hdc = GetDC(IntPtr.Zero);
  172. Size size = new Size();
  173. size.Width = GetDeviceCaps(hdc, HORZRES);
  174. size.Height = GetDeviceCaps(hdc, VERTRES);
  175. ReleaseDC(IntPtr.Zero, hdc);
  176. return size;
  177. }
  178. }
  179. /// <summary>
  180. /// 当前系统DPI_X 大小 一般为96
  181. /// </summary>
  182. public static int DpiX
  183. {
  184. get
  185. {
  186. IntPtr hdc = GetDC(IntPtr.Zero);
  187. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  188. ReleaseDC(IntPtr.Zero, hdc);
  189. return DpiX;
  190. }
  191. }
  192. /// <summary>
  193. /// 当前系统DPI_Y 大小 一般为96
  194. /// </summary>
  195. public static int DpiY
  196. {
  197. get
  198. {
  199. IntPtr hdc = GetDC(IntPtr.Zero);
  200. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  201. ReleaseDC(IntPtr.Zero, hdc);
  202. return DpiX;
  203. }
  204. }
  205. /// <summary>
  206. /// 获取真实设置的桌面分辨率大小
  207. /// </summary>
  208. public static Size DESKTOP
  209. {
  210. get
  211. {
  212. IntPtr hdc = GetDC(IntPtr.Zero);
  213. Size size = new Size();
  214. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  215. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  216. ReleaseDC(IntPtr.Zero, hdc);
  217. return size;
  218. }
  219. }
  220. /// <summary>
  221. /// 获取宽度缩放百分比
  222. /// </summary>
  223. public static float ScaleX
  224. {
  225. get
  226. {
  227. IntPtr hdc = GetDC(IntPtr.Zero);
  228. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  229. int d = GetDeviceCaps(hdc, HORZRES);
  230. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  231. ReleaseDC(IntPtr.Zero, hdc);
  232. return ScaleX;
  233. }
  234. }
  235. /// <summary>
  236. /// 获取高度缩放百分比
  237. /// </summary>
  238. public static float ScaleY
  239. {
  240. get
  241. {
  242. IntPtr hdc = GetDC(IntPtr.Zero);
  243. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  244. ReleaseDC(IntPtr.Zero, hdc);
  245. return ScaleY;
  246. }
  247. }
  248. #endregion
  249. }
  250. #endregion
  251. public static mainForm mainform1 = null;
  252. public mainForm()
  253. {
  254. InitializeComponent();
  255. mainform1 = this;
  256. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  257. stopwatch.Start();
  258. //端口初始化
  259. mySerialProcess.Init();
  260. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  261. //检查文件夹
  262. if (!Directory.Exists(localInfo.LocalPath))
  263. {
  264. Directory.CreateDirectory(localInfo.LocalPath);
  265. }
  266. if (!Directory.Exists(localInfo.LocalDataPath))
  267. {
  268. Directory.CreateDirectory(localInfo.LocalDataPath);
  269. }
  270. if (!Directory.Exists(localInfo.ToolsPath))
  271. {
  272. Directory.CreateDirectory(localInfo.ToolsPath);
  273. }
  274. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  275. {
  276. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  277. }
  278. //检查备忘录文件
  279. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  280. {
  281. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  282. }
  283. //检验流水号记录文件
  284. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  285. {
  286. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  287. }
  288. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  289. {
  290. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  291. }
  292. //服务器初始化
  293. do
  294. {
  295. //检查是否存在配置文件
  296. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  297. {
  298. //解密
  299. string sLine = aes.DecryptFromFile(localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  300. string[] array_CfgInfo = sLine.Split(',');
  301. //解析配置文件
  302. ServerIP = array_CfgInfo[0].ToString();
  303. ServerPort = array_CfgInfo[1].ToString();
  304. ServerUser = array_CfgInfo[2].ToString();
  305. ServerPassWd = array_CfgInfo[3].ToString();
  306. if (array_CfgInfo[4].ToString() == "True")
  307. {
  308. OfflineFlag = true;
  309. checkBox_OffLineFacMode.Checked = true;
  310. checkBox_OffLineCheckMode.Checked = true;
  311. }
  312. }
  313. else //不存在配置文件由用户选择
  314. {
  315. ServerCfgForm1.ShowDialog();
  316. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  317. {
  318. case 0: //武汉园区
  319. case 1: //顺德工厂
  320. {
  321. ServerIP = "10.177.130.30";
  322. ServerPort = "15021";
  323. ServerUser = "factory_test";
  324. ServerPassWd = "ttium";
  325. OfflineFlag = false;
  326. checkBox_OffLineFacMode.Checked = false;
  327. checkBox_OffLineCheckMode.Checked = false;
  328. break;
  329. }
  330. case 2: //威灵园区
  331. case 3: //越南工厂
  332. case 4: //公司外部
  333. {
  334. ServerIP = "8.134.109.44";
  335. ServerPort = "21";
  336. ServerUser = "ttium";
  337. ServerPassWd = "ttium123";
  338. OfflineFlag = false;
  339. checkBox_OffLineFacMode.Checked = false;
  340. checkBox_OffLineCheckMode.Checked = false;
  341. break;
  342. }
  343. case 5: //离线使用
  344. {
  345. //输入管理员密码
  346. Scan scan_form = new Scan();
  347. scan_form.label1.Text = "请输入管理员密码";
  348. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  349. scan_form.ShowDialog();
  350. if (scan_form.textBox_Scan.Text == "ttium.123")
  351. {
  352. //检查许可
  353. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OffLineUseKeyFileName)) //未许可
  354. {
  355. if (MessageBox.Show("无离线授权,请导入许可文件!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
  356. {
  357. Licences myLicences = new Licences();
  358. myLicences.ShowDialog();
  359. //从许可文件读取内容
  360. string str_lic = aes.DecryptFromFile(myLicences.textBox_LicencePath.Text, "2D820F88F60A39D5", "3687C5216B19D16B");
  361. string PC_Code = PC_Information.GetCPUSerialNumber();
  362. if (PC_Code == str_lic) //授权码正确
  363. {
  364. aes.EncryptToFile(PC_Code, localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  365. string strInfo = "";
  366. strInfo = "0;" + DateTime.Now.ToString("yyyyMMdd");
  367. aes.EncryptToFile(strInfo, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  368. }
  369. else //授权码错误
  370. {
  371. MessageBox.Show("许可文件无效,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  372. System.Environment.Exit(0);
  373. }
  374. }
  375. else
  376. {
  377. System.Environment.Exit(0);
  378. }
  379. }
  380. else //已授权
  381. {
  382. string str_Key = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  383. //判断授权是否正确
  384. if (PC_Information.GetCPUSerialNumber() == str_Key) //授权正确
  385. {
  386. //检查离线使用记录文件
  387. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OfflineUseLogFileName))
  388. {
  389. MessageBox.Show("许可文件内容缺失,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  390. System.Environment.Exit(0);
  391. }
  392. //获取离线使用记录并更新
  393. string UseLog = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  394. UInt32 UseTimes = Convert.ToUInt32(UseLog.Split(';')[0]);
  395. UseTimes++;
  396. string str = UseTimes.ToString() + ";" + UseLog.Split(';')[1];
  397. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  398. //判断授权期限
  399. DateTime DataOrigin = new DateTime();
  400. DateTime.TryParseExact(UseLog.Split(';')[1], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DataOrigin);
  401. DateTime DataEnd = DataOrigin.AddDays(90);
  402. DateTime NowDate = DateTime.Now.Date;
  403. if ((NowDate > DataEnd) || (UseTimes > 1000)) //第一次打开软件90天内,或1000次内
  404. {
  405. MessageBox.Show("离线授权过期,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  406. System.Environment.Exit(0);
  407. }
  408. }
  409. else
  410. {
  411. MessageBox.Show("离线授权错误,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  412. System.Environment.Exit(0);
  413. }
  414. }
  415. OfflineFlag = true;
  416. checkBox_OffLineFacMode.Checked = true;
  417. checkBox_OffLineCheckMode.Checked = true;
  418. }
  419. else
  420. {
  421. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  422. System.Environment.Exit(0);
  423. }
  424. break;
  425. }
  426. default: //无效
  427. {
  428. System.Environment.Exit(0);
  429. break;
  430. }
  431. }
  432. //保存网络配置文件
  433. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  434. {
  435. string str = ServerIP + "," + ServerPort + "," + ServerUser + "," + ServerPassWd + "," + (OfflineFlag == true).ToString();
  436. //加密保存
  437. aes.EncryptToFile(str, localInfo.LocalPath + localInfo.ServerCfgFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  438. }
  439. }
  440. } while (false);
  441. //检查配置文件
  442. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  443. {
  444. //打开文件
  445. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  446. string sLine = "";
  447. ArrayList array_CfgInfo = new ArrayList();
  448. array_CfgInfo.Clear();
  449. while (sLine != null)
  450. {
  451. sLine = objReader.ReadLine();
  452. array_CfgInfo.Add(sLine);
  453. }
  454. objReader.Close();
  455. //解析配置文件
  456. try
  457. {
  458. //Port Set
  459. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  460. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  461. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  462. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  463. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  464. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  465. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  466. //Option
  467. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  468. //Server Set
  469. toolStripTextBox_ServerPath.Text = array_CfgInfo[11].ToString().Split(':')[1];
  470. //MacInfo
  471. toolStripTextBox_MAC.Text = array_CfgInfo[14].ToString().Split(':')[1];
  472. toolStripTextBoxMACAddr.Text = array_CfgInfo[15].ToString().Split(':')[1];
  473. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  474. toolStripTextBox_MACPD.Text = array_CfgInfo[17].ToString().Split(':')[1];
  475. //Log Address
  476. textBox_LogAddrBegin.Text = array_CfgInfo[20].ToString().Split(':')[1];
  477. textBox_LogAddrEnd.Text = array_CfgInfo[21].ToString().Split(':')[1];
  478. //电机类型
  479. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[24].ToString().Split(':')[1] == "True");
  480. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  481. //检测阈值
  482. toolStripTextBox_ThVol.Text = array_CfgInfo[28].ToString().Split(':')[1];
  483. toolStripTextBox_ThCur.Text = array_CfgInfo[29].ToString().Split(':')[1];
  484. toolStripTextBox_ThSpeed.Text = array_CfgInfo[30].ToString().Split(':')[1];
  485. toolStripTextBox_ThTor.Text = array_CfgInfo[31].ToString().Split(':')[1];
  486. toolStripTextBox_ThCad.Text = array_CfgInfo[32].ToString().Split(':')[1];
  487. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[33].ToString().Split(':')[1];
  488. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[34].ToString().Split(':')[1];
  489. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[35].ToString().Split(':')[1];
  490. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  491. //MOS内阻校准系数
  492. toolStripTextBox_MosCalK.Text = array_CfgInfo[39].ToString().Split(':')[1];
  493. toolStripTextBox_MOS1.Text= array_CfgInfo[40].ToString().Split(':')[1];
  494. toolStripTextBox_MOS2.Text = array_CfgInfo[41].ToString().Split(':')[1];
  495. toolStripTextBox_MOS3.Text = array_CfgInfo[42].ToString().Split(':')[1];
  496. //通信协议类型
  497. cANToolStripMenuItem.Checked = (array_CfgInfo[45].ToString().Split(':')[1] == "True");
  498. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  499. //自动更新开关
  500. 打开ToolStripMenuItem.Checked = (array_CfgInfo[49].ToString().Split(':')[1] == "True");
  501. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  502. //位置校准偏差
  503. textBox_AngleDiffTh.Text = array_CfgInfo[52].ToString().Split(':')[1];
  504. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  505. textBox_AngleZeroTh.Text = array_CfgInfo[53].ToString().Split(':')[1];
  506. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  507. }
  508. catch (System.Exception)
  509. {
  510. timer_500ms.Enabled = false;
  511. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  512. timer_500ms.Enabled = true;
  513. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  514. }
  515. }
  516. else //不存在配置文件,生成文件写入默认值
  517. {
  518. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  519. }
  520. //解析本地流水号记录
  521. do
  522. {
  523. //测试模式
  524. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  525. //检验模式
  526. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  527. } while (false);
  528. //获取本机信息,读取时间较长,优先从本地文件获取
  529. do
  530. {
  531. try
  532. {
  533. //本地文件为空,读取信息保存
  534. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  535. {
  536. Local_HdInformation = "";
  537. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  538. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  539. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  540. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  541. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  542. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  543. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  544. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  545. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  546. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  547. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  548. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  549. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  550. }
  551. //从本地读取,计算机名和IP地址重新读
  552. else
  553. {
  554. Local_HdInformation = "";
  555. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  556. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  557. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  558. for (int i = 0; i < fileInfo.Length; i++)
  559. Local_HdInformation += fileInfo[i] + "\r\n";
  560. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  561. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  562. }
  563. }
  564. catch(Exception)
  565. {
  566. }
  567. } while (false);
  568. //系统登录
  569. do
  570. {
  571. EnterForm1.ShowDialog();
  572. try
  573. {
  574. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  575. {
  576. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  577. {
  578. //隐藏设置项
  579. 其它配置项ToolStripMenuItem.Visible = false;
  580. 写入存储ToolStripMenuItem.Visible = false;
  581. 服务器配置ToolStripMenuItem.Visible = false;
  582. 判断阈值ToolStripMenuItem.Visible = false;
  583. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  584. mOS内阻范围ToolStripMenuItem.Visible = false;
  585. 力矩传感器检验ToolStripMenuItem.Visible = false;
  586. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  587. //显示生产信息
  588. 生产信息ToolStripMenuItem.Visible = true;
  589. //显示电机类型,但不可编辑
  590. 电机类型ToolStripMenuItem.Visible = true;
  591. 中置电机ToolStripMenuItem.Enabled = false;
  592. 轮毂电机ToolStripMenuItem.Enabled = false;
  593. if (uARTToolStripMenuItem.Checked)
  594. UART协议ToolStripMenuItem.Visible = true;
  595. //隐藏研发调试界面
  596. tabPage_MotorParam.Parent = null;
  597. tabPage_BikeParam.Parent = null;
  598. tabPage_BikeParam2.Parent = null;
  599. tabPage_ControlParam.Parent = null;
  600. tabPage_SensorParam.Parent = null;
  601. tabPage_AssistParam.Parent = null;
  602. tabPage_UsrRideParam.Parent = null;
  603. tabPage_DebugParam.Parent = null;
  604. tabPage_RecordInfo.Parent = null;
  605. tabPage_OtherInfo.Parent = null;
  606. tabPage_OBC.Parent = null;
  607. tabPage_RAMorFLASH.Parent = null;
  608. tabPage_FactoryMode.Parent = null;
  609. tabPage_DebugInfo.Parent = null;
  610. tabPage_AngleCal.Parent = null;
  611. tabPage_FuncSet.Parent = null;
  612. //显示运行信息
  613. tabPage_RunInfo.Parent = tabControl2;
  614. //根据电机类型修改生产信息和电机类型
  615. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  616. {
  617. 中置电机ToolStripMenuItem.Checked = true;
  618. 轮毂电机ToolStripMenuItem.Checked = false;
  619. toolStripTextBox_MACPD.Text = "MM_MC1";
  620. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  621. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  622. }
  623. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  624. {
  625. 中置电机ToolStripMenuItem.Checked = false;
  626. 轮毂电机ToolStripMenuItem.Checked = true;
  627. toolStripTextBox_MACPD.Text = "GF_250_1";
  628. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  629. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  630. }
  631. //显示对应生产测试界面
  632. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  633. {
  634. tabPage_ProductMode_Write.Parent = tabControl1;
  635. tabPage_ProductMode_Write.Select();
  636. tabPage_ProductMode_Read.Parent = null;
  637. }
  638. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  639. {
  640. tabPage_ProductMode_Read.Parent = tabControl1;
  641. tabPage_ProductMode_Read.Select();
  642. tabPage_ProductMode_Write.Parent = null;
  643. }
  644. //应答指令不提示
  645. ACK_DisFlag = false;
  646. //退出登录
  647. break;
  648. }
  649. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  650. {
  651. //隐藏工作台内容,新建窗口完成配置
  652. groupBox1.Visible = false;
  653. groupBox3.Visible = false;
  654. tabControl2.Visible = false;
  655. //隐藏提示信息
  656. label_StarInfo.Visible = false;
  657. //打开参数配置框
  658. GenerateParamsForm.ShowDialog();
  659. System.Environment.Exit(0);
  660. //退出登录
  661. break;
  662. }
  663. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  664. {
  665. //隐藏量产界面
  666. tabPage_ProductMode_Read.Parent = null;
  667. tabPage_ProductMode_Write.Parent = null;
  668. //隐藏配置项
  669. 其它配置项ToolStripMenuItem.Visible = false;
  670. 服务器配置ToolStripMenuItem.Visible = false;
  671. 判断阈值ToolStripMenuItem.Visible = false;
  672. 力矩传感器检验ToolStripMenuItem.Visible = false;
  673. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  674. mOS内阻范围ToolStripMenuItem.Visible = false;
  675. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  676. //显示生产信息
  677. 生产信息ToolStripMenuItem.Visible = true;
  678. //显示电机类型,但不可编辑
  679. 电机类型ToolStripMenuItem.Visible = true;
  680. 中置电机ToolStripMenuItem.Enabled = true;
  681. 轮毂电机ToolStripMenuItem.Enabled = true;
  682. if (uARTToolStripMenuItem.Checked)
  683. UART协议ToolStripMenuItem.Visible = true;
  684. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  685. {
  686. 中置电机ToolStripMenuItem.Checked = true;
  687. 轮毂电机ToolStripMenuItem.Checked = false;
  688. toolStripTextBox_MACPD.Text = "MM_MC1";
  689. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  690. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  691. }
  692. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  693. {
  694. 中置电机ToolStripMenuItem.Checked = false;
  695. 轮毂电机ToolStripMenuItem.Checked = true;
  696. toolStripTextBox_MACPD.Text = "GF_250_1";
  697. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  698. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  699. }
  700. //退出登录
  701. break;
  702. }
  703. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  704. {
  705. //隐藏设置项
  706. 其它配置项ToolStripMenuItem.Visible = false;
  707. 写入存储ToolStripMenuItem.Visible = false;
  708. 服务器配置ToolStripMenuItem.Visible = false;
  709. 判断阈值ToolStripMenuItem.Visible = false;
  710. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  711. mOS内阻范围ToolStripMenuItem.Visible = false;
  712. 力矩传感器检验ToolStripMenuItem.Visible = false;
  713. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  714. //显示生产信息
  715. 生产信息ToolStripMenuItem.Visible = true;
  716. //显示电机类型,但不可编辑
  717. 电机类型ToolStripMenuItem.Visible = false;
  718. 中置电机ToolStripMenuItem.Enabled = false;
  719. 轮毂电机ToolStripMenuItem.Enabled = false;
  720. if (uARTToolStripMenuItem.Checked)
  721. UART协议ToolStripMenuItem.Visible = true;
  722. //隐藏研发调试界面
  723. tabPage_MotorParam.Parent = null;
  724. tabPage_BikeParam.Parent = null;
  725. tabPage_BikeParam2.Parent = null;
  726. tabPage_ControlParam.Parent = null;
  727. tabPage_SensorParam.Parent = null;
  728. tabPage_AssistParam.Parent = null;
  729. tabPage_UsrRideParam.Parent = null;
  730. tabPage_DebugParam.Parent = null;
  731. tabPage_RecordInfo.Parent = null;
  732. tabPage_OtherInfo.Parent = null;
  733. tabPage_OBC.Parent = null;
  734. tabPage_RAMorFLASH.Parent = null;
  735. tabPage_FactoryMode.Parent = null;
  736. tabPage_DebugInfo.Parent = null;
  737. tabPage_AngleCal.Parent = null;
  738. tabPage_FuncSet.Parent = null;
  739. //显示运行信息
  740. tabPage_RunInfo.Parent = tabControl2;
  741. //目前仅轮毂使用
  742. 中置电机ToolStripMenuItem.Checked = false;
  743. 轮毂电机ToolStripMenuItem.Checked = true;
  744. toolStripTextBox_MACPD.Text = "GF_250_1";
  745. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  746. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  747. //显示量产测试界面
  748. tabPage_ProductMode_Write.Parent = tabControl1;
  749. tabPage_ProductMode_Write.Select();
  750. tabPage_ProductMode_Read.Parent = null;
  751. checkBox_OffLineFacMode.Checked = false;
  752. checkBox_OffLineFacMode.Enabled = true;
  753. checkBox_OffLineCheckMode.Checked = false;
  754. checkBox_OffLineCheckMode.Enabled = true;
  755. //应答指令不提示
  756. ACK_DisFlag = false;
  757. //退出登录
  758. break;
  759. }
  760. else if (EnterForm1.comboBox_User.Text == "研发调试")
  761. {
  762. //隐藏量产界面
  763. tabPage_ProductMode_Read.Parent = null;
  764. tabPage_ProductMode_Write.Parent = null;
  765. 服务器配置ToolStripMenuItem.Visible = false;
  766. if (uARTToolStripMenuItem.Checked)
  767. UART协议ToolStripMenuItem.Visible = true;
  768. //退出登录
  769. break;
  770. }
  771. else if (EnterForm1.comboBox_User.Text == "管理员")
  772. {
  773. //不隐藏任何界面
  774. //...
  775. //退出登录
  776. break;
  777. }
  778. else
  779. {
  780. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  781. //重新登录
  782. continue;
  783. }
  784. }
  785. else
  786. {
  787. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  788. //重新登录
  789. continue;
  790. }
  791. }
  792. catch (Exception)
  793. {
  794. System.Environment.Exit(0);
  795. }
  796. } while (true);
  797. //配置网络FTP服务器
  798. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  799. //创建线程,定时检测网络连接状态
  800. Thread th = new Thread(NetworkCheck);
  801. th.IsBackground = true;
  802. th.Start();
  803. //允许跨线程访问
  804. Control.CheckForIllegalCrossThreadCalls = false;
  805. }
  806. /// <summary>
  807. /// 检查网络状态线程
  808. /// </summary>
  809. private void NetworkCheck()
  810. {
  811. //允许离线使用,直接退出
  812. if (OfflineFlag == true) //允许离线使用
  813. {
  814. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  815. return;
  816. }
  817. //不允许离线使用,实时监测网络状态
  818. else
  819. {
  820. //初始化第一次连接FTP服务器
  821. bool Result = myFtp.CheckFtp();
  822. if (Result == true)//服务器连接成功
  823. {
  824. myFtp.IsNetConnected = true;
  825. //上传登录日志
  826. do
  827. {
  828. //日志文件名
  829. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  830. string fileName = date;
  831. //日志内容
  832. string fileInfo = Local_HdInformation;
  833. //保存本地
  834. if (!Directory.Exists(localInfo.LocalLogPath))
  835. Directory.CreateDirectory(localInfo.LocalLogPath);
  836. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  837. //上传服务器
  838. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  839. } while (false);
  840. }
  841. else//服务器连接失败
  842. {
  843. myFtp.IsNetConnected = false;
  844. if (EnterForm1.comboBox_User.Text != "管理员")
  845. {
  846. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  847. this.Close();
  848. }
  849. }
  850. //创建定时器,定时30s检查网络
  851. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  852. timer_CheckNet.Enabled = true;
  853. timer_CheckNet.Interval = 30000;
  854. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  855. timer_CheckNet.Start();
  856. while (true)
  857. {
  858. Thread.Sleep(1);
  859. if (myFtp.IsNetConnected == false)
  860. {
  861. label_Server_ComStatus.Text = "网络已断开";
  862. label_ServerStatus.BackColor = Color.Red;
  863. }
  864. else
  865. {
  866. label_Server_ComStatus.Text = "网络已连接";
  867. label_ServerStatus.BackColor = Color.Green;
  868. }
  869. }
  870. }
  871. }
  872. /// <summary>
  873. /// 线程中定时任务,检查网络状态
  874. /// </summary>
  875. /// <param name="sender"></param>
  876. /// <param name="e"></param>
  877. private void timer_CheckNet_Tick(object sender, EventArgs e)
  878. {
  879. //连接FTP服务器
  880. bool Result = myFtp.CheckFtp();
  881. if (Result == true)//服务器连接成功
  882. {
  883. myFtp.IsNetConnected = true;
  884. //允许使用
  885. groupBox1.Enabled = true;
  886. groupBox3.Enabled = true;
  887. tabControl2.Enabled = true;
  888. }
  889. else//服务器连接失败
  890. {
  891. myFtp.IsNetConnected = false;
  892. if (EnterForm1.comboBox_User.Text != "管理员")
  893. {
  894. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  895. //禁止使用
  896. groupBox1.Enabled = false;
  897. groupBox3.Enabled = false;
  898. tabControl2.Enabled = false;
  899. }
  900. }
  901. }
  902. #region 非独占性延时函数
  903. public static void Delay_ms(int milliSecond)
  904. {
  905. int start = Environment.TickCount;
  906. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  907. {
  908. Application.DoEvents();
  909. }
  910. }
  911. #endregion
  912. private void MainForm_Load(object sender, System.EventArgs e)
  913. {
  914. timer_500ms.Start();
  915. //页面初始化
  916. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  917. label_Computername.Text = System.Environment.UserName;
  918. label_UserName.Text = EnterForm1.comboBox_User.Text;
  919. //位置校准表格初始化
  920. for (int i = 0; i < 7; i++)
  921. {
  922. int index = dataGridView_AngleCal.Rows.Add();
  923. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  924. }
  925. dataGridView_AngleCal.AllowUserToAddRows = false;
  926. //拓展功能表格初始化
  927. for (int i = 0; i < 8; i++)
  928. {
  929. int index = dataGridView_FunSet.Rows.Add();
  930. dataGridView_FunSet.Rows[index].Cells[0].Value = "#" + (i + 1).ToString();
  931. }
  932. dataGridView_FunSet.AllowUserToAddRows = false;
  933. //窗体显示版本
  934. this.Text += Version;
  935. //检查版本,自动更新
  936. do
  937. {
  938. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  939. {
  940. break;
  941. }
  942. //检查网络状态
  943. if (myFtp.CheckFtp() == false)
  944. {
  945. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  946. break;
  947. }
  948. else
  949. {
  950. //检查本地文件删除
  951. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  952. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  953. //读取最新版本号
  954. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  955. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  956. string sLine = "";
  957. ArrayList arrText = new ArrayList();//创建一个动态数组
  958. while (sLine != null)
  959. {
  960. sLine = objReader.ReadLine();
  961. arrText.Add(sLine);
  962. }
  963. objReader.Close();
  964. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  965. //检查是否有最新版本
  966. string[] VerOld = mainForm.Version.Trim().Split('.');
  967. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  968. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  969. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  970. if (VerNew_int <= VerOld_int)
  971. {
  972. //版本已是最新,跳出
  973. break;
  974. }
  975. //确认下载最新版本
  976. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  977. {
  978. string SavePath = Directory.GetCurrentDirectory();
  979. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  980. foreach (string file in FileList)
  981. {
  982. if (file.Contains(".exe"))
  983. {
  984. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  985. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  986. System.Environment.Exit(0);
  987. }
  988. }
  989. }
  990. }
  991. } while (false);
  992. //下拉控件初始值设定
  993. comboBox_WorkMode.SelectedIndex = 0;
  994. comboBox_GearSt.SelectedIndex = 0;
  995. comboBox_LightSwitch.SelectedIndex = 1;
  996. comboBox_OBC_SetGearST.SelectedIndex = 0;
  997. comboBox_OBC_LightSw.SelectedIndex = 1;
  998. comboBox_AssistTorque.SelectedIndex = 0;
  999. comboBox_AssistCadence.SelectedIndex = 0;
  1000. //combobox事件定义
  1001. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  1002. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  1003. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  1004. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  1005. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  1006. //端口自动连接
  1007. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  1008. {
  1009. try
  1010. {
  1011. PortConnect();
  1012. }
  1013. catch (System.Exception)
  1014. {
  1015. timer_500ms.Enabled = false;
  1016. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1017. timer_500ms.Enabled = true;
  1018. }
  1019. }
  1020. //不识别联动装置盒自动打开界面
  1021. #if true
  1022. groupBox1.Visible = true;
  1023. groupBox3.Visible = true;
  1024. tabControl2.Visible = true;
  1025. label_StarInfo.Visible = false;
  1026. #endif
  1027. //创建线程,定时解析数据
  1028. Thread th = new Thread(Task_SerialProcess);
  1029. th.IsBackground = true;
  1030. th.Start();
  1031. }
  1032. #region 结构体与字节流相互转换
  1033. public static class MyConverter
  1034. {
  1035. /// <summary>
  1036. /// 由结构体转换为byte数组
  1037. /// </summary>
  1038. public static byte[] StructureToByte<T>(T structure)
  1039. {
  1040. int size = Marshal.SizeOf(typeof(T));
  1041. byte[] buffer = new byte[size];
  1042. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  1043. try
  1044. {
  1045. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  1046. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  1047. }
  1048. finally
  1049. {
  1050. Marshal.FreeHGlobal(bufferIntPtr);
  1051. }
  1052. return buffer;
  1053. }
  1054. /// <summary>
  1055. /// 由byte数组转换为结构体
  1056. /// </summary>
  1057. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  1058. {
  1059. object structure = null;
  1060. int size = Marshal.SizeOf(typeof(T));
  1061. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  1062. try
  1063. {
  1064. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  1065. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  1066. }
  1067. finally
  1068. {
  1069. Marshal.FreeHGlobal(allocIntPtr);
  1070. }
  1071. return (T)structure;
  1072. }
  1073. }
  1074. #endregion
  1075. #region 故障日志解析显示
  1076. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1077. {
  1078. string SaveData = "";
  1079. //Log1
  1080. if (Log1.Error_Index != 0xFFFF)
  1081. {
  1082. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1083. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1084. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1085. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1086. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1087. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1088. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1089. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1090. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1091. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1092. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1093. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1094. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1095. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1096. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1097. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1098. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1099. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1100. {
  1101. SaveData += "续航:" + "---km" + ", ";
  1102. }
  1103. else
  1104. {
  1105. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1106. }
  1107. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1108. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1109. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1110. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1111. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1112. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1113. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1114. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1115. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1116. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1117. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1118. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1119. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1120. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1121. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1122. SaveData += "\r\n\r\n";
  1123. richTextBox_Record.AppendText(SaveData);
  1124. SaveData = "";
  1125. }
  1126. //Log2
  1127. if (Log2.Error_Index != 0xFFFF)
  1128. {
  1129. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1130. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1131. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1132. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1133. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1134. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1135. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1136. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1137. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1138. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1139. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1140. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1141. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1142. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1143. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1144. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1145. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1146. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1147. {
  1148. SaveData += "续航:" + "---km" + ", ";
  1149. }
  1150. else
  1151. {
  1152. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1153. }
  1154. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1155. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1156. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1157. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1158. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1159. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1160. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1161. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1162. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1163. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1164. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1165. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1166. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1167. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1168. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1169. SaveData += "\r\n\r\n";
  1170. richTextBox_Record.AppendText(SaveData);
  1171. SaveData = "";
  1172. }
  1173. }
  1174. #endregion
  1175. #region 串口数据解析线程
  1176. /// <summary>
  1177. /// 串口数据解析线程
  1178. /// </summary>
  1179. private void Task_SerialProcess()
  1180. {
  1181. //创建定时器,定时读取串口数据
  1182. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1183. timer_ReadSerial.Enabled = true;
  1184. timer_ReadSerial.Interval = 20;
  1185. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1186. timer_ReadSerial.Start();
  1187. while (true)
  1188. {
  1189. Thread.Sleep(1);
  1190. };
  1191. }
  1192. /// <summary>
  1193. /// 串口解析定时器
  1194. /// </summary>
  1195. /// <param name="sender"></param>
  1196. /// <param name="e"></param>
  1197. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1198. {
  1199. //串口解析
  1200. Serial_process(mySerialProcess.buffer);
  1201. }
  1202. #endregion
  1203. #region 数据解析
  1204. public void Serial_process(List<byte> buffer)
  1205. {
  1206. byte DataNum = 0; //记录每条命令数据段的长度
  1207. ushort PackageID, Cmd;
  1208. byte[] Data = new byte[1024];
  1209. try
  1210. {
  1211. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1212. {
  1213. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1214. {
  1215. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1216. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1217. {
  1218. int CmdLen = buffer[5];
  1219. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1220. while (CmdLen > 0) //读取命令段
  1221. {
  1222. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1223. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1224. if (DataNum <= (CmdLen - 2))
  1225. {
  1226. for (int i = 0; i < DataNum; i++)
  1227. {
  1228. Data[i] = buffer[i + 8];
  1229. }
  1230. // 串口接收的数据 显示在子窗口
  1231. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1232. {
  1233. string strTemp = String.Empty;
  1234. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1235. for (int i = 0; i < CmdLen + 11; i++)
  1236. {
  1237. strTemp += (buffer[i].ToString("X2") + " ");
  1238. }
  1239. strTemp += "\n";
  1240. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1241. }
  1242. buffer.RemoveRange(0, CmdLen + 11);
  1243. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1244. DataRevToString(Cmd, Data);//指令数据转为字符串
  1245. }
  1246. }
  1247. }
  1248. else
  1249. {
  1250. buffer.RemoveAt(0);//ID不对
  1251. }
  1252. }
  1253. else
  1254. {
  1255. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1256. }
  1257. }
  1258. }
  1259. catch (Exception)
  1260. {
  1261. }
  1262. }
  1263. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1264. {
  1265. int DataTemp;
  1266. ushort uData16;
  1267. unchecked
  1268. {
  1269. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1270. }
  1271. #region 解析发送给CDL的指令
  1272. if (ID == 0x7FF)
  1273. {
  1274. switch (CmdTemp)
  1275. {
  1276. case 0x1100://
  1277. {
  1278. unchecked
  1279. {
  1280. this.Invoke((EventHandler)(delegate
  1281. {
  1282. //CDL连接成功
  1283. mySerialProcess.CDL_Online_Flag = true;
  1284. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1285. groupBox1.Visible = true;
  1286. groupBox3.Visible = true;
  1287. tabControl2.Visible = true;
  1288. label_StarInfo.Visible = false;
  1289. }));
  1290. }
  1291. break;
  1292. }
  1293. default: break;
  1294. }
  1295. }
  1296. #endregion
  1297. #region 解析电机的命令
  1298. else if ((ID == 0x715) || (ID == 0x710))
  1299. {
  1300. switch (CmdTemp)
  1301. {
  1302. case 0x1020://电机运行信息
  1303. {
  1304. unchecked
  1305. {
  1306. this.Invoke((EventHandler)(delegate
  1307. {
  1308. MC_RunInfo_Refresh = true;
  1309. //车速
  1310. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1311. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1312. //输出转速
  1313. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1314. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1315. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1316. Class_MotorSpeed.Data = DataTemp;
  1317. //电功率
  1318. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1319. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1320. //母线电压
  1321. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1322. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1323. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1324. //母线电流
  1325. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1326. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1327. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1328. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1329. Class_CurrentData.Data = DataTemp;
  1330. //踏频
  1331. DataTemp = (ushort)(Data[10]);
  1332. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1333. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1334. Class_CadenceData.Data = DataTemp;
  1335. //踩踏力矩
  1336. DataTemp = (ushort)(Data[11]);
  1337. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1338. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1339. Class_TorqueData.Data = DataTemp;
  1340. //踩踏方向
  1341. DataTemp = (ushort)(Data[12]);
  1342. if (DataTemp == 0)
  1343. {
  1344. textBox_RunInfo_Dir.Text = "正向";
  1345. }
  1346. else if (DataTemp == 1)
  1347. {
  1348. textBox_RunInfo_Dir.Text = "反向";
  1349. }
  1350. else if (DataTemp == 2)
  1351. {
  1352. textBox_RunInfo_Dir.Text = "停止";
  1353. }
  1354. //助力档位
  1355. DataTemp = (ushort)(Data[13]);
  1356. if (DataTemp == 0x33)
  1357. {
  1358. textBox_RunInfo_GearSt.Text = "SMART";
  1359. //comboBox_GearSt.SelectedIndex = 5;
  1360. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1361. }
  1362. else if (DataTemp == 0x22)
  1363. {
  1364. textBox_RunInfo_GearSt.Text = "WALK";
  1365. //comboBox_GearSt.SelectedIndex = 6;
  1366. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1367. }
  1368. else
  1369. {
  1370. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1371. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1372. //comboBox_GearSt.SelectedIndex = DataTemp;
  1373. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1374. }
  1375. //大灯状态
  1376. DataTemp = (ushort)(Data[14]);
  1377. if (DataTemp == 0xF0)
  1378. {
  1379. textBox_RunInfo_LightSwitch.Text = "OFF";
  1380. //comboBox_LightSwitch.SelectedIndex = 1;
  1381. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1382. }
  1383. else if (DataTemp == 0xF1)
  1384. {
  1385. textBox_RunInfo_LightSwitch.Text = "ON";
  1386. //comboBox_LightSwitch.SelectedIndex = 0;
  1387. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1388. }
  1389. //剩余电量
  1390. DataTemp = (ushort)(Data[15]);
  1391. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1392. //剩余续航里程
  1393. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1394. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1395. {
  1396. textBox_RunInfo_Range.Text = "---";
  1397. }
  1398. else
  1399. {
  1400. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1401. }
  1402. //预留(显示力矩Reg),空2bytes
  1403. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1404. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1405. //平均功耗
  1406. DataTemp = (ushort)(Data[20]);
  1407. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1408. //PCB温度
  1409. DataTemp = (ushort)(Data[21]);
  1410. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1411. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1412. Class_MotorTemp.Data = DataTemp - 40;
  1413. //绕组温度
  1414. DataTemp = (ushort)(Data[22]);
  1415. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1416. //MCU温度
  1417. DataTemp = (ushort)(Data[23]);
  1418. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1419. //单次里程
  1420. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1421. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1422. //单次时间
  1423. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1424. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1425. //RSV1
  1426. DataTemp = (ushort)(Data[28]);
  1427. textBox_RunInfo_RSV1.Text = Convert.ToString(DataTemp);
  1428. //RSV2
  1429. DataTemp = (ushort)(Data[29]);
  1430. textBox_RunInfo_RSV2.Text = Convert.ToString(DataTemp);
  1431. //RSV3
  1432. DataTemp = (ushort)(Data[30]);
  1433. textBox_RunInfo_RSV3.Text = Convert.ToString(DataTemp);
  1434. //GearBox
  1435. DataTemp = (ushort)(Data[31]);
  1436. textBox_RunInfo_GearBox.Text = Convert.ToString(DataTemp);
  1437. //数据保存
  1438. RunInfoAutoSave();
  1439. }));
  1440. }
  1441. break;
  1442. }
  1443. case 0x1104://故障码
  1444. {
  1445. unchecked
  1446. {
  1447. this.Invoke((EventHandler)(delegate
  1448. {
  1449. MC_ErrorCode_Refresh = true;
  1450. textBox_ErrorCode.Text =
  1451. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1452. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1453. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1454. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1455. "H";
  1456. }));
  1457. }
  1458. break;
  1459. }
  1460. case 0xA903://反馈指令
  1461. {
  1462. unchecked
  1463. {
  1464. this.Invoke((EventHandler)(delegate
  1465. {
  1466. if (ACK_DisFlag == true)
  1467. {
  1468. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1469. //关机反馈
  1470. PowerOffAckStatus = true;
  1471. }
  1472. //应答标志置位
  1473. WriteACK = true;
  1474. }));
  1475. }
  1476. break;
  1477. }
  1478. case 0xB226://马达参数
  1479. {
  1480. unchecked
  1481. {
  1482. this.Invoke((EventHandler)(delegate
  1483. {
  1484. richTextBox_MotorParam.Clear();
  1485. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1486. {
  1487. if (i == 6)
  1488. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1489. else
  1490. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1491. }
  1492. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1493. }));
  1494. }
  1495. break;
  1496. }
  1497. case 0xB31A://整车信息
  1498. {
  1499. unchecked
  1500. {
  1501. this.Invoke((EventHandler)(delegate
  1502. {
  1503. richTextBox_BikeParam.Clear();
  1504. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1505. {
  1506. if (i == 9)
  1507. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1508. else
  1509. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1510. //更新前后灯参数
  1511. if (i == 8)
  1512. {
  1513. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1514. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1515. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1516. }
  1517. //更新开关机参数
  1518. else if (i == 11)
  1519. {
  1520. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1521. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1522. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1523. }
  1524. }
  1525. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1526. }));
  1527. }
  1528. break;
  1529. }
  1530. case 0xB420://控制器参数
  1531. {
  1532. unchecked
  1533. {
  1534. this.Invoke((EventHandler)(delegate
  1535. {
  1536. richTextBox_ControlParam.Clear();
  1537. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1538. {
  1539. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1540. //转把定速巡航
  1541. if (i == 13)
  1542. {
  1543. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1544. }
  1545. }
  1546. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1547. }));
  1548. }
  1549. break;
  1550. }
  1551. case 0xB528://传感器参数
  1552. {
  1553. unchecked
  1554. {
  1555. this.Invoke((EventHandler)(delegate
  1556. {
  1557. richTextBox_SensorParam.Clear();
  1558. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1559. {
  1560. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1561. }
  1562. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1563. //更新生产模式页面传感器零点和标定值
  1564. textBox_FacModeSensorADC0.Text = (Data[9] * 256 + Data[8]).ToString();
  1565. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1566. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1567. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1568. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1569. WriteACK = true;
  1570. }));
  1571. }
  1572. break;
  1573. }
  1574. case 0xB64C://助力参数
  1575. {
  1576. unchecked
  1577. {
  1578. this.Invoke((EventHandler)(delegate
  1579. {
  1580. richTextBox_AssistParam.Clear();
  1581. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1582. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1583. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1584. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1585. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1586. {
  1587. if (i < index_1) //数据占用2bytes
  1588. {
  1589. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1590. }
  1591. else if (i <= index_2) //数据占用4bytes
  1592. {
  1593. 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])) + ", ");
  1594. }
  1595. else if (i < index_3) //数据占用2bytes,无符号
  1596. {
  1597. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1598. }
  1599. else if (i <= index_4) //数据占用2bytes,有符号
  1600. {
  1601. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1602. }
  1603. else //数据占用2bytes,无符号
  1604. {
  1605. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1606. }
  1607. }
  1608. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1609. }));
  1610. }
  1611. break;
  1612. }
  1613. case 0xB74C://历史记录
  1614. {
  1615. unchecked
  1616. {
  1617. this.Invoke((EventHandler)(delegate
  1618. {
  1619. richTextBox_Record.Clear();
  1620. for (int i = 0; i < myParams.Record.Count; i++)
  1621. {
  1622. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1623. }
  1624. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1625. }));
  1626. }
  1627. break;
  1628. }
  1629. case 0xB83A://调试参数
  1630. {
  1631. unchecked
  1632. {
  1633. this.Invoke((EventHandler)(delegate
  1634. {
  1635. richTextBox_DebugParam.Clear();
  1636. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1637. {
  1638. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1639. }
  1640. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1641. }));
  1642. }
  1643. break;
  1644. }
  1645. case 0xB904://存储标志
  1646. {
  1647. unchecked
  1648. {
  1649. this.Invoke((EventHandler)(delegate
  1650. {
  1651. ushort Flag = 0;
  1652. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1653. if (Flag == 0)
  1654. {
  1655. radioButton_EE_SaveNo.Checked = true;
  1656. radioButton_EE_SaveYes.Checked = false;
  1657. }
  1658. else
  1659. {
  1660. radioButton_EE_SaveNo.Checked = false;
  1661. radioButton_EE_SaveYes.Checked = true;
  1662. }
  1663. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1664. if (Flag == 0)
  1665. {
  1666. radioButton_SIP_SaveNo.Checked = true;
  1667. radioButton_SIP_SaveYes.Checked = false;
  1668. }
  1669. else
  1670. {
  1671. radioButton_SIP_SaveNo.Checked = false;
  1672. radioButton_SIP_SaveYes.Checked = true;
  1673. }
  1674. }));
  1675. }
  1676. break;
  1677. }
  1678. case 0x1240://电机版本信息
  1679. {
  1680. unchecked
  1681. {
  1682. this.Invoke((EventHandler)(delegate
  1683. {
  1684. //电机型号
  1685. textBox_Model.Text = "";
  1686. textBox_OBC_ReadModel.Text = "";
  1687. textBox_FacModeName.Text = "";
  1688. for (ushort i = 0; i < 16; i++)
  1689. {
  1690. if (Data[i] == 0x2E)
  1691. {
  1692. break;
  1693. }
  1694. textBox_Model.Text += ((char)Data[i]).ToString();
  1695. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1696. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1697. }
  1698. Class_Motor_Ver.Mode = textBox_Model.Text;
  1699. //电机SN
  1700. textBox_SN.Text = "";
  1701. textBox_OBC_ReadSN.Text = "";
  1702. textBox_FacModeNum.Text = "";
  1703. for (ushort i = 0; i < 16; i++)
  1704. {
  1705. if (Data[16 + i] == 0x2E)
  1706. {
  1707. break;
  1708. }
  1709. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1710. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1711. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1712. }
  1713. Class_Motor_Ver.SN = textBox_SN.Text;
  1714. //电机HW
  1715. textBox_HW.Text = "";
  1716. textBox_OBC_ReadHW.Text = "";
  1717. textBox_FacModeHW.Text = "";
  1718. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1719. {
  1720. if (Data[32 + i] == 0x2E)
  1721. {
  1722. break;
  1723. }
  1724. else if (Data[32 + i] == 'r')
  1725. {
  1726. Data[32 + i] = (byte)'.';
  1727. break;
  1728. }
  1729. string strTemp = "";
  1730. strTemp = ((char)Data[32 + i]).ToString();
  1731. textBox_HW.Text += strTemp;
  1732. textBox_OBC_ReadHW.Text += strTemp;
  1733. textBox_FacModeHW.Text += strTemp;
  1734. }
  1735. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1736. {
  1737. if (Data[40 + i] == 0x2E)
  1738. {
  1739. break;
  1740. }
  1741. else if (Data[40 + i] == 'r')
  1742. {
  1743. Data[40 + i] = (byte)'.';
  1744. break;
  1745. }
  1746. string strTemp = "";
  1747. strTemp = ((char)Data[40 + i]).ToString();
  1748. textBox_HW.Text += strTemp;
  1749. textBox_OBC_ReadHW.Text += strTemp;
  1750. textBox_FacModeHW.Text += strTemp;
  1751. }
  1752. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1753. {
  1754. string strTemp = "";
  1755. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1756. textBox_HW.Text += strTemp;
  1757. textBox_OBC_ReadHW.Text += strTemp;
  1758. textBox_FacModeHW.Text += strTemp;
  1759. }
  1760. Class_Motor_Ver.HW = textBox_HW.Text;
  1761. //电机FW
  1762. textBox_FW.Text = "";
  1763. textBox_OBC_ReadFW.Text = "";
  1764. textBox_FacModeFW.Text = "";
  1765. for (ushort i = 0; i < 16; i++)
  1766. {
  1767. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1768. {
  1769. break;
  1770. }
  1771. if (Data[48 + i] == 'r')
  1772. {
  1773. Data[48 + i] = (byte)'.';
  1774. }
  1775. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1776. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1777. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1778. }
  1779. Class_Motor_Ver.FW = textBox_FW.Text;
  1780. }));
  1781. }
  1782. break;
  1783. }
  1784. case 0xA610://自定义1
  1785. {
  1786. unchecked
  1787. {
  1788. this.Invoke((EventHandler)(delegate
  1789. {
  1790. textBox_User1.Text = "";
  1791. for (ushort i = 0; i < 16; i++)
  1792. {
  1793. if (Data[i] == 0x2E)
  1794. {
  1795. break;
  1796. }
  1797. textBox_User1.Text += ((char)Data[i]).ToString();
  1798. }
  1799. }));
  1800. }
  1801. break;
  1802. }
  1803. case 0xA710://自定义2
  1804. {
  1805. unchecked
  1806. {
  1807. this.Invoke((EventHandler)(delegate
  1808. {
  1809. textBox_User2.Text = "";
  1810. for (ushort i = 0; i < 16; i++)
  1811. {
  1812. if (Data[i] == 0x2E)
  1813. {
  1814. break;
  1815. }
  1816. textBox_User2.Text += ((char)Data[i]).ToString();
  1817. }
  1818. }));
  1819. }
  1820. break;
  1821. }
  1822. case 0xA810://自定义1
  1823. {
  1824. unchecked
  1825. {
  1826. this.Invoke((EventHandler)(delegate
  1827. {
  1828. textBox_User3.Text = "";
  1829. for (ushort i = 0; i < 16; i++)
  1830. {
  1831. if (Data[i] == 0x2E)
  1832. {
  1833. break;
  1834. }
  1835. textBox_User3.Text += ((char)Data[i]).ToString();
  1836. }
  1837. }));
  1838. }
  1839. break;
  1840. }
  1841. case 0xA520://生产信息
  1842. {
  1843. unchecked
  1844. {
  1845. this.Invoke((EventHandler)(delegate
  1846. {
  1847. //生产商
  1848. textBox_MAC.Text = "";
  1849. for (ushort i = 0; i < 8; i++)
  1850. {
  1851. if (Data[i] == 0x2E)
  1852. {
  1853. break;
  1854. }
  1855. textBox_MAC.Text += ((char)Data[i]).ToString();
  1856. }
  1857. //生产地
  1858. textBox_MACAdd.Text = "";
  1859. for (ushort i = 0; i < 8; i++)
  1860. {
  1861. if (Data[8 + i] == 0x2E)
  1862. {
  1863. break;
  1864. }
  1865. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1866. }
  1867. //生产日期
  1868. textBox_MACDate.Text = "";
  1869. for (ushort i = 0; i < 8; i++)
  1870. {
  1871. if (Data[16 + i] == 0x2E)
  1872. {
  1873. break;
  1874. }
  1875. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1876. }
  1877. //品牌信息
  1878. textBox_PP.Text = "";
  1879. for (ushort i = 0; i < 8; i++)
  1880. {
  1881. if (Data[24 + i] == 0x2E)
  1882. {
  1883. break;
  1884. }
  1885. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1886. }
  1887. }));
  1888. }
  1889. break;
  1890. }
  1891. case 0xA408://密钥
  1892. {
  1893. unchecked
  1894. {
  1895. this.Invoke((EventHandler)(delegate
  1896. {
  1897. textBox_Key.Text = "";
  1898. for (ushort i = 0; i < 8; i++)
  1899. {
  1900. textBox_Key.Text += ((char)Data[i]).ToString();
  1901. }
  1902. }));
  1903. }
  1904. break;
  1905. }
  1906. case 0xAB09://存储器数据
  1907. case 0xAB0A:
  1908. case 0xAB0B:
  1909. case 0xAB0C:
  1910. {
  1911. unchecked
  1912. {
  1913. this.Invoke((EventHandler)(delegate
  1914. {
  1915. long ByteNum = 0;
  1916. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1917. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1918. {
  1919. for (int i = 0; i < ByteNum; i++)
  1920. {
  1921. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1922. }
  1923. }
  1924. else //根据设置自动转换10进制显示
  1925. {
  1926. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1927. {
  1928. switch (ByteNum)
  1929. {
  1930. case 1:
  1931. {
  1932. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1933. break;
  1934. }
  1935. case 2:
  1936. {
  1937. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1938. break;
  1939. }
  1940. case 3:
  1941. {
  1942. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1943. break;
  1944. }
  1945. case 4:
  1946. {
  1947. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1948. break;
  1949. }
  1950. default:
  1951. {
  1952. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1953. break;
  1954. }
  1955. }
  1956. }
  1957. else //16进制显示
  1958. {
  1959. switch (ByteNum)
  1960. {
  1961. case 1:
  1962. {
  1963. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1964. break;
  1965. }
  1966. case 2:
  1967. {
  1968. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1969. break;
  1970. }
  1971. case 3:
  1972. {
  1973. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1974. break;
  1975. }
  1976. case 4:
  1977. {
  1978. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1979. break;
  1980. }
  1981. default:
  1982. {
  1983. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1984. break;
  1985. }
  1986. }
  1987. }
  1988. }
  1989. }));
  1990. }
  1991. break;
  1992. }
  1993. case 0xAB88://故障日志
  1994. {
  1995. unchecked
  1996. {
  1997. this.Invoke((EventHandler)(delegate
  1998. {
  1999. //电机存储的故障日志,一包128字节包含2条故障日志
  2000. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  2001. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  2002. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  2003. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  2004. //数据显示
  2005. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  2006. }));
  2007. }
  2008. break;
  2009. }
  2010. case 0x1401://在线检测结果
  2011. {
  2012. unchecked
  2013. {
  2014. this.Invoke((EventHandler)(delegate
  2015. {
  2016. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  2017. }));
  2018. }
  2019. break;
  2020. }
  2021. case 0x1510://骑行历史信息
  2022. {
  2023. unchecked
  2024. {
  2025. this.Invoke((EventHandler)(delegate
  2026. {
  2027. long DataTemp32;
  2028. //ODO里程
  2029. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  2030. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2031. textBox_ODO_KM.Text = DataTemp32.ToString();
  2032. //ODO时间
  2033. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  2034. if (DataTemp32 >= 60 * 100000)
  2035. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2036. else
  2037. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2038. textBox_ODO_TIME.Text = DataTemp32.ToString();
  2039. //TRIP里程
  2040. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  2041. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2042. textBox_TRIP_KM.Text = DataTemp32.ToString();
  2043. //TRIP时间
  2044. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  2045. if (DataTemp32 >= 60 * 100000)
  2046. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2047. else
  2048. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2049. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  2050. }));
  2051. }
  2052. break;
  2053. }
  2054. case 0x1720://客户信息
  2055. {
  2056. unchecked
  2057. {
  2058. this.Invoke((EventHandler)(delegate
  2059. {
  2060. //软件标识
  2061. textBox_SP.Text = "";
  2062. textBox_OBC_ReadSP.Text = "";
  2063. textBox_FacModeSP.Text = "";
  2064. for (ushort i = 0; i < 23; i++)
  2065. {
  2066. if (Data[i] == 'r')
  2067. {
  2068. Data[i] = (byte)'.';
  2069. }
  2070. textBox_SP.Text += ((char)Data[i]).ToString();
  2071. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  2072. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2073. }
  2074. //Git提交版本信息
  2075. textBox_FacModeGit.Text = "";
  2076. for (ushort i = 0; i < 9; i++)
  2077. {
  2078. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2079. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2080. }
  2081. Class_Motor_Ver.Special = textBox_SP.Text;
  2082. }));
  2083. }
  2084. break;
  2085. }
  2086. case 0xBA20: //调试信息
  2087. {
  2088. unchecked
  2089. {
  2090. this.Invoke((EventHandler)(delegate
  2091. {
  2092. MC_DebugInfo_Refresh = true;
  2093. //系统状态机
  2094. DataTemp = (short)(Data[0]);
  2095. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2096. //二层状态机
  2097. DataTemp = (short)(Data[1]);
  2098. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2099. //电机状态机
  2100. DataTemp = (short)(Data[2]);
  2101. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2102. //助力状态机
  2103. DataTemp = (short)(Data[3]);
  2104. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2105. //IdRef
  2106. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2107. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2108. //IqRef
  2109. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2110. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2111. //UdRef
  2112. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2113. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2114. //UqRef
  2115. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2116. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2117. //瞬时力矩
  2118. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2119. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2120. //时间滤波力矩
  2121. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2122. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2123. //踏频滤波力矩
  2124. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2125. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2126. //IdFdb
  2127. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2128. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2129. //IqFdb
  2130. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2131. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2132. //助力输出
  2133. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2134. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2135. //转把百分比
  2136. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2137. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2138. //数据保存
  2139. RunInfoAutoSave();
  2140. }));
  2141. }
  2142. break;
  2143. }
  2144. case 0xBB20: //产品标签信息
  2145. {
  2146. unchecked
  2147. {
  2148. this.Invoke((EventHandler)(delegate
  2149. {
  2150. //产品标签
  2151. textBox_TagInfo.Text = "";
  2152. for (ushort i = 0; i < 32; i++)
  2153. {
  2154. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2155. }
  2156. }));
  2157. }
  2158. break;
  2159. }
  2160. case 0xBC20: //内阻校正信息
  2161. {
  2162. unchecked
  2163. {
  2164. this.Invoke((EventHandler)(delegate
  2165. {
  2166. //内阻1
  2167. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2168. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2169. //内阻2
  2170. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2171. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2172. //内阻3
  2173. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2174. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2175. //K1
  2176. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2177. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2178. //K2
  2179. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2180. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2181. //K3
  2182. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2183. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2184. //K4
  2185. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2186. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2187. //K5
  2188. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2189. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2190. }));
  2191. }
  2192. break;
  2193. }
  2194. case 0xBD20: //整车信息2
  2195. {
  2196. unchecked
  2197. {
  2198. this.Invoke((EventHandler)(delegate
  2199. {
  2200. richTextBox_BikeParam2.Clear();
  2201. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2202. {
  2203. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2204. }
  2205. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2206. }));
  2207. }
  2208. break;
  2209. }
  2210. case 0xBE20: //用户骑行参数
  2211. {
  2212. unchecked
  2213. {
  2214. this.Invoke((EventHandler)(delegate
  2215. {
  2216. richTextBox_UsrRidesParam.Clear();
  2217. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2218. {
  2219. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2220. }
  2221. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2222. }));
  2223. }
  2224. break;
  2225. }
  2226. case 0xBF58: //位置传感器校准值
  2227. {
  2228. unchecked
  2229. {
  2230. this.Invoke((EventHandler)(delegate
  2231. {
  2232. string[] str1 = new string[42];
  2233. double[] error1 = new double[42];
  2234. //更新校准数据
  2235. for (int i = 0; i < 42; i++)
  2236. {
  2237. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2238. error1[i] = data1 - (60 * (i % 6) + 60);
  2239. if (error1[i] < -180)
  2240. {
  2241. error1[i] = error1[i] + 360;
  2242. }
  2243. str1[i] = data1.ToString("F2");
  2244. AngledataRecord[i] = str1[i];
  2245. }
  2246. for (int i = 0; i < 7; i++)
  2247. for (int j = 0; j < 6; j++)
  2248. {
  2249. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2250. }
  2251. //计算偏差最小值、最大值和平均值
  2252. //Array.ConvertAll(error1, Math.Abs);
  2253. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2254. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2255. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2256. //计算零点偏差
  2257. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2258. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2259. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2260. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2261. double tmp3 = (tmp2 - tmp1);
  2262. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2263. }));
  2264. }
  2265. break;
  2266. }
  2267. case 0xC008: //故障日志地址
  2268. {
  2269. unchecked
  2270. {
  2271. this.Invoke((EventHandler)(delegate
  2272. {
  2273. uint Addr_Begin = 0, Addr_End = 0;
  2274. Addr_Begin = (uint)((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]);
  2275. Addr_End = (uint)((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]);
  2276. textBox_LogAddrBegin.Text = Convert.ToString(Addr_Begin, 16).PadLeft(8, '0').ToUpper();
  2277. textBox_LogAddrEnd.Text = Convert.ToString(Addr_End, 16).PadLeft(8, '0').ToUpper();
  2278. }));
  2279. }
  2280. break;
  2281. }
  2282. case 0xC109: //Boot版本信息
  2283. {
  2284. BootInfo = "";
  2285. for (ushort i = 0; i < 9; i++)
  2286. {
  2287. BootInfo += ((char)Data[i]).ToString();
  2288. }
  2289. break;
  2290. }
  2291. case 0xC142: //功能配置表
  2292. {
  2293. unchecked
  2294. {
  2295. this.Invoke((EventHandler)(delegate
  2296. {
  2297. //块编号
  2298. ushort Num = (ushort)(Data[1] * 256 + Data[0]);
  2299. comboBox_FunSet_BlockNum.SelectedIndex = Num - 1;
  2300. //显示数据
  2301. for (int i = 0; i < 64; i++)
  2302. {
  2303. dataGridView_FunSet.Rows[i / 8].Cells[i % 8 + 1].Value = Data[i + 2].ToString();
  2304. }
  2305. }));
  2306. }
  2307. break;
  2308. }
  2309. case 0xC220: //定制编号
  2310. {
  2311. unchecked
  2312. {
  2313. this.Invoke((EventHandler)(delegate
  2314. {
  2315. //定制编号
  2316. textBox_UserNum.Text = "";
  2317. for (ushort i = 0; i < 32; i++)
  2318. {
  2319. textBox_UserNum.Text += ((char)Data[i]).ToString();
  2320. }
  2321. }));
  2322. }
  2323. break;
  2324. }
  2325. default:
  2326. {
  2327. break;
  2328. }
  2329. }
  2330. //存储器导出数据显示
  2331. if ((CmdTemp & 0xFF00) == 0xAB00)
  2332. {
  2333. unchecked
  2334. {
  2335. this.Invoke((EventHandler)(delegate
  2336. {
  2337. long ByteNum = 0;
  2338. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2339. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2340. {
  2341. for (int i = 0; i < ByteNum; i++)
  2342. {
  2343. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2344. }
  2345. }
  2346. }));
  2347. }
  2348. }
  2349. }
  2350. #endregion
  2351. #region 解析BMS广播的命令
  2352. else if (ID == 0x720)
  2353. {
  2354. switch (CmdTemp)
  2355. {
  2356. case 0x1010://BMS运行信息
  2357. {
  2358. unchecked
  2359. {
  2360. this.Invoke((EventHandler)(delegate
  2361. {
  2362. BMS_RunInfo_Refresh = true;
  2363. richTextBox_OBC_BMS_RunInfo.Clear();
  2364. //电压
  2365. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2366. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2367. //电流
  2368. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2369. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2370. //剩余容量
  2371. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2372. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2373. //满充容量
  2374. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2375. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2376. //电芯温度
  2377. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2378. //剩余电量
  2379. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2380. //电池状态
  2381. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2382. //SOH
  2383. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2384. //循环次数
  2385. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2386. }));
  2387. }
  2388. break;
  2389. }
  2390. default: break;
  2391. }
  2392. }
  2393. #endregion
  2394. #region 解析电机发送OBC的命令
  2395. else if (ID == 0x713)
  2396. {
  2397. switch (CmdTemp)
  2398. {
  2399. case 0x5408://电机用户参数
  2400. {
  2401. unchecked
  2402. {
  2403. this.Invoke((EventHandler)(delegate
  2404. {
  2405. richTextBox_OBC_ReadUserInfo.Clear();
  2406. //默认周长
  2407. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2408. //启动模式
  2409. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2410. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2411. //限速
  2412. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2413. //周长微调
  2414. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2415. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2416. //助力方案
  2417. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2418. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2419. //关机时间
  2420. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2421. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2422. //限速微调
  2423. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2424. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2425. //定速巡航
  2426. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2427. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2428. }));
  2429. }
  2430. break;
  2431. }
  2432. case 0x5303://电机应答反馈
  2433. {
  2434. unchecked
  2435. {
  2436. this.Invoke((EventHandler)(delegate
  2437. {
  2438. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2439. }));
  2440. }
  2441. break;
  2442. }
  2443. case 0x5620: //用户骑行参数
  2444. {
  2445. unchecked
  2446. {
  2447. this.Invoke((EventHandler)(delegate
  2448. {
  2449. richTextBox_UsrRidesParam.Clear();
  2450. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2451. {
  2452. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2453. }
  2454. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2455. }));
  2456. }
  2457. break;
  2458. }
  2459. default: break;
  2460. }
  2461. }
  2462. #endregion
  2463. }
  2464. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2465. {
  2466. CmdRevStrTemp = "";
  2467. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2468. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2469. ushort len = (ushort)(CmdTemp & 0x00FF);
  2470. for (int i = 0; i < len ; i++)
  2471. {
  2472. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2473. }
  2474. }
  2475. #endregion
  2476. /// <summary>
  2477. /// 端口连接或断开
  2478. /// </summary>
  2479. private void PortConnect()
  2480. {
  2481. bool result = false;
  2482. if (连接ToolStripMenuItem.Text == "连接")
  2483. {
  2484. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2485. if (result)
  2486. {
  2487. toolStripComboBox_ComNum.Enabled = false;
  2488. toolStripComboBox_Baudrate.Enabled = false;
  2489. 刷新ToolStripMenuItem.Enabled = false;
  2490. 连接ToolStripMenuItem.Text = "断开";
  2491. 连接ToolStripMenuItem.Checked = true;
  2492. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2493. label_PortStatus.BackColor = Color.Green;
  2494. }
  2495. }
  2496. else if (连接ToolStripMenuItem.Text == "断开")
  2497. {
  2498. checkBox_OBC_StartSetGearSt.Checked = false;
  2499. checkBox_OBC_StartReadBMS.Checked = false;
  2500. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2501. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2502. toolStripComboBox_ComNum.Enabled = true;
  2503. toolStripComboBox_Baudrate.Enabled = true;
  2504. 刷新ToolStripMenuItem.Enabled = true;
  2505. 连接ToolStripMenuItem.Text = "连接";
  2506. 连接ToolStripMenuItem.Checked = false;
  2507. label_COM_Sta.Text = "连接状态:未连接";
  2508. label_PortStatus.BackColor = Color.Red;
  2509. }
  2510. }
  2511. /// <summary>
  2512. /// 端口连接事件
  2513. /// </summary>
  2514. /// <param name="sender"></param>
  2515. /// <param name="e"></param>
  2516. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2517. {
  2518. PortConnect();
  2519. }
  2520. /// <summary>
  2521. /// 端口号刷新事件
  2522. /// </summary>
  2523. /// <param name="sender"></param>
  2524. /// <param name="e"></param>
  2525. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2526. {
  2527. toolStripComboBox_ComNum.Items.Clear();
  2528. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2529. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2530. }
  2531. /// <summary>
  2532. /// 存储标志修改事件
  2533. /// </summary>
  2534. /// <param name="sender"></param>
  2535. /// <param name="e"></param>
  2536. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2537. {
  2538. if (写入存储ToolStripMenuItem.Checked)
  2539. {
  2540. EnterForm1.ShowDialog();
  2541. try
  2542. {
  2543. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2544. {
  2545. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2546. {
  2547. 写入存储ToolStripMenuItem.Checked = false;
  2548. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2549. }
  2550. else
  2551. {
  2552. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2553. }
  2554. }
  2555. else
  2556. {
  2557. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2558. }
  2559. }
  2560. catch (Exception)
  2561. {
  2562. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2563. }
  2564. }
  2565. else
  2566. {
  2567. 写入存储ToolStripMenuItem.Checked = true;
  2568. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2569. }
  2570. }
  2571. /// <summary>
  2572. /// 1s定时器
  2573. /// </summary>
  2574. /// <param name="sender"></param>
  2575. /// <param name="e"></param>
  2576. private void timer_1s_Tick(object sender, EventArgs e)
  2577. {
  2578. //时间更新
  2579. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2580. //MC_Runinfo超时清除
  2581. if (MC_RunInfo_Refresh == false)
  2582. {
  2583. MC_RunInfo_Refresh_Cnt++;
  2584. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2585. {
  2586. MC_RunInfo_Clear();
  2587. MC_RunInfo_Refresh_Cnt = 0;
  2588. }
  2589. }
  2590. else
  2591. {
  2592. MC_RunInfo_Refresh_Cnt = 0;
  2593. }
  2594. MC_RunInfo_Refresh = false;
  2595. //MC_Debuginfo超时清除
  2596. if (MC_DebugInfo_Refresh == false)
  2597. {
  2598. MC_DebugInfo_Refresh_Cnt++;
  2599. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2600. {
  2601. MC_DebugInfo_Clear();
  2602. MC_DebugInfo_Refresh_Cnt = 0;
  2603. }
  2604. }
  2605. else
  2606. {
  2607. MC_DebugInfo_Refresh_Cnt = 0;
  2608. }
  2609. MC_DebugInfo_Refresh = false;
  2610. //BMS_RunInfo超时清除
  2611. if (BMS_RunInfo_Refresh == false)
  2612. {
  2613. BMS_RunInfo_Refresh_Cnt++;
  2614. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2615. {
  2616. richTextBox_OBC_BMS_RunInfo.Clear();
  2617. BMS_RunInfo_Refresh_Cnt = 0;
  2618. }
  2619. }
  2620. else
  2621. {
  2622. BMS_RunInfo_Refresh_Cnt = 0;
  2623. }
  2624. BMS_RunInfo_Refresh = false;
  2625. //故障码超时清除
  2626. if (MC_ErrorCode_Refresh == false)
  2627. {
  2628. MC_ErrorCode_Refresh_Cnt++;
  2629. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2630. {
  2631. textBox_ErrorCode.Text = "---";
  2632. MC_ErrorCode_Refresh_Cnt = 0;
  2633. }
  2634. }
  2635. else
  2636. {
  2637. MC_ErrorCode_Refresh_Cnt = 0;
  2638. }
  2639. MC_ErrorCode_Refresh = false;
  2640. //CDL连接超时
  2641. if (识别通讯盒ToolStripMenuItem.Checked)
  2642. {
  2643. if (mySerialProcess.CDL_Online_Flag == false)
  2644. {
  2645. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2646. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2647. {
  2648. timer_500ms.Enabled = false;
  2649. MessageBox.Show("连接失败!", "提示");
  2650. timer_500ms.Enabled = true;
  2651. //关闭串口
  2652. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2653. toolStripComboBox_ComNum.Enabled = true;
  2654. toolStripComboBox_Baudrate.Enabled = true;
  2655. 刷新ToolStripMenuItem.Enabled = true;
  2656. 连接ToolStripMenuItem.Text = "连接";
  2657. 连接ToolStripMenuItem.Checked = false;
  2658. label_COM_Sta.Text = "连接状态:未连接";
  2659. label_PortStatus.BackColor = Color.Red;
  2660. }
  2661. }
  2662. }
  2663. //OBC定时发送设置档位
  2664. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2665. {
  2666. var CtrlCode = new byte[2];
  2667. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2668. CtrlCode[0] = 0x33;
  2669. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2670. CtrlCode[0] = 0x22;
  2671. else
  2672. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2673. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2674. CtrlCode[1] = 0xF1;
  2675. else
  2676. CtrlCode[1] = 0xF0;
  2677. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2678. {
  2679. checkBox_OBC_StartSetGearSt.Checked = false;
  2680. }
  2681. }
  2682. //OBC定时发送查询电池
  2683. if (checkBox_OBC_StartReadBMS.Checked == true)
  2684. {
  2685. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2686. {
  2687. checkBox_OBC_StartReadBMS.Checked = false;
  2688. }
  2689. }
  2690. //定时读取存储器
  2691. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2692. {
  2693. var Address = new byte[4];
  2694. UInt32 Address_Begin;
  2695. UInt32 Addres_End;
  2696. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2697. richTextBox_RamFlasgData.Clear();
  2698. do
  2699. {
  2700. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2701. {
  2702. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2703. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2704. continue;
  2705. }
  2706. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2707. {
  2708. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2709. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2710. continue;
  2711. }
  2712. else
  2713. {
  2714. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2715. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2716. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2717. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2718. if (Addres_End < Address_Begin)
  2719. {
  2720. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2721. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2722. continue;
  2723. }
  2724. else
  2725. {
  2726. var SendByte = new byte[8];
  2727. SendByte[0] = (byte)(Address_Begin >> 24);
  2728. SendByte[1] = (byte)(Address_Begin >> 16);
  2729. SendByte[2] = (byte)(Address_Begin >> 8);
  2730. SendByte[3] = (byte)(Address_Begin);
  2731. SendByte[4] = (byte)(Addres_End >> 24);
  2732. SendByte[5] = (byte)(Addres_End >> 16);
  2733. SendByte[6] = (byte)(Addres_End >> 8);
  2734. SendByte[7] = (byte)(Addres_End);
  2735. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2736. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2737. }
  2738. }
  2739. } while (false);
  2740. }
  2741. //写入参数等待计时
  2742. ACK_WaitCnt++;
  2743. }
  2744. /// <summary>
  2745. /// 运行信息清除
  2746. /// </summary>
  2747. private void MC_RunInfo_Clear()
  2748. {
  2749. foreach (Control c in tabPage_RunInfo.Controls)
  2750. {
  2751. if ((c is TextBox))
  2752. {
  2753. if (c.Name != textBox_ErrorCode.ToString())
  2754. c.Text = "---";
  2755. }
  2756. }
  2757. }
  2758. /// <summary>
  2759. /// 调试信息清除
  2760. /// </summary>
  2761. private void MC_DebugInfo_Clear()
  2762. {
  2763. foreach (Control c in tabPage_DebugInfo.Controls)
  2764. {
  2765. if ((c is TextBox))
  2766. {
  2767. if (c.Name != textBox_ErrorCode.ToString())
  2768. c.Text = "---";
  2769. }
  2770. }
  2771. }
  2772. /// <summary>
  2773. /// 读取马达参数
  2774. /// </summary>
  2775. /// <param name="sender"></param>
  2776. /// <param name="e"></param>
  2777. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2778. {
  2779. richTextBox_MotorParam.Clear();
  2780. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2781. }
  2782. /// <summary>
  2783. /// 写入马达参数
  2784. /// </summary>
  2785. /// <param name="sender"></param>
  2786. /// <param name="e"></param>
  2787. private void button_Write_Click(object sender, EventArgs e)
  2788. {
  2789. var ConfigParam = new byte[40];
  2790. for (int i = 0; i < 40; i++)
  2791. ConfigParam[i] = 0;
  2792. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2793. short wDataTemp = 0;
  2794. ushort DataTemp = 0;
  2795. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2796. try
  2797. {
  2798. for (int i = 0; i < strDataTemp.Length; i++)
  2799. {
  2800. if (i == 6)
  2801. {
  2802. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2803. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2804. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2805. }
  2806. else
  2807. {
  2808. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2809. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2810. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2811. }
  2812. }
  2813. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2814. }
  2815. catch (Exception)
  2816. {
  2817. timer_500ms.Enabled = false;
  2818. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2819. timer_500ms.Enabled = true;
  2820. }
  2821. }
  2822. /// <summary>
  2823. /// 读取整车信息
  2824. /// </summary>
  2825. /// <param name="sender"></param>
  2826. /// <param name="e"></param>
  2827. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2828. {
  2829. richTextBox_BikeParam.Clear();
  2830. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2831. }
  2832. /// <summary>
  2833. /// 写入整车信息
  2834. /// </summary>
  2835. /// <param name="sender"></param>
  2836. /// <param name="e"></param>
  2837. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2838. {
  2839. var ConfigParam = new byte[28];
  2840. for (int i = 0; i < 28; i++)
  2841. ConfigParam[i] = 0;
  2842. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2843. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2844. try
  2845. {
  2846. for (int i = 0; i < strDataTemp.Length; i++)
  2847. {
  2848. short wDataTemp = 0;
  2849. //前后灯参数修改
  2850. if (i == 8)
  2851. {
  2852. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2853. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2854. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2855. }
  2856. //开关机参数
  2857. else if (i == 11)
  2858. {
  2859. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2860. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2861. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2862. }
  2863. else
  2864. {
  2865. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2866. }
  2867. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2868. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2869. }
  2870. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2871. }
  2872. catch (Exception)
  2873. {
  2874. timer_500ms.Enabled = false;
  2875. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2876. timer_500ms.Enabled = true;
  2877. }
  2878. }
  2879. /// <summary>
  2880. /// 读取控制器参数
  2881. /// </summary>
  2882. /// <param name="sender"></param>
  2883. /// <param name="e"></param>
  2884. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2885. {
  2886. richTextBox_ControlParam.Clear();
  2887. comboBox_Bike_CCS.SelectedIndex = 0;
  2888. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2889. }
  2890. /// <summary>
  2891. /// 写入控制器参数
  2892. /// </summary>
  2893. /// <param name="sender"></param>
  2894. /// <param name="e"></param>
  2895. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2896. {
  2897. var ConfigParam = new byte[34];
  2898. for (int i = 0; i < 34; i++)
  2899. ConfigParam[i] = 0;
  2900. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2901. ushort uwDataTemp = 0;
  2902. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2903. try
  2904. {
  2905. for (int i = 0; i < strDataTemp.Length; i++)
  2906. {
  2907. if (i == 13)
  2908. {
  2909. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2910. }
  2911. else
  2912. {
  2913. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2914. }
  2915. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2916. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2917. }
  2918. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2919. }
  2920. catch (Exception)
  2921. {
  2922. timer_500ms.Enabled = false;
  2923. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2924. timer_500ms.Enabled = true;
  2925. }
  2926. }
  2927. /// <summary>
  2928. /// 读取助力参数
  2929. /// </summary>
  2930. /// <param name="sender"></param>
  2931. /// <param name="e"></param>
  2932. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2933. {
  2934. var ConfigParam = new byte[4];
  2935. int AssistNum = 0;
  2936. try
  2937. {
  2938. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2939. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2940. ConfigParam[1] = (byte)(AssistNum >> 8);
  2941. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2942. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2943. ConfigParam[3] = (byte)(AssistNum >> 8);
  2944. richTextBox_AssistParam.Clear();
  2945. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2946. }
  2947. catch (Exception)
  2948. {
  2949. timer_500ms.Enabled = false;
  2950. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2951. timer_500ms.Enabled = true;
  2952. }
  2953. }
  2954. /// <summary>
  2955. /// 写入助力参数
  2956. /// </summary>
  2957. /// <param name="sender"></param>
  2958. /// <param name="e"></param>
  2959. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2960. {
  2961. var ConfigParam = new byte[80];
  2962. for (int i = 0; i < 80; i++)
  2963. ConfigParam[i] = 0;
  2964. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2965. long lDataTemp = 0;
  2966. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2967. int index_1 = 0, index_2 = 0;
  2968. try
  2969. {
  2970. for (int i = 0; i < strDataTemp.Length; i++)
  2971. {
  2972. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2973. {
  2974. index_1 = i;
  2975. break;
  2976. }
  2977. }
  2978. for (int i = 0; i < strDataTemp.Length; i++)
  2979. {
  2980. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2981. {
  2982. index_2 = i;
  2983. break;
  2984. }
  2985. }
  2986. for (int i = 0; i < strDataTemp.Length; i++)
  2987. {
  2988. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2989. if (i < index_1)
  2990. {
  2991. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2992. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2993. }
  2994. else if (i <= index_2)
  2995. {
  2996. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2997. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2998. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2999. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  3000. }
  3001. else
  3002. {
  3003. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  3004. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  3005. }
  3006. }
  3007. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  3008. }
  3009. catch (Exception)
  3010. {
  3011. timer_500ms.Enabled = false;
  3012. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3013. timer_500ms.Enabled = true;
  3014. }
  3015. }
  3016. /// <summary>
  3017. /// 读取调试参数
  3018. /// </summary>
  3019. /// <param name="sender"></param>
  3020. /// <param name="e"></param>
  3021. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  3022. {
  3023. richTextBox_DebugParam.Clear();
  3024. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  3025. }
  3026. /// <summary>
  3027. /// 写入调试参数
  3028. /// </summary>
  3029. /// <param name="sender"></param>
  3030. /// <param name="e"></param>
  3031. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  3032. {
  3033. var ConfigParam = new byte[60];
  3034. for (int i = 0; i < 60; i++)
  3035. ConfigParam[i] = 0;
  3036. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3037. ushort uwDataTemp = 0;
  3038. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3039. try
  3040. {
  3041. for (int i = 0; i < strDataTemp.Length; i++)
  3042. {
  3043. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3044. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3045. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3046. }
  3047. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  3048. }
  3049. catch (Exception)
  3050. {
  3051. timer_500ms.Enabled = false;
  3052. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3053. timer_500ms.Enabled = true;
  3054. }
  3055. }
  3056. /// <summary>
  3057. /// 读取历史
  3058. /// </summary>
  3059. /// <param name="sender"></param>
  3060. /// <param name="e"></param>
  3061. private void button_ReadRecord_Click(object sender, EventArgs e)
  3062. {
  3063. richTextBox_Record.Clear();
  3064. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  3065. }
  3066. /// <summary>
  3067. /// 读取传感器参数
  3068. /// </summary>
  3069. /// <param name="sender"></param>
  3070. /// <param name="e"></param>
  3071. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  3072. {
  3073. richTextBox_SensorParam.Clear();
  3074. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3075. }
  3076. /// <summary>
  3077. /// 写入力矩传感器标定值
  3078. /// </summary>
  3079. /// <param name="sender"></param>
  3080. /// <param name="e"></param>
  3081. private void button_Write_Cal_Click(object sender, EventArgs e)
  3082. {
  3083. var ConfigParam = new byte[4];
  3084. for (int i = 0; i < 4; i++)
  3085. ConfigParam[i] = 0;
  3086. ushort uwDataTemp = 0;
  3087. try
  3088. {
  3089. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  3090. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3091. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3092. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  3093. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3094. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3095. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3096. }
  3097. catch (Exception)
  3098. {
  3099. timer_500ms.Enabled = false;
  3100. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3101. timer_500ms.Enabled = true;
  3102. }
  3103. }
  3104. /// <summary>
  3105. /// 写入传感器参数
  3106. /// </summary>
  3107. /// <param name="sender"></param>
  3108. /// <param name="e"></param>
  3109. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  3110. {
  3111. var ConfigParam = new byte[14];
  3112. for (int i = 0; i < 14; i++)
  3113. ConfigParam[i] = 0;
  3114. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3115. ushort uwDataTemp = 0;
  3116. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3117. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3118. int index = 0;
  3119. try
  3120. {
  3121. for (int i = 0; i < strDataTemp.Length; i++)
  3122. {
  3123. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3124. {
  3125. index = i;
  3126. break;
  3127. }
  3128. }
  3129. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3130. {
  3131. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3132. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3133. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3134. }
  3135. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3136. }
  3137. catch (Exception)
  3138. {
  3139. timer_500ms.Enabled = false;
  3140. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3141. timer_500ms.Enabled = true;
  3142. }
  3143. }
  3144. /// <summary>
  3145. /// 写入型号
  3146. /// </summary>
  3147. /// <param name="sender"></param>
  3148. /// <param name="e"></param>
  3149. private void button_WriteModel_Click(object sender, EventArgs e)
  3150. {
  3151. string Mode = textBox_Model.Text;
  3152. var ModeArray = new byte[16];
  3153. for (ushort i = 0; i < Mode.Length; i++)
  3154. {
  3155. ModeArray[i] = (byte)Mode[i];
  3156. }
  3157. if (Mode.Length < 16)
  3158. {
  3159. ModeArray[Mode.Length] = (byte)'.';
  3160. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3161. {
  3162. ModeArray[Mode.Length + 1 + i] = 0x20;
  3163. }
  3164. }
  3165. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3166. }
  3167. /// <summary>
  3168. /// 写入SN
  3169. /// </summary>
  3170. /// <param name="sender"></param>
  3171. /// <param name="e"></param>
  3172. private void button_WriteSN_Click(object sender, EventArgs e)
  3173. {
  3174. string SN = textBox_SN.Text;
  3175. var SNArray = new byte[16];
  3176. for (ushort i = 0; i < SN.Length; i++)
  3177. {
  3178. SNArray[i] = (byte)SN[i];
  3179. }
  3180. if (SN.Length < 16)
  3181. {
  3182. SNArray[SN.Length] = (byte)'.';
  3183. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3184. {
  3185. SNArray[SN.Length + 1 + i] = 0x20;
  3186. }
  3187. }
  3188. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3189. }
  3190. /// <summary>
  3191. /// 查询版本信息
  3192. /// </summary>
  3193. /// <param name="sender"></param>
  3194. /// <param name="e"></param>
  3195. private void button_ReadVersion_Click(object sender, EventArgs e)
  3196. {
  3197. textBox_Model.Text = "---";
  3198. textBox_SN.Text = "---";
  3199. textBox_HW.Text = "---";
  3200. textBox_FW.Text = "---";
  3201. textBox_SP.Text = "---";
  3202. textBox_OBC_ReadModel.Text = "---";
  3203. textBox_OBC_ReadSN.Text = "---";
  3204. textBox_OBC_ReadHW.Text = "---";
  3205. textBox_OBC_ReadFW.Text = "---";
  3206. textBox_OBC_ReadSP.Text = "---";
  3207. textBox_FacModeName.Text = "---";
  3208. textBox_FacModeNum.Text = "---";
  3209. textBox_FacModeHW.Text = "---";
  3210. textBox_FacModeFW.Text = "---";
  3211. textBox_FacModeSP.Text = "---";
  3212. Class_Motor_Ver.Mode = "---";
  3213. Class_Motor_Ver.SN = "---";
  3214. Class_Motor_Ver.HW = "---";
  3215. Class_Motor_Ver.FW = "---";
  3216. Class_Motor_Ver.Special = "---";
  3217. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3218. }
  3219. /// <summary>
  3220. /// 查询自定义1
  3221. /// </summary>
  3222. /// <param name="sender"></param>
  3223. /// <param name="e"></param>
  3224. private void button_ReadUser1_Click(object sender, EventArgs e)
  3225. {
  3226. textBox_User1.Text = "---";
  3227. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3228. }
  3229. /// <summary>
  3230. /// 查询自定义2
  3231. /// </summary>
  3232. /// <param name="sender"></param>
  3233. /// <param name="e"></param>
  3234. private void button_ReadUser2_Click(object sender, EventArgs e)
  3235. {
  3236. textBox_User2.Text = "---";
  3237. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3238. }
  3239. /// <summary>
  3240. /// 查询自定义3
  3241. /// </summary>
  3242. /// <param name="sender"></param>
  3243. /// <param name="e"></param>
  3244. private void button_ReadUser3_Click(object sender, EventArgs e)
  3245. {
  3246. textBox_User3.Text = "---";
  3247. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3248. }
  3249. /// <summary>
  3250. /// 写入自定义字符串1
  3251. /// </summary>
  3252. /// <param name="sender"></param>
  3253. /// <param name="e"></param>
  3254. private void button_WriteUser1_Click(object sender, EventArgs e)
  3255. {
  3256. string User = textBox_User1.Text;
  3257. var UserArray = new byte[16];
  3258. for (ushort i = 0; i < User.Length; i++)
  3259. {
  3260. UserArray[i] = (byte)User[i];
  3261. }
  3262. if (User.Length < 16)
  3263. {
  3264. UserArray[User.Length] = (byte)'.';
  3265. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3266. {
  3267. UserArray[User.Length + 1 + i] = 0x20;
  3268. }
  3269. }
  3270. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3271. }
  3272. /// <summary>
  3273. /// 写入自定义字符串2
  3274. /// </summary>
  3275. /// <param name="sender"></param>
  3276. /// <param name="e"></param>
  3277. private void button_WriteUser2_Click(object sender, EventArgs e)
  3278. {
  3279. string User = textBox_User2.Text;
  3280. var UserArray = new byte[16];
  3281. for (ushort i = 0; i < User.Length; i++)
  3282. {
  3283. UserArray[i] = (byte)User[i];
  3284. }
  3285. if (User.Length < 16)
  3286. {
  3287. UserArray[User.Length] = (byte)'.';
  3288. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3289. {
  3290. UserArray[User.Length + 1 + i] = 0x20;
  3291. }
  3292. }
  3293. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3294. }
  3295. /// <summary>
  3296. /// 写入自定义字符串3
  3297. /// </summary>
  3298. /// <param name="sender"></param>
  3299. /// <param name="e"></param>
  3300. private void button_WriteUser3_Click(object sender, EventArgs e)
  3301. {
  3302. string User = textBox_User3.Text;
  3303. var UserArray = new byte[16];
  3304. for (ushort i = 0; i < User.Length; i++)
  3305. {
  3306. UserArray[i] = (byte)User[i];
  3307. }
  3308. if (User.Length < 16)
  3309. {
  3310. UserArray[User.Length] = (byte)'.';
  3311. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3312. {
  3313. UserArray[User.Length + 1 + i] = 0x20;
  3314. }
  3315. }
  3316. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3317. }
  3318. /// <summary>
  3319. /// 查询生产信息
  3320. /// </summary>
  3321. /// <param name="sender"></param>
  3322. /// <param name="e"></param>
  3323. private void button_ReadMAC_Click(object sender, EventArgs e)
  3324. {
  3325. textBox_MAC.Text = "---";
  3326. textBox_MACAdd.Text = "---";
  3327. textBox_MACDate.Text = "---";
  3328. textBox_PP.Text = "---";
  3329. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3330. }
  3331. /// <summary>
  3332. /// 写入生产信息
  3333. /// </summary>
  3334. /// <param name="sender"></param>
  3335. /// <param name="e"></param>
  3336. private void button_WriteMac_Click(object sender, EventArgs e)
  3337. {
  3338. var MACArray = new byte[32];
  3339. //填入生产商
  3340. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3341. {
  3342. MACArray[i] = (byte)textBox_MAC.Text[i];
  3343. }
  3344. if (textBox_MAC.Text.Length < 8)
  3345. {
  3346. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3347. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3348. {
  3349. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3350. }
  3351. }
  3352. //填入生产地
  3353. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3354. {
  3355. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3356. }
  3357. if (textBox_MACAdd.Text.Length < 8)
  3358. {
  3359. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3360. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3361. {
  3362. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3363. }
  3364. }
  3365. //填入生产日期
  3366. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3367. {
  3368. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3369. }
  3370. if (textBox_MACDate.Text.Length < 8)
  3371. {
  3372. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3373. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3374. {
  3375. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3376. }
  3377. }
  3378. //填入品牌
  3379. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3380. {
  3381. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3382. }
  3383. if (textBox_PP.Text.Length < 8)
  3384. {
  3385. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3386. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3387. {
  3388. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3389. }
  3390. }
  3391. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3392. }
  3393. /// <summary>
  3394. /// 查询密钥
  3395. /// </summary>
  3396. /// <param name="sender"></param>
  3397. /// <param name="e"></param>
  3398. private void button_ReadKey_Click(object sender, EventArgs e)
  3399. {
  3400. textBox_Key.Text = "---";
  3401. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3402. }
  3403. /// <summary>
  3404. /// 写入校验密钥
  3405. /// </summary>
  3406. /// <param name="sender"></param>
  3407. /// <param name="e"></param>
  3408. private void button_WriteKey_Click(object sender, EventArgs e)
  3409. {
  3410. string Key = textBox_Key.Text;
  3411. var KeyArray = new byte[8];
  3412. if (Key.Length != 8)
  3413. {
  3414. timer_500ms.Enabled = false;
  3415. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3416. timer_500ms.Enabled = true;
  3417. return;
  3418. }
  3419. for (ushort i = 0; i < Key.Length; i++)
  3420. {
  3421. KeyArray[i] = (byte)Key[i];
  3422. }
  3423. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3424. }
  3425. /// <summary>
  3426. /// 查询在线检测结果
  3427. /// </summary>
  3428. /// <param name="sender"></param>
  3429. /// <param name="e"></param>
  3430. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3431. {
  3432. textBox_Online.Text = "---";
  3433. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3434. }
  3435. /// <summary>
  3436. /// 系统清除
  3437. /// </summary>
  3438. /// <param name="sender"></param>
  3439. /// <param name="e"></param>
  3440. private void button_SystemClear_Click(object sender, EventArgs e)
  3441. {
  3442. var Code = new byte[5];
  3443. Code[0] = (byte)'C';
  3444. Code[1] = (byte)'L';
  3445. Code[2] = (byte)'E';
  3446. Code[3] = (byte)'A';
  3447. Code[4] = (byte)'R';
  3448. timer_500ms.Enabled = false;
  3449. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3450. {
  3451. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3452. {
  3453. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3454. {
  3455. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3456. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3457. }
  3458. }
  3459. }
  3460. timer_500ms.Enabled = true;
  3461. }
  3462. /// <summary>
  3463. /// 参数还原
  3464. /// </summary>
  3465. /// <param name="sender"></param>
  3466. /// <param name="e"></param>
  3467. private void button_Recovery_Click(object sender, EventArgs e)
  3468. {
  3469. var Code = new byte[8];
  3470. Code[0] = (byte)'R';
  3471. Code[1] = (byte)'E';
  3472. Code[2] = (byte)'C';
  3473. Code[3] = (byte)'O';
  3474. Code[4] = (byte)'V';
  3475. Code[5] = (byte)'E';
  3476. Code[6] = (byte)'R';
  3477. Code[7] = (byte)'Y';
  3478. timer_500ms.Enabled = false;
  3479. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3480. {
  3481. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3482. {
  3483. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3484. {
  3485. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3486. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3487. }
  3488. }
  3489. }
  3490. timer_500ms.Enabled = true;
  3491. }
  3492. /// <summary>
  3493. /// 系统复位
  3494. /// </summary>
  3495. /// <param name="sender"></param>
  3496. /// <param name="e"></param>
  3497. private void button_Reset_Click(object sender, EventArgs e)
  3498. {
  3499. var Code_Off = new byte[5];
  3500. var Code_Reset = new byte[5];
  3501. Code_Off[0] = (byte)'O';
  3502. Code_Off[1] = (byte)'F';
  3503. Code_Off[2] = (byte)'F';
  3504. Code_Off[3] = (byte)'.';
  3505. Code_Off[4] = (byte)'.';
  3506. Code_Reset[0] = (byte)'R';
  3507. Code_Reset[1] = (byte)'E';
  3508. Code_Reset[2] = (byte)'S';
  3509. Code_Reset[3] = (byte)'E';
  3510. Code_Reset[4] = (byte)'T';
  3511. timer_500ms.Enabled = false;
  3512. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3513. {
  3514. timer_500ms.Enabled = true;
  3515. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3516. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3517. PowerOffAckStatus = false;
  3518. Delay_ms(250);
  3519. int TryCnt = 3;
  3520. while ((TryCnt--) >= 0)
  3521. {
  3522. if (!PowerOffAckStatus)
  3523. {
  3524. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3525. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3526. PowerOffAckStatus = false;
  3527. Delay_ms(250);
  3528. }
  3529. else break;
  3530. }
  3531. if (PowerOffAckStatus)
  3532. {
  3533. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3534. }
  3535. else
  3536. {
  3537. timer_500ms.Enabled = false;
  3538. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3539. timer_500ms.Enabled = true;
  3540. }
  3541. }
  3542. timer_500ms.Enabled = true;
  3543. }
  3544. /// <summary>
  3545. /// 记录清除
  3546. /// </summary>
  3547. /// <param name="sender"></param>
  3548. /// <param name="e"></param>
  3549. private void button_ClearLog_Click(object sender, EventArgs e)
  3550. {
  3551. var Code = new byte[9];
  3552. Code[0] = (byte)'L';
  3553. Code[1] = (byte)'O';
  3554. Code[2] = (byte)'G';
  3555. Code[3] = (byte)' ';
  3556. Code[4] = (byte)'C';
  3557. Code[5] = (byte)'L';
  3558. Code[6] = (byte)'E';
  3559. Code[7] = (byte)'A';
  3560. Code[8] = (byte)'R';
  3561. timer_500ms.Enabled = false;
  3562. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3563. {
  3564. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3565. {
  3566. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3567. {
  3568. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3569. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3570. }
  3571. }
  3572. }
  3573. timer_500ms.Enabled = true;
  3574. }
  3575. /// <summary>
  3576. /// 打开系统计算器
  3577. /// </summary>
  3578. /// <param name="sender"></param>
  3579. /// <param name="e"></param>
  3580. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3581. {
  3582. System.Diagnostics.Process.Start("calc.exe");
  3583. }
  3584. /// <summary>
  3585. ///故障转换和显示
  3586. /// </summary>
  3587. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3588. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3589. "",""};
  3590. private string ErrorInfoDisplay(UInt32 Code)
  3591. {
  3592. string Result = "";
  3593. if (Code == 0)
  3594. {
  3595. Result = "无故障";
  3596. }
  3597. else
  3598. {
  3599. for (int i = 0; i < 32; i++)
  3600. {
  3601. if ((Code & 0x01) == 0x01)
  3602. {
  3603. Result += ErrorInfo[i] + " ";
  3604. }
  3605. Code >>= 1;
  3606. }
  3607. }
  3608. return Result;
  3609. }
  3610. /// <summary>
  3611. /// 鼠标滑过故障码显示具体内容
  3612. /// </summary>
  3613. /// <param name="sender"></param>
  3614. /// <param name="e"></param>
  3615. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3616. {
  3617. // 创建the ToolTip
  3618. ToolTip toolTip1 = new ToolTip();
  3619. // 设置显示样式
  3620. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3621. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3622. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3623. toolTip1.ShowAlways = true;//是否显示提示框
  3624. // 设置伴随的对象.
  3625. string ErrorCode = this.textBox_ErrorCode.Text;
  3626. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3627. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3628. }
  3629. /// <summary>
  3630. /// 数据记录
  3631. /// </summary>
  3632. private void RunInfoAutoSave()
  3633. {
  3634. if (运行信息记录ToolStripMenuItem.Checked == true)
  3635. {
  3636. if (RunInfoSaveFilename == string.Empty)
  3637. {
  3638. return;
  3639. }
  3640. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3641. foreach (Control c in tabPage_RunInfo.Controls)
  3642. {
  3643. if (c is TextBox)
  3644. {
  3645. SaveData += c.Text + " , ";
  3646. }
  3647. }
  3648. foreach (Control c in tabPage_DebugInfo.Controls)
  3649. {
  3650. if (c is TextBox)
  3651. {
  3652. SaveData += c.Text + " , ";
  3653. }
  3654. }
  3655. SaveData += "\r\n";
  3656. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3657. }
  3658. }
  3659. /// <summary>
  3660. /// 打开或关闭数据记录
  3661. /// </summary>
  3662. /// <param name="sender"></param>
  3663. /// <param name="e"></param>
  3664. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3665. {
  3666. if (运行信息记录ToolStripMenuItem.Checked == false)
  3667. {
  3668. if (mySerialProcess.mySerial.IsOpen == true)
  3669. {
  3670. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3671. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3672. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3673. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3674. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3675. 运行信息记录ToolStripMenuItem.Checked = true;
  3676. }
  3677. else
  3678. {
  3679. timer_500ms.Enabled = false;
  3680. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3681. timer_500ms.Enabled = true;
  3682. }
  3683. }
  3684. else
  3685. {
  3686. 运行信息记录ToolStripMenuItem.Checked = false;
  3687. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3688. }
  3689. }
  3690. /// <summary>
  3691. /// 仪表启动控制档位开关事件
  3692. /// </summary>
  3693. /// <param name="sender"></param>
  3694. /// <param name="e"></param>
  3695. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3696. {
  3697. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3698. {
  3699. //检查串口是否打开
  3700. if (!mySerialProcess.mySerial.IsOpen)
  3701. {
  3702. timer_500ms.Enabled = false;
  3703. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3704. timer_500ms.Enabled = true;
  3705. checkBox_OBC_StartSetGearSt.Checked = false;
  3706. return;
  3707. }
  3708. //检查是否选择档位和打开车灯
  3709. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3710. {
  3711. timer_500ms.Enabled = false;
  3712. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3713. timer_500ms.Enabled = true;
  3714. checkBox_OBC_StartSetGearSt.Checked = false;
  3715. return;
  3716. }
  3717. }
  3718. }
  3719. /// <summary>
  3720. /// OBC查询电机用户参数
  3721. /// </summary>
  3722. /// <param name="sender"></param>
  3723. /// <param name="e"></param>
  3724. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3725. {
  3726. richTextBox_OBC_ReadUserInfo.Clear();
  3727. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3728. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3729. }
  3730. /// <summary>
  3731. /// OBC设置电机用户参数
  3732. /// </summary>
  3733. /// <param name="sender"></param>
  3734. /// <param name="e"></param>
  3735. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3736. {
  3737. var UserInfoCode = new byte[8];
  3738. for (int i = 0; i < UserInfoCode.Length; i++)
  3739. UserInfoCode[i] = 0;
  3740. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3741. {
  3742. timer_500ms.Enabled = false;
  3743. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3744. timer_500ms.Enabled = true;
  3745. return;
  3746. }
  3747. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3748. {
  3749. timer_500ms.Enabled = false;
  3750. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3751. timer_500ms.Enabled = true;
  3752. return;
  3753. }
  3754. //周长微调
  3755. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3756. //启动模式
  3757. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3758. //助力方案
  3759. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3760. //自动关机时间
  3761. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3762. //限速微调
  3763. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3764. //定速巡航开关
  3765. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3766. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3767. }
  3768. /// <summary>
  3769. /// OBC查询电机版本信息
  3770. /// </summary>
  3771. /// <param name="sender"></param>
  3772. /// <param name="e"></param>
  3773. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3774. {
  3775. textBox_Model.Text = "---";
  3776. textBox_SN.Text = "---";
  3777. textBox_HW.Text = "---";
  3778. textBox_FW.Text = "---";
  3779. textBox_SP.Text = "---";
  3780. textBox_OBC_ReadModel.Text = "---";
  3781. textBox_OBC_ReadSN.Text = "---";
  3782. textBox_OBC_ReadHW.Text = "---";
  3783. textBox_OBC_ReadFW.Text = "---";
  3784. textBox_OBC_ReadSP.Text = "---";
  3785. textBox_FacModeName.Text = "---";
  3786. textBox_FacModeNum.Text = "---";
  3787. textBox_FacModeHW.Text = "---";
  3788. textBox_FacModeFW.Text = "---";
  3789. textBox_FacModeSP.Text = "---";
  3790. Class_Motor_Ver.Mode = "---";
  3791. Class_Motor_Ver.SN = "---";
  3792. Class_Motor_Ver.HW = "---";
  3793. Class_Motor_Ver.FW = "---";
  3794. Class_Motor_Ver.Special = "---";
  3795. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3796. }
  3797. /// <summary>
  3798. /// OBC读取骑行历史
  3799. /// </summary>
  3800. /// <param name="sender"></param>
  3801. /// <param name="e"></param>
  3802. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3803. {
  3804. textBox_OBC_TRIP_KM.Text = "";
  3805. textBox_OBC_TRIP_TIME.Text = "";
  3806. textBox_OBC_ODO_KM.Text = "";
  3807. textBox_OBC_ODO_TIME.Text = "";
  3808. textBox_ODO_KM.Text = "---";
  3809. textBox_ODO_TIME.Text = "---";
  3810. textBox_TRIP_KM.Text = "---";
  3811. textBox_TRIP_TIME.Text = "---";
  3812. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3813. }
  3814. /// <summary>
  3815. /// OBC清除TRIP里程
  3816. /// </summary>
  3817. /// <param name="sender"></param>
  3818. /// <param name="e"></param>
  3819. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3820. {
  3821. var Code = new byte[5];
  3822. Code[0] = (byte)'C';
  3823. Code[1] = (byte)'L';
  3824. Code[2] = (byte)'E';
  3825. Code[3] = (byte)'A';
  3826. Code[4] = (byte)'R';
  3827. timer_500ms.Enabled = false;
  3828. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3829. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3830. timer_500ms.Enabled = true;
  3831. }
  3832. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3833. {
  3834. if (checkBox_OBC_StartReadBMS.Checked == true)
  3835. {
  3836. //检查串口是否打开
  3837. if (!mySerialProcess.mySerial.IsOpen)
  3838. {
  3839. timer_500ms.Enabled = false;
  3840. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3841. timer_500ms.Enabled = true;
  3842. checkBox_OBC_StartReadBMS.Checked = false;
  3843. return;
  3844. }
  3845. }
  3846. }
  3847. /// <summary>
  3848. /// 写入力矩传感器参数
  3849. /// </summary>
  3850. /// <param name="sender"></param>
  3851. /// <param name="e"></param>
  3852. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3853. {
  3854. var ConfigParam = new byte[46];
  3855. for (int i = 0; i < 14; i++)
  3856. ConfigParam[i] = 0;
  3857. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3858. ushort uwDataTemp = 0;
  3859. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3860. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3861. int index = 0;
  3862. try
  3863. {
  3864. for (int i = 0; i < strDataTemp.Length; i++)
  3865. {
  3866. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3867. {
  3868. index = i;
  3869. break;
  3870. }
  3871. }
  3872. for (int i = 0; i < (index + 1); i++)
  3873. {
  3874. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3875. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3876. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3877. }
  3878. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3879. }
  3880. catch (Exception)
  3881. {
  3882. timer_500ms.Enabled = false;
  3883. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3884. timer_500ms.Enabled = true;
  3885. }
  3886. }
  3887. /// <summary>
  3888. /// 查询存储标志
  3889. /// </summary>
  3890. /// <param name="sender"></param>
  3891. /// <param name="e"></param>
  3892. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3893. {
  3894. radioButton_EE_SaveYes.Checked = false;
  3895. radioButton_EE_SaveNo.Checked = false;
  3896. radioButton_SIP_SaveYes.Checked = false;
  3897. radioButton_SIP_SaveNo.Checked = false;
  3898. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3899. }
  3900. /// <summary>
  3901. /// 写入存储标志
  3902. /// </summary>
  3903. /// <param name="sender"></param>
  3904. /// <param name="e"></param>
  3905. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3906. {
  3907. var SaveFlag = new byte[6];
  3908. for (int i = 0; i < 6; i++)
  3909. SaveFlag[i] = 0;
  3910. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3911. {
  3912. timer_500ms.Enabled = false;
  3913. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3914. timer_500ms.Enabled = true;
  3915. return;
  3916. }
  3917. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3918. {
  3919. timer_500ms.Enabled = false;
  3920. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3921. timer_500ms.Enabled = true;
  3922. return;
  3923. }
  3924. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3925. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3926. SaveFlag[3] = 0;
  3927. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3928. SaveFlag[5] = 0;
  3929. timer_500ms.Enabled = false;
  3930. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3931. {
  3932. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3933. }
  3934. timer_500ms.Enabled = true;
  3935. }
  3936. /// <summary>
  3937. /// 读取指定地址数据
  3938. /// </summary>
  3939. /// <param name="sender"></param>
  3940. /// <param name="e"></param>
  3941. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3942. {
  3943. var Address = new byte[4];
  3944. UInt32 Address_Begin;
  3945. UInt32 Addres_End;
  3946. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3947. richTextBox_RamFlasgData.Clear();
  3948. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3949. {
  3950. timer_500ms.Enabled = false;
  3951. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3952. timer_500ms.Enabled = true;
  3953. return;
  3954. }
  3955. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3956. {
  3957. timer_500ms.Enabled = false;
  3958. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3959. timer_500ms.Enabled = true;
  3960. return;
  3961. }
  3962. else
  3963. {
  3964. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3965. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3966. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3967. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3968. if (Addres_End < Address_Begin)
  3969. {
  3970. timer_500ms.Enabled = false;
  3971. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3972. timer_500ms.Enabled = true;
  3973. return;
  3974. }
  3975. else
  3976. {
  3977. var SendByte = new byte[8];
  3978. SendByte[0] = (byte)(Address_Begin >> 24);
  3979. SendByte[1] = (byte)(Address_Begin >> 16);
  3980. SendByte[2] = (byte)(Address_Begin >> 8);
  3981. SendByte[3] = (byte)(Address_Begin);
  3982. SendByte[4] = (byte)(Addres_End >> 24);
  3983. SendByte[5] = (byte)(Addres_End >> 16);
  3984. SendByte[6] = (byte)(Addres_End >> 8);
  3985. SendByte[7] = (byte)(Addres_End);
  3986. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3987. }
  3988. }
  3989. }
  3990. /// <summary>
  3991. /// 工作模式选择
  3992. /// </summary>
  3993. /// <param name="sender"></param>
  3994. /// <param name="e"></param>
  3995. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3996. {
  3997. var RunMode = new byte[1];
  3998. if (comboBox_WorkMode.Text == "配置模式")
  3999. RunMode[0] = 0x01;
  4000. else if (comboBox_WorkMode.Text == "调试模式")
  4001. RunMode[0] = 0x02;
  4002. else
  4003. RunMode[0] = 0x00;
  4004. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4005. }
  4006. /// <summary>
  4007. /// 助力档位选择
  4008. /// </summary>
  4009. /// <param name="sender"></param>
  4010. /// <param name="e"></param>
  4011. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  4012. {
  4013. var CtrlCode = new byte[2];
  4014. if (comboBox_GearSt.SelectedIndex == 5)//档位
  4015. CtrlCode[0] = 0x33;
  4016. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  4017. CtrlCode[0] = 0x22;
  4018. else
  4019. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  4020. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  4021. CtrlCode[1] = 0xF1;
  4022. else
  4023. CtrlCode[1] = 0xF0;
  4024. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  4025. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  4026. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  4027. Delay_ms(500);
  4028. //设置百分比
  4029. do
  4030. {
  4031. var PercentCode = new byte[1];
  4032. if (comboBox_GearSt.SelectedIndex == 0) //Off
  4033. {
  4034. PercentCode[0] = 0;
  4035. textBox_MotorSpeedPercent.Text = "0";
  4036. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4037. }
  4038. else if (comboBox_GearSt.SelectedIndex == 6) //Walk
  4039. {
  4040. if (comboBox_WorkMode.SelectedIndex != 0)
  4041. {
  4042. PercentCode[0] = 100;
  4043. textBox_MotorSpeedPercent.Text = "100";
  4044. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, PercentCode);
  4045. }
  4046. }
  4047. } while (false);
  4048. }
  4049. /// <summary>
  4050. /// 仪表档位选择
  4051. /// </summary>
  4052. /// <param name="sender"></param>
  4053. /// <param name="e"></param>
  4054. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  4055. {
  4056. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  4057. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  4058. }
  4059. /// <summary>
  4060. /// 生产模式初始化
  4061. /// </summary>
  4062. /// <param name="sender"></param>
  4063. /// <param name="e"></param>
  4064. private void button_FacModeInit_Click(object sender, EventArgs e)
  4065. {
  4066. var Code = new byte[5];
  4067. Code[0] = (byte)'C';
  4068. Code[1] = (byte)'L';
  4069. Code[2] = (byte)'E';
  4070. Code[3] = (byte)'A';
  4071. Code[4] = (byte)'R';
  4072. timer_500ms.Enabled = false;
  4073. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4074. {
  4075. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4076. {
  4077. timer_500ms.Enabled = true;
  4078. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4079. PowerOffAckStatus = false;
  4080. Delay_ms(250);
  4081. int TryCnt = 3;
  4082. while ((TryCnt--) >= 0)
  4083. {
  4084. if (!PowerOffAckStatus)
  4085. {
  4086. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  4087. PowerOffAckStatus = false;
  4088. Delay_ms(250);
  4089. }
  4090. else break;
  4091. }
  4092. if (PowerOffAckStatus)
  4093. {
  4094. timer_500ms.Enabled = false;
  4095. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4096. timer_500ms.Enabled = true;
  4097. }
  4098. else
  4099. {
  4100. timer_500ms.Enabled = false;
  4101. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4102. timer_500ms.Enabled = true;
  4103. }
  4104. timer_500ms.Enabled = true;
  4105. }
  4106. }
  4107. timer_500ms.Enabled = true;
  4108. //清除历史测试记录
  4109. textBox_FacModeSensorADC0.Text = "";
  4110. textBox_FacModeSensorADC1.Text = "";
  4111. textBox_FacModeSensorADC2.Text = "";
  4112. textBox_FacModeSensorADC3.Text = "";
  4113. textBox_FacModeSensorADC4.Text = "";
  4114. LightSwitchStatus = false;
  4115. MotorRunStatus = false;
  4116. textBox_MotorSpeedPercent.Text = "5";
  4117. textBox_FacModeName.Text = "";
  4118. textBox_FacModeNum.Text = "";
  4119. textBox_FacModeHW.Text = "";
  4120. textBox_FacModeFW.Text = "";
  4121. }
  4122. /// <summary>
  4123. /// 生产模式读取传感器参数
  4124. /// </summary>
  4125. /// <param name="sender"></param>
  4126. /// <param name="e"></param>
  4127. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  4128. {
  4129. richTextBox_SensorParam.Clear();
  4130. textBox_FacModeSensorADC0.Text = "";
  4131. textBox_FacModeSensorADC1.Text = "";
  4132. textBox_FacModeSensorADC2.Text = "";
  4133. textBox_FacModeSensorADC3.Text = "";
  4134. textBox_FacModeSensorADC4.Text = "";
  4135. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4136. //零点判断
  4137. label1_TorqueCal0.BackColor = Color.Red;
  4138. WriteACK = false;
  4139. ACK_WaitCnt = 0;
  4140. Delay_ms(200);
  4141. if (WriteACK == true) //力矩读取正常
  4142. {
  4143. WriteACK = false;
  4144. //获取零点
  4145. ushort ZeroNew;
  4146. ZeroNew = (ushort)Convert.ToUInt16(textBox_FacModeSensorADC0.Text);
  4147. //比较零点
  4148. if ((ZeroNew <= TorqueParamsForm.Zero.Max) && (ZeroNew >= TorqueParamsForm.Zero.Min))
  4149. {
  4150. label1_TorqueCal0.BackColor = Color.Green;
  4151. }
  4152. else
  4153. {
  4154. MessageBoxTimeOut.Show("力矩传感器零点超范围!\r\n" + "最新零点:" + ZeroNew.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4155. }
  4156. }
  4157. else //力矩读取不正常
  4158. {
  4159. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4160. }
  4161. }
  4162. /// <summary>
  4163. /// 生产模式传感器标定1
  4164. /// </summary>
  4165. /// <param name="sender"></param>
  4166. /// <param name="e"></param>
  4167. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4168. {
  4169. var ConfigParam = new byte[4];
  4170. for (int i = 0; i < 4; i++)
  4171. ConfigParam[i] = 0;
  4172. ushort uwDataTemp = 0;
  4173. try
  4174. {
  4175. uwDataTemp = 1;//负载序号
  4176. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4177. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4178. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4179. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4180. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4181. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4182. Delay_ms(200);
  4183. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4184. //标定1判断
  4185. label1_TorqueCal1.BackColor = Color.Red;
  4186. WriteACK = false;
  4187. ACK_WaitCnt = 0;
  4188. Delay_ms(200);
  4189. if (WriteACK == true) //力矩读取正常
  4190. {
  4191. WriteACK = false;
  4192. //获取标定1
  4193. ushort K1_T, K1;
  4194. K1_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal1.Text) * 10);
  4195. K1 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC1.Text));
  4196. //比较标定1
  4197. if ((K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min))
  4198. {
  4199. label1_TorqueCal1.BackColor = Color.Green;
  4200. }
  4201. else
  4202. {
  4203. MessageBoxTimeOut.Show("力矩传感器标定1超范围!\r\n" + "加载扭矩:" + K1_T.ToString() + "\r\n标定值:" + K1.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4204. }
  4205. }
  4206. else //力矩读取不正常
  4207. {
  4208. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4209. }
  4210. }
  4211. catch (Exception)
  4212. {
  4213. timer_500ms.Enabled = false;
  4214. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4215. timer_500ms.Enabled = true;
  4216. }
  4217. }
  4218. /// <summary>
  4219. /// 生产模式传感器标定2
  4220. /// </summary>
  4221. /// <param name="sender"></param>
  4222. /// <param name="e"></param>
  4223. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4224. {
  4225. var ConfigParam = new byte[4];
  4226. for (int i = 0; i < 4; i++)
  4227. ConfigParam[i] = 0;
  4228. ushort uwDataTemp = 0;
  4229. try
  4230. {
  4231. uwDataTemp = 2;//负载序号
  4232. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4233. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4234. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4235. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4236. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4237. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4238. Delay_ms(200);
  4239. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4240. //标定2判断
  4241. label1_TorqueCal2.BackColor = Color.Red;
  4242. WriteACK = false;
  4243. ACK_WaitCnt = 0;
  4244. Delay_ms(200);
  4245. if (WriteACK == true) //力矩读取正常
  4246. {
  4247. WriteACK = false;
  4248. //获取标定2
  4249. ushort K2_T, K2;
  4250. K2_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal2.Text) * 10);
  4251. K2 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC2.Text));
  4252. //比较标定1
  4253. if ((K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min))
  4254. {
  4255. label1_TorqueCal2.BackColor = Color.Green;
  4256. }
  4257. else
  4258. {
  4259. MessageBoxTimeOut.Show("力矩传感器标定2超范围!\r\n" + "加载扭矩:" + K2_T.ToString() + "\r\n标定值:" + K2.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4260. }
  4261. }
  4262. else //力矩读取不正常
  4263. {
  4264. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4265. }
  4266. }
  4267. catch (Exception)
  4268. {
  4269. timer_500ms.Enabled = false;
  4270. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4271. timer_500ms.Enabled = true;
  4272. }
  4273. }
  4274. /// <summary>
  4275. /// 生产模式传感器标定3
  4276. /// </summary>
  4277. /// <param name="sender"></param>
  4278. /// <param name="e"></param>
  4279. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4280. {
  4281. var ConfigParam = new byte[4];
  4282. for (int i = 0; i < 4; i++)
  4283. ConfigParam[i] = 0;
  4284. ushort uwDataTemp = 0;
  4285. try
  4286. {
  4287. uwDataTemp = 3;//负载序号
  4288. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4289. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4290. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4291. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4292. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4293. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4294. Delay_ms(200);
  4295. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4296. //标定3判断
  4297. label1_TorqueCal3.BackColor = Color.Red;
  4298. WriteACK = false;
  4299. ACK_WaitCnt = 0;
  4300. Delay_ms(200);
  4301. if (WriteACK == true) //力矩读取正常
  4302. {
  4303. WriteACK = false;
  4304. //获取标定3
  4305. ushort K3_T, K3;
  4306. K3_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal3.Text) * 10);
  4307. K3 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC3.Text));
  4308. //比较标定1
  4309. if ((K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min))
  4310. {
  4311. label1_TorqueCal3.BackColor = Color.Green;
  4312. }
  4313. else
  4314. {
  4315. MessageBoxTimeOut.Show("力矩传感器标定3超范围!\r\n" + "加载扭矩:" + K3_T.ToString() + "\r\n标定值:" + K3.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4316. }
  4317. }
  4318. else //力矩读取不正常
  4319. {
  4320. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4321. }
  4322. }
  4323. catch (Exception)
  4324. {
  4325. timer_500ms.Enabled = false;
  4326. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4327. timer_500ms.Enabled = true;
  4328. }
  4329. }
  4330. /// <summary>
  4331. /// 生产模式传感器标定4
  4332. /// </summary>
  4333. /// <param name="sender"></param>
  4334. /// <param name="e"></param>
  4335. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4336. {
  4337. var ConfigParam = new byte[4];
  4338. for (int i = 0; i < 4; i++)
  4339. ConfigParam[i] = 0;
  4340. ushort uwDataTemp = 0;
  4341. try
  4342. {
  4343. WriteACK = false;
  4344. uwDataTemp = 4;//负载序号
  4345. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4346. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4347. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4348. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4349. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4350. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4351. Delay_ms(200);
  4352. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4353. //标定4判断
  4354. label1_TorqueCal4.BackColor = Color.Red;
  4355. WriteACK = false;
  4356. ACK_WaitCnt = 0;
  4357. Delay_ms(200);
  4358. if (WriteACK == true) //力矩读取正常
  4359. {
  4360. //获取标定4
  4361. ushort K4_T, K4;
  4362. K4_T = (ushort)(Convert.ToUInt16(textBox_FacModeSensorCal4.Text) * 10);
  4363. K4 = (ushort)(Convert.ToUInt16(textBox_FacModeSensorADC4.Text));
  4364. //比较标定1
  4365. if ((K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min))
  4366. {
  4367. label1_TorqueCal4.BackColor = Color.Green;
  4368. }
  4369. else
  4370. {
  4371. MessageBoxTimeOut.Show("力矩传感器标定4超范围!\r\n" + "加载扭矩:" + K4_T.ToString() + "\r\n标定值:" + K4.ToString(), "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4372. }
  4373. }
  4374. else //力矩读取不正常
  4375. {
  4376. MessageBoxTimeOut.Show("读取力矩传感器数据失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  4377. }
  4378. }
  4379. catch (Exception)
  4380. {
  4381. timer_500ms.Enabled = false;
  4382. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4383. timer_500ms.Enabled = true;
  4384. }
  4385. }
  4386. /// <summary>
  4387. /// 生产模式开关灯
  4388. /// </summary>
  4389. /// <param name="sender"></param>
  4390. /// <param name="e"></param>
  4391. bool LightSwitchStatus = false;
  4392. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4393. {
  4394. var CtrlCode = new byte[2];
  4395. CtrlCode[0] = 0x00;
  4396. if (LightSwitchStatus)
  4397. {
  4398. CtrlCode[1] = 0xF0;
  4399. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4400. }
  4401. else
  4402. {
  4403. CtrlCode[1] = 0xF1;
  4404. button_FacModeLightSW.BackColor = Color.Yellow;
  4405. }
  4406. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4407. {
  4408. LightSwitchStatus = !LightSwitchStatus;
  4409. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4410. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4411. }
  4412. }
  4413. /// <summary>
  4414. /// 生产模式电机控制
  4415. /// </summary>
  4416. /// <param name="sender"></param>
  4417. /// <param name="e"></param>
  4418. bool MotorRunStatus = false;
  4419. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4420. {
  4421. string DebugDefaultInfo = "";
  4422. //获取调试信息
  4423. if (richTextBox_DebugParam.Text == string.Empty)
  4424. {
  4425. richTextBox_DebugParam.Clear();
  4426. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4427. }
  4428. Delay_ms(200);
  4429. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4430. //获取参数
  4431. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4432. if (strDataTemp.Length != 29)
  4433. {
  4434. timer_500ms.Enabled = false;
  4435. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4436. timer_500ms.Enabled = true;
  4437. return;
  4438. }
  4439. //设置参数
  4440. var ConfigParam = new byte[60];
  4441. for (int i = 0; i < 60; i++)
  4442. ConfigParam[i] = 0;
  4443. ConfigParam[0] = 0x00;
  4444. ushort uwDataTemp = 0;
  4445. if (!MotorRunStatus) //停止状态
  4446. {
  4447. //设置速度环
  4448. strDataTemp[0] = "整体运行模式=3";
  4449. //发送数据
  4450. try
  4451. {
  4452. for (int i = 0; i < strDataTemp.Length; i++)
  4453. {
  4454. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4455. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4456. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4457. }
  4458. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4459. return;
  4460. }
  4461. catch (Exception)
  4462. {
  4463. timer_500ms.Enabled = false;
  4464. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4465. timer_500ms.Enabled = true;
  4466. }
  4467. Delay_ms(200);
  4468. //设置转速百分比100%
  4469. textBox_MotorSpeedPercent.Text = "100";
  4470. ConfigParam[0] = (byte)100;
  4471. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4472. MotorRunStatus = !MotorRunStatus;
  4473. button_FacModeMotorRun.BackColor = Color.Yellow;
  4474. Delay_ms(200);
  4475. //电机进入配置模式
  4476. var RunMode = new byte[1];
  4477. RunMode[0] = 0x01;
  4478. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4479. }
  4480. else //运转状态
  4481. {
  4482. //设置转速百分比0%
  4483. textBox_MotorSpeedPercent.Text = "0";
  4484. ConfigParam[0] = (byte)0;
  4485. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4486. MotorRunStatus = !MotorRunStatus;
  4487. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4488. Delay_ms(200);
  4489. //还原为原始值
  4490. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4491. try
  4492. {
  4493. for (int i = 0; i < strDataTemp.Length; i++)
  4494. {
  4495. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4496. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4497. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4498. }
  4499. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4500. return;
  4501. }
  4502. catch (Exception)
  4503. {
  4504. timer_500ms.Enabled = false;
  4505. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4506. timer_500ms.Enabled = true;
  4507. }
  4508. Delay_ms(200);
  4509. //电机退出配置模式
  4510. var RunMode = new byte[1];
  4511. RunMode[0] = 0x00;
  4512. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4513. }
  4514. }
  4515. /// <summary>
  4516. /// 生产模式写入型号
  4517. /// </summary>
  4518. /// <param name="sender"></param>
  4519. /// <param name="e"></param>
  4520. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4521. {
  4522. string Mode = textBox_FacModeName.Text;
  4523. var ModeArray = new byte[16];
  4524. for (ushort i = 0; i < Mode.Length; i++)
  4525. {
  4526. ModeArray[i] = (byte)Mode[i];
  4527. }
  4528. if (Mode.Length < 16)
  4529. {
  4530. ModeArray[Mode.Length] = (byte)'.';
  4531. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4532. {
  4533. ModeArray[Mode.Length + 1 + i] = 0x20;
  4534. }
  4535. }
  4536. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4537. }
  4538. /// <summary>
  4539. /// 生产模式写入SN
  4540. /// </summary>
  4541. /// <param name="sender"></param>
  4542. /// <param name="e"></param>
  4543. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4544. {
  4545. string SN = textBox_FacModeNum.Text;
  4546. var SNArray = new byte[16];
  4547. for (ushort i = 0; i < SN.Length; i++)
  4548. {
  4549. SNArray[i] = (byte)SN[i];
  4550. }
  4551. if (SN.Length < 16)
  4552. {
  4553. SNArray[SN.Length] = (byte)'.';
  4554. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4555. {
  4556. SNArray[SN.Length + 1 + i] = 0x20;
  4557. }
  4558. }
  4559. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4560. }
  4561. /// <summary>
  4562. /// 生产模式读取版本信息
  4563. /// </summary>
  4564. /// <param name="sender"></param>
  4565. /// <param name="e"></param>
  4566. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4567. {
  4568. textBox_Model.Text = "---";
  4569. textBox_SN.Text = "---";
  4570. textBox_HW.Text = "---";
  4571. textBox_FW.Text = "---";
  4572. textBox_SP.Text = "---";
  4573. textBox_OBC_ReadModel.Text = "---";
  4574. textBox_OBC_ReadSN.Text = "---";
  4575. textBox_OBC_ReadHW.Text = "---";
  4576. textBox_OBC_ReadFW.Text = "---";
  4577. textBox_OBC_ReadSP.Text = "---";
  4578. textBox_FacModeName.Text = "---";
  4579. textBox_FacModeNum.Text = "---";
  4580. textBox_FacModeHW.Text = "---";
  4581. textBox_FacModeFW.Text = "---";
  4582. textBox_FacModeSP.Text = "---";
  4583. textBox_FacModeGit.Text = "---";
  4584. Class_Motor_Ver.Mode = "---";
  4585. Class_Motor_Ver.SN = "---";
  4586. Class_Motor_Ver.HW = "---";
  4587. Class_Motor_Ver.FW = "---";
  4588. Class_Motor_Ver.Special = "---";
  4589. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4590. }
  4591. /// <summary>
  4592. /// 生产模式写入生产信息
  4593. /// </summary>
  4594. /// <param name="sender"></param>
  4595. /// <param name="e"></param>
  4596. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4597. {
  4598. var MACArray = new byte[32];
  4599. string MacDefaultInfo = "";
  4600. string MacAddDefaultInfo = "";
  4601. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4602. string MacPPDefaultInfo = "";
  4603. do
  4604. {
  4605. //填入生产商
  4606. if (toolStripTextBox_MAC.Text == string.Empty)
  4607. {
  4608. break;
  4609. }
  4610. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4611. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4612. {
  4613. MACArray[i] = (byte)MacDefaultInfo[i];
  4614. }
  4615. if (MacDefaultInfo.Length < 8)
  4616. {
  4617. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4618. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4619. {
  4620. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4621. }
  4622. }
  4623. //填入生产地
  4624. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4625. {
  4626. break;
  4627. }
  4628. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4629. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4630. {
  4631. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4632. }
  4633. if (MacAddDefaultInfo.Length < 8)
  4634. {
  4635. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4636. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4637. {
  4638. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4639. }
  4640. }
  4641. //填入生产日期
  4642. if (toolStripTextBox_MACDate.Text == string.Empty)
  4643. {
  4644. break;
  4645. }
  4646. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4647. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4648. {
  4649. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4650. }
  4651. if (MacDateDefaultInfo.Length < 8)
  4652. {
  4653. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4654. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4655. {
  4656. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4657. }
  4658. }
  4659. //填入产品标识
  4660. if (toolStripTextBox_MACPD.Text == string.Empty)
  4661. {
  4662. break;
  4663. }
  4664. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4665. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4666. {
  4667. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4668. }
  4669. if (MacPPDefaultInfo.Length < 8)
  4670. {
  4671. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4672. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4673. {
  4674. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4675. }
  4676. }
  4677. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4678. return;
  4679. } while (false);
  4680. timer_500ms.Enabled = false;
  4681. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4682. timer_500ms.Enabled = true;
  4683. }
  4684. /// <summary>
  4685. /// 生产模式保存测试页面
  4686. /// </summary>
  4687. /// <param name="sender"></param>
  4688. /// <param name="e"></param>
  4689. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4690. {
  4691. Button_FacModeSaveResult.Text = "存储中…";
  4692. string[] AssistParams = new string[15];
  4693. do
  4694. {
  4695. //读取一次马达参数
  4696. richTextBox_MotorParam.Clear();
  4697. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4698. Delay_ms(100);
  4699. //读取一次整车参数
  4700. richTextBox_BikeParam.Clear();
  4701. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4702. Delay_ms(100);
  4703. //读取一次整车参数2
  4704. richTextBox_BikeParam2.Clear();
  4705. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4706. Delay_ms(100);
  4707. //读取一次控制参数
  4708. richTextBox_ControlParam.Clear();
  4709. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4710. Delay_ms(100);
  4711. //查询传感器
  4712. richTextBox_SensorParam.Clear();
  4713. textBox_FacModeSensorADC0.Text = "";
  4714. textBox_FacModeSensorADC1.Text = "";
  4715. textBox_FacModeSensorADC2.Text = "";
  4716. textBox_FacModeSensorADC3.Text = "";
  4717. textBox_FacModeSensorADC4.Text = "";
  4718. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4719. Delay_ms(100);
  4720. //读取15次助力参数
  4721. for (int i = 1; i <= 15; i++)
  4722. {
  4723. var ConfigParam = new byte[4];
  4724. richTextBox_AssistParam.Clear();
  4725. ConfigParam[0] = (byte)(i & 0xFF);
  4726. ConfigParam[1] = (byte)(i >> 8);
  4727. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4728. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4729. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4730. Delay_ms(200);
  4731. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4732. }
  4733. //读取一次用户骑行参数
  4734. richTextBox_UsrRidesParam.Clear();
  4735. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4736. Delay_ms(100);
  4737. //读取一次调试信息
  4738. richTextBox_DebugParam.Clear();
  4739. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4740. Delay_ms(100);
  4741. //读取一次历史信息
  4742. richTextBox_Record.Clear();
  4743. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4744. Delay_ms(100);
  4745. //读取一次电机运行信息
  4746. var CtrlCode = new byte[2];
  4747. CtrlCode[0] = 0x00;
  4748. CtrlCode[1] = 0xF0;
  4749. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4750. Delay_ms(100);
  4751. //读取一次版本信息
  4752. textBox_Model.Text = "---";
  4753. textBox_SN.Text = "---";
  4754. textBox_HW.Text = "---";
  4755. textBox_FW.Text = "---";
  4756. textBox_OBC_ReadModel.Text = "---";
  4757. textBox_OBC_ReadSN.Text = "---";
  4758. textBox_OBC_ReadHW.Text = "---";
  4759. textBox_OBC_ReadFW.Text = "---";
  4760. textBox_FacModeName.Text = "---";
  4761. textBox_FacModeNum.Text = "---";
  4762. textBox_FacModeHW.Text = "---";
  4763. textBox_FacModeFW.Text = "---";
  4764. Class_Motor_Ver.Mode = "---";
  4765. Class_Motor_Ver.SN = "---";
  4766. Class_Motor_Ver.HW = "---";
  4767. Class_Motor_Ver.FW = "---";
  4768. Class_Motor_Ver.Special = "---";
  4769. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4770. Delay_ms(100);
  4771. //读取一次生产信息
  4772. textBox_MAC.Text = "";
  4773. textBox_MACAdd.Text = "";
  4774. textBox_MACDate.Text = "";
  4775. textBox_PP.Text = "";
  4776. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4777. Delay_ms(100);
  4778. //读取一次自定义信息
  4779. textBox_User1.Text = "---";
  4780. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4781. Delay_ms(100);
  4782. textBox_User2.Text = "---";
  4783. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4784. Delay_ms(100);
  4785. textBox_User3.Text = "---";
  4786. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4787. Delay_ms(100);
  4788. //读取一次密钥
  4789. textBox_Key.Text = "---";
  4790. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4791. Delay_ms(100);
  4792. //读取一次存储标志
  4793. radioButton_EE_SaveYes.Checked = false;
  4794. radioButton_EE_SaveNo.Checked = false;
  4795. radioButton_SIP_SaveYes.Checked = false;
  4796. radioButton_SIP_SaveNo.Checked = false;
  4797. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4798. Delay_ms(100);
  4799. //读取一次MOS内阻校准参数
  4800. foreach (Control c in groupBox21.Controls)
  4801. {
  4802. if (c is TextBox)
  4803. c.Text = "";
  4804. }
  4805. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4806. Delay_ms(100);
  4807. //提示检查
  4808. #if false
  4809. timer_1s.Enabled = false;
  4810. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4811. {
  4812. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4813. timer_1s.Enabled = true;
  4814. return;
  4815. }
  4816. timer_1s.Enabled = true;
  4817. Delay_ms(200);
  4818. #endif
  4819. //判断数据是否有效
  4820. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4821. {
  4822. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4823. break;
  4824. }
  4825. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4826. {
  4827. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4828. break;
  4829. }
  4830. //设置文件存储路径
  4831. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4832. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4833. Save_Path += PD_PathName;
  4834. if (!Directory.Exists(Save_Path))
  4835. Directory.CreateDirectory(Save_Path);
  4836. //保存页面
  4837. string PIC_SaveFileName = "";
  4838. Double scaleX = PrimaryScreen.ScaleX;
  4839. Double scaleY = PrimaryScreen.ScaleY;
  4840. //保存页面
  4841. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4842. Graphics g = Graphics.FromImage(bit);
  4843. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4844. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4845. bit.Save(PIC_SaveFileName);
  4846. //保存数据
  4847. string DataFileName = "";
  4848. string FileInfo = "";
  4849. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4850. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4851. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4852. FileInfo += "\r\n";
  4853. FileInfo += "[电机信息]\r\n";
  4854. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4855. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4856. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4857. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4858. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4859. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4860. FileInfo += "\r\n";
  4861. FileInfo += "[马达参数]\r\n";
  4862. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4863. FileInfo += "\r\n";
  4864. FileInfo += "[整车参数]\r\n";
  4865. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4866. FileInfo += "\r\n";
  4867. FileInfo += "[控制参数]\r\n";
  4868. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4869. FileInfo += "\r\n";
  4870. FileInfo += "[传感器参数]\r\n";
  4871. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4872. FileInfo += "\r\n";
  4873. FileInfo += "[助力参数]\r\n";
  4874. for(int i=0;i<15;i++)
  4875. {
  4876. FileInfo += AssistParams[i] + "\r\n";
  4877. }
  4878. FileInfo += "[调试参数]\r\n";
  4879. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4880. FileInfo += "\r\n";
  4881. FileInfo += "[历史信息]\r\n";
  4882. FileInfo += richTextBox_Record.Text + "\r\n";
  4883. FileInfo += "\r\n";
  4884. FileInfo += "[MOS内阻校准参数]\r\n";
  4885. FileInfo += textBox_MOS_K1.Text + ", ";
  4886. FileInfo += textBox_MOS_K2.Text + ", ";
  4887. FileInfo += textBox_MOS_K3.Text + ", ";
  4888. FileInfo += textBox_MOS_K4.Text + ", ";
  4889. FileInfo += textBox_MOS_K5.Text + ", ";
  4890. FileInfo += textBox_MOS_R1.Text + ", ";
  4891. FileInfo += textBox_MOS_R2.Text + ", ";
  4892. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4893. FileInfo += "\r\n";
  4894. FileInfo += "[整车参数2]\r\n";
  4895. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4896. FileInfo += "\r\n";
  4897. FileInfo += "[用户骑行参数]\r\n";
  4898. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4899. FileInfo += "\r\n";
  4900. FileInfo += "[生产信息]\r\n";
  4901. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4902. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4903. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4904. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4905. FileInfo += "\r\n";
  4906. FileInfo += "[自定义信息]\r\n";
  4907. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4908. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4909. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4910. FileInfo += "\r\n";
  4911. FileInfo += "[校验密钥]\r\n";
  4912. FileInfo += textBox_Key.Text + "\r\n";
  4913. FileInfo += "\r\n";
  4914. FileInfo += "[存储标志]\r\n";
  4915. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4916. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4917. FileInfo += "\r\n";
  4918. FileInfo += Local_HdInformation;
  4919. FileInfo += "\r\n";
  4920. FileInfo += "文件格式: V2.0\r\n";
  4921. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4922. Delay_ms(1000);
  4923. timer_500ms.Enabled = false;
  4924. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4925. timer_500ms.Enabled = true;
  4926. //数据上传
  4927. if (myFtp.IsNetConnected == true)
  4928. {
  4929. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4930. //检查路径
  4931. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4932. {
  4933. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4934. }
  4935. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4936. {
  4937. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4938. }
  4939. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4940. {
  4941. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4942. }
  4943. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4944. {
  4945. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4946. }
  4947. //上传文件
  4948. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4949. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4950. if ((result1 & result2) == true)
  4951. {
  4952. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4953. }
  4954. else
  4955. {
  4956. timer_500ms.Enabled = false;
  4957. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4958. timer_500ms.Enabled = true;
  4959. }
  4960. }
  4961. else
  4962. {
  4963. timer_500ms.Enabled = false;
  4964. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4965. timer_500ms.Enabled = true;
  4966. }
  4967. Button_FacModeSaveResult.Text = "保存数据";
  4968. return;
  4969. } while (false);
  4970. timer_500ms.Enabled = false;
  4971. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4972. timer_500ms.Enabled = true;
  4973. Button_FacModeSaveResult.Text = "保存数据";
  4974. }
  4975. /// <summary>
  4976. /// 工具箱页面保存
  4977. /// </summary>
  4978. /// <param name="sender"></param>
  4979. /// <param name="e"></param>
  4980. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4981. {
  4982. Double scaleX = PrimaryScreen.ScaleX;
  4983. Double scaleY = PrimaryScreen.ScaleY;
  4984. //保存页面
  4985. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4986. Graphics g = Graphics.FromImage(bit);
  4987. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4988. SaveFileDialog sf = new SaveFileDialog();
  4989. sf.Title = "页面保存";
  4990. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4991. sf.Filter = "图片|*.png";
  4992. timer_500ms.Enabled = false;
  4993. if (sf.ShowDialog() == DialogResult.OK)
  4994. {
  4995. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4996. }
  4997. timer_500ms.Enabled = true;
  4998. }
  4999. /// <summary>
  5000. /// 生产模式关机
  5001. /// </summary>
  5002. /// <param name="sender"></param>
  5003. /// <param name="e"></param>
  5004. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  5005. {
  5006. var Code_Off = new byte[5];
  5007. var Code_Reset = new byte[5];
  5008. Code_Off[0] = (byte)'O';
  5009. Code_Off[1] = (byte)'F';
  5010. Code_Off[2] = (byte)'F';
  5011. Code_Off[3] = (byte)'.';
  5012. Code_Off[4] = (byte)'.';
  5013. Code_Reset[0] = (byte)'R';
  5014. Code_Reset[1] = (byte)'E';
  5015. Code_Reset[2] = (byte)'S';
  5016. Code_Reset[3] = (byte)'E';
  5017. Code_Reset[4] = (byte)'T';
  5018. timer_500ms.Enabled = false;
  5019. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  5020. {
  5021. timer_500ms.Enabled = true;
  5022. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5023. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5024. PowerOffAckStatus = false;
  5025. Delay_ms(250);
  5026. int TryCnt = 3;
  5027. while ((TryCnt--) >= 0)
  5028. {
  5029. if (!PowerOffAckStatus)
  5030. {
  5031. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  5032. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  5033. PowerOffAckStatus = false;
  5034. Delay_ms(250);
  5035. }
  5036. else break;
  5037. }
  5038. if (PowerOffAckStatus)
  5039. {
  5040. timer_500ms.Enabled = false;
  5041. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5042. timer_500ms.Enabled = true;
  5043. }
  5044. else
  5045. {
  5046. timer_500ms.Enabled = false;
  5047. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5048. timer_500ms.Enabled = true;
  5049. }
  5050. }
  5051. timer_500ms.Enabled = true;
  5052. }
  5053. //仪表电源键按下
  5054. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  5055. {
  5056. var Code = new byte[2];
  5057. Code[0] = 0;
  5058. Code[1] = 0b00100000;
  5059. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5060. }
  5061. /// <summary>
  5062. /// 仪表加键按下
  5063. /// </summary>
  5064. /// <param name="sender"></param>
  5065. /// <param name="e"></param>
  5066. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  5067. {
  5068. var Code = new byte[2];
  5069. Code[0] = 0;
  5070. Code[1] = 0b00010000;
  5071. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5072. }
  5073. /// <summary>
  5074. /// 仪表减键按下
  5075. /// </summary>
  5076. /// <param name="sender"></param>
  5077. /// <param name="e"></param>
  5078. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  5079. {
  5080. var Code = new byte[2];
  5081. Code[0] = 0;
  5082. Code[1] = 0b00001000;
  5083. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5084. }
  5085. /// <summary>
  5086. /// 仪表Walk键按下
  5087. /// </summary>
  5088. /// <param name="sender"></param>
  5089. /// <param name="e"></param>
  5090. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  5091. {
  5092. var Code = new byte[2];
  5093. Code[0] = 0;
  5094. Code[1] = 0b00000100;
  5095. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5096. }
  5097. /// <summary>
  5098. /// 仪表Light键按下
  5099. /// </summary>
  5100. /// <param name="sender"></param>
  5101. /// <param name="e"></param>
  5102. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  5103. {
  5104. var Code = new byte[2];
  5105. Code[0] = 0;
  5106. Code[1] = 0b00000010;
  5107. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5108. }
  5109. /// <summary>
  5110. /// 仪表Set键按下
  5111. /// </summary>
  5112. /// <param name="sender"></param>
  5113. /// <param name="e"></param>
  5114. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  5115. {
  5116. var Code = new byte[2];
  5117. Code[0] = 0;
  5118. Code[1] = 0b00000001;
  5119. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  5120. }
  5121. /// <summary>
  5122. /// 导出电机故障日志
  5123. /// </summary>
  5124. /// <param name="sender"></param>
  5125. /// <param name="e"></param>
  5126. private void button_ExportLog_Click(object sender, EventArgs e)
  5127. {
  5128. var Address = new byte[4];
  5129. UInt32 Address_Begin;
  5130. UInt32 Addres_End;
  5131. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  5132. string textBox_Address_End = textBox_LogAddrEnd.Text;
  5133. richTextBox_Record.Clear();
  5134. textBox_LogAddrBegin.ReadOnly = true;
  5135. textBox_LogAddrEnd.ReadOnly = true;
  5136. if (!mySerialProcess.mySerial.IsOpen)
  5137. {
  5138. timer_500ms.Enabled = false;
  5139. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5140. timer_500ms.Enabled = true;
  5141. return;
  5142. }
  5143. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  5144. {
  5145. timer_500ms.Enabled = false;
  5146. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5147. timer_500ms.Enabled = true;
  5148. return;
  5149. }
  5150. else
  5151. {
  5152. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  5153. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5154. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  5155. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  5156. if (Addres_End <= Address_Begin)
  5157. {
  5158. timer_500ms.Enabled = false;
  5159. MessageBox.Show("结束地址应大于起始地址!", "提示");
  5160. timer_500ms.Enabled = true;
  5161. return;
  5162. }
  5163. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  5164. {
  5165. timer_500ms.Enabled = false;
  5166. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  5167. timer_500ms.Enabled = true;
  5168. return;
  5169. }
  5170. else
  5171. {
  5172. UInt32 ReadCount = 0;
  5173. button_ExportLog.Text = "导出中...";
  5174. button_ExportLog.Enabled = false;
  5175. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  5176. for (ushort i = 0; i < ReadCount; i++)
  5177. {
  5178. var SendByte = new byte[8];
  5179. UInt32 Address_Temp_Begin;
  5180. UInt32 Address_Temp_End;
  5181. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  5182. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  5183. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  5184. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  5185. SendByte[3] = (byte)(Address_Temp_Begin);
  5186. Address_Temp_End = Address_Temp_Begin + 127;
  5187. SendByte[4] = (byte)(Address_Temp_End >> 24);
  5188. SendByte[5] = (byte)(Address_Temp_End >> 16);
  5189. SendByte[6] = (byte)(Address_Temp_End >> 8);
  5190. SendByte[7] = (byte)(Address_Temp_End);
  5191. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  5192. Delay_ms(200);//Thread.Sleep(200);
  5193. }
  5194. button_ExportLog.Text = "导出日志";
  5195. button_ExportLog.Enabled = true;
  5196. }
  5197. }
  5198. }
  5199. /// <summary>
  5200. /// 保存日志信息
  5201. /// </summary>
  5202. /// <param name="sender"></param>
  5203. /// <param name="e"></param>
  5204. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  5205. {
  5206. string SaveInfo = "";
  5207. if (richTextBox_Record.Text == string.Empty)
  5208. {
  5209. timer_500ms.Enabled = false;
  5210. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5211. timer_500ms.Enabled = true;
  5212. return;
  5213. }
  5214. //获取保存信息
  5215. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  5216. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  5217. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  5218. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  5219. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  5220. SaveInfo += "\r\n";
  5221. SaveInfo += richTextBox_Record.Text;
  5222. //设置保存路径和文件名
  5223. SaveFileDialog sf = new SaveFileDialog();
  5224. sf.Title = "数据保存";
  5225. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  5226. sf.FileName.Replace(" ", "");
  5227. sf.Filter = "日志|*.ttlog";
  5228. if (sf.ShowDialog() == DialogResult.OK)
  5229. {
  5230. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  5231. }
  5232. }
  5233. /// <summary>
  5234. /// 双击修改日志起始地址
  5235. /// </summary>
  5236. /// <param name="sender"></param>
  5237. /// <param name="e"></param>
  5238. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  5239. {
  5240. textBox_LogAddrBegin.ReadOnly = false;
  5241. }
  5242. /// <summary>
  5243. /// 双击修改日志结束地址
  5244. /// </summary>
  5245. /// <param name="sender"></param>
  5246. /// <param name="e"></param>
  5247. private void label88_DoubleClick(object sender, EventArgs e)
  5248. {
  5249. textBox_LogAddrEnd.ReadOnly = false;
  5250. }
  5251. /// <summary>
  5252. /// 存储器自动读取选择
  5253. /// </summary>
  5254. /// <param name="sender"></param>
  5255. /// <param name="e"></param>
  5256. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  5257. {
  5258. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  5259. {
  5260. //检查串口是否打开
  5261. if (!mySerialProcess.mySerial.IsOpen)
  5262. {
  5263. timer_500ms.Enabled = false;
  5264. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5265. timer_500ms.Enabled = true;
  5266. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5267. return;
  5268. }
  5269. }
  5270. }
  5271. /// <summary>
  5272. /// 系统开机按钮
  5273. /// </summary>
  5274. /// <param name="sender"></param>
  5275. /// <param name="e"></param>
  5276. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5277. {
  5278. byte[] Data = new byte[1];
  5279. Data[0] = 0xF1;
  5280. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5281. }
  5282. /// <summary>
  5283. /// 系统关机按钮
  5284. /// </summary>
  5285. /// <param name="sender"></param>
  5286. /// <param name="e"></param>
  5287. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5288. {
  5289. byte[] Data = new byte[1];
  5290. Data[0] = 0xF0;
  5291. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5292. }
  5293. /// <summary>
  5294. /// 连接开机选择
  5295. /// </summary>
  5296. /// <param name="sender"></param>
  5297. /// <param name="e"></param>
  5298. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5299. {
  5300. //输入用户名
  5301. EnterForm1.ShowDialog();
  5302. try
  5303. {
  5304. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5305. {
  5306. if (EnterForm1.comboBox_User.Text == "管理员")
  5307. {
  5308. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5309. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5310. }
  5311. else
  5312. {
  5313. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5314. }
  5315. }
  5316. else
  5317. {
  5318. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5319. }
  5320. }
  5321. catch (Exception)
  5322. {
  5323. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5324. }
  5325. }
  5326. /// <summary>
  5327. /// 断开关机选择
  5328. /// </summary>
  5329. /// <param name="sender"></param>
  5330. /// <param name="e"></param>
  5331. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5332. {
  5333. //输入用户名
  5334. EnterForm1.ShowDialog();
  5335. try
  5336. {
  5337. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5338. {
  5339. if (EnterForm1.comboBox_User.Text == "管理员")
  5340. {
  5341. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5342. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5343. }
  5344. else
  5345. {
  5346. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5347. }
  5348. }
  5349. else
  5350. {
  5351. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5352. }
  5353. }
  5354. catch (Exception)
  5355. {
  5356. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5357. }
  5358. }
  5359. /// <summary>
  5360. /// 识别通讯盒选择
  5361. /// </summary>
  5362. /// <param name="sender"></param>
  5363. /// <param name="e"></param>
  5364. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5365. {
  5366. //输入用户名
  5367. EnterForm1.ShowDialog();
  5368. try
  5369. {
  5370. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5371. {
  5372. if (EnterForm1.comboBox_User.Text == "管理员")
  5373. {
  5374. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5375. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5376. }
  5377. else
  5378. {
  5379. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5380. }
  5381. }
  5382. else
  5383. {
  5384. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5385. }
  5386. }
  5387. catch (Exception)
  5388. {
  5389. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5390. }
  5391. }
  5392. /// <summary>
  5393. /// 将配置信息导出为cfg文件
  5394. /// </summary>
  5395. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5396. {
  5397. if (DeleteFlag)
  5398. {
  5399. if (File.Exists(FileName))
  5400. File.Delete(FileName);
  5401. }
  5402. string CfgFileInfo = "";
  5403. CfgFileInfo += "[PortSet]" + "\r\n";
  5404. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5405. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5406. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5407. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5408. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5409. CfgFileInfo += "\r\n";
  5410. CfgFileInfo += "[Option]" + "\r\n";
  5411. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5412. CfgFileInfo += "\r\n";
  5413. CfgFileInfo += "[ServerSet]" + "\r\n";
  5414. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5415. CfgFileInfo += "\r\n";
  5416. CfgFileInfo += "[MacInfo]" + "\r\n";
  5417. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5418. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5419. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5420. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5421. CfgFileInfo += "\r\n";
  5422. CfgFileInfo += "[LogAddress]" + "\r\n";
  5423. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5424. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5425. CfgFileInfo += "\r\n";
  5426. CfgFileInfo += "[MotorType]" + "\r\n";
  5427. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5428. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5429. CfgFileInfo += "\r\n";
  5430. CfgFileInfo += "[CheckValue]" + "\r\n";
  5431. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5432. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5433. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5434. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5435. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5436. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5437. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5438. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5439. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5440. CfgFileInfo += "\r\n";
  5441. CfgFileInfo += "[MosCalK]" + "\r\n";
  5442. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5443. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5444. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5445. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5446. CfgFileInfo += "\r\n";
  5447. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5448. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5449. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5450. CfgFileInfo += "\r\n";
  5451. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5452. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5453. CfgFileInfo += "\r\n";
  5454. CfgFileInfo += "[AngleCal]" + "\r\n";
  5455. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5456. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5457. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5458. }
  5459. /// <summary>
  5460. /// 配置状态更新,点击时保存
  5461. /// </summary>
  5462. private void ConfigFileSave_Click(object sender, EventArgs e)
  5463. {
  5464. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5465. }
  5466. /// <summary>
  5467. /// 文本框修改结束,回车保存
  5468. /// </summary>
  5469. /// <param name="sender"></param>
  5470. /// <param name="e"></param>
  5471. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5472. {
  5473. if (e.KeyCode == Keys.Enter)
  5474. {
  5475. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5476. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5477. }
  5478. }
  5479. /// <summary>
  5480. /// 弹出扫码按钮
  5481. /// </summary>
  5482. /// <param name="sender"></param>
  5483. /// <param name="e"></param>
  5484. private void button_ScanCode_Click(object sender, EventArgs e)
  5485. {
  5486. Scan scan_form = new Scan();
  5487. scan_form.ShowDialog();
  5488. do
  5489. {
  5490. if (scan_form.textBox_Scan.Text == string.Empty)
  5491. {
  5492. timer_500ms.Enabled = false;
  5493. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5494. timer_500ms.Enabled = true;
  5495. break;
  5496. }
  5497. string ScanInfo = scan_form.textBox_Scan.Text;
  5498. string regexInfo = "";
  5499. string[] InfoList = { "" };
  5500. try
  5501. {
  5502. if (中置电机ToolStripMenuItem.Checked == true)
  5503. {
  5504. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5505. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5506. }
  5507. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5508. {
  5509. if (!ScanInfo.Contains("/")) //老编码规则
  5510. {
  5511. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5512. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5513. string Spec = InfoList[1];
  5514. string Sn = InfoList[2];
  5515. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5516. InfoList[1] = Sn;
  5517. }
  5518. else //新编码规则
  5519. {
  5520. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  5521. {
  5522. { "01", "A" },
  5523. { "02", "B" },
  5524. { "03", "C" },
  5525. { "04", "D" },
  5526. { "05", "E" },
  5527. { "06", "F" },
  5528. { "07", "G" },
  5529. { "08", "H" },
  5530. { "09", "I" }
  5531. };
  5532. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  5533. {
  5534. { "24V", "A" },
  5535. { "36V", "B" },
  5536. { "42V", "C" },
  5537. { "48V", "D" },
  5538. { "52V", "E" },
  5539. { "60V", "F" }
  5540. };
  5541. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5542. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  5543. string Spec = InfoList[1].Replace("-", "").Replace("/","");
  5544. string Sn = InfoList[2];
  5545. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  5546. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  5547. InfoList[1] = Sn;
  5548. }
  5549. }
  5550. }
  5551. catch (Exception)
  5552. {
  5553. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5554. return;
  5555. }
  5556. if (InfoList.Length >= 2)
  5557. {
  5558. //写入型号
  5559. textBox_FacModeName.Text = InfoList[0];
  5560. string Mode = textBox_FacModeName.Text;
  5561. var ModeArray = new byte[16];
  5562. for (ushort i = 0; i < Mode.Length; i++)
  5563. {
  5564. ModeArray[i] = (byte)Mode[i];
  5565. }
  5566. if (Mode.Length < 16)
  5567. {
  5568. ModeArray[Mode.Length] = (byte)'.';
  5569. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5570. {
  5571. ModeArray[Mode.Length + 1 + i] = 0x20;
  5572. }
  5573. }
  5574. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5575. //写入SN
  5576. textBox_FacModeNum.Text = InfoList[1];
  5577. string SN = textBox_FacModeNum.Text;
  5578. var SNArray = new byte[16];
  5579. for (ushort i = 0; i < SN.Length; i++)
  5580. {
  5581. SNArray[i] = (byte)SN[i];
  5582. }
  5583. if (SN.Length < 16)
  5584. {
  5585. SNArray[SN.Length] = (byte)'.';
  5586. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5587. {
  5588. SNArray[SN.Length + 1 + i] = 0x20;
  5589. }
  5590. }
  5591. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5592. }
  5593. else
  5594. {
  5595. timer_500ms.Enabled = false;
  5596. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5597. timer_500ms.Enabled = true;
  5598. break;
  5599. }
  5600. } while (false);
  5601. scan_form.Dispose();
  5602. }
  5603. /// <summary>
  5604. /// 切换电机类型
  5605. /// </summary>
  5606. /// <param name="sender"></param>
  5607. /// <param name="e"></param>
  5608. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5609. {
  5610. 中置电机ToolStripMenuItem.Checked = true;
  5611. 轮毂电机ToolStripMenuItem.Checked = false;
  5612. toolStripTextBox_MACPD.Text = "MM_MC1";
  5613. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5614. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5615. }
  5616. /// <summary>
  5617. /// 切换电机类型
  5618. /// </summary>
  5619. /// <param name="sender"></param>
  5620. /// <param name="e"></param>
  5621. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5622. {
  5623. 中置电机ToolStripMenuItem.Checked = false;
  5624. 轮毂电机ToolStripMenuItem.Checked = true;
  5625. toolStripTextBox_MACPD.Text = "GF_250_1";
  5626. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5627. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5628. }
  5629. /// <summary>
  5630. /// 获取配置文件日期
  5631. /// </summary>
  5632. /// <param name="DisAll"></param>
  5633. private void GetDateList(bool DisAll)
  5634. {
  5635. string[] DateList = { "" };
  5636. //从服务器更新日期列表
  5637. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5638. {
  5639. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5640. }
  5641. //从本地更新日期列表
  5642. else
  5643. {
  5644. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5645. }
  5646. comboBox_FacModeCfgDate.Items.Clear();
  5647. comboBox_CheckModeCfgDate.Items.Clear();
  5648. //日期列表加载
  5649. if (DisAll == true)
  5650. {
  5651. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5652. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5653. comboBox_FacModeCfgDate.Items.Add("---");
  5654. comboBox_CheckModeCfgDate.Items.Add("---");
  5655. foreach (var file in DateList)
  5656. {
  5657. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5658. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5659. }
  5660. }
  5661. else
  5662. {
  5663. if (DateList.Length > 10)
  5664. {
  5665. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5666. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5667. comboBox_FacModeCfgDate.Items.Add("---");
  5668. comboBox_CheckModeCfgDate.Items.Add("---");
  5669. }
  5670. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5671. {
  5672. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5673. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5674. }
  5675. }
  5676. }
  5677. /// <summary>
  5678. /// 获取配置文件列表
  5679. /// </summary>
  5680. /// <param name="date"></param>
  5681. private void GetFileListFrom(string date)
  5682. {
  5683. string[] FileList = { "" };
  5684. //从服务器更新文件列表
  5685. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5686. {
  5687. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5688. }
  5689. else
  5690. {
  5691. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5692. }
  5693. comboBox_CheckModeCfgFile.Items.Clear();
  5694. comboBox_FacModeCfgFile.Items.Clear();
  5695. foreach (var file in FileList)
  5696. {
  5697. if (file.Contains(".ttcfg"))
  5698. {
  5699. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5700. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5701. }
  5702. }
  5703. }
  5704. /// <summary>
  5705. /// 检验模式选择文件日期
  5706. /// </summary>
  5707. /// <param name="sender"></param>
  5708. /// <param name="e"></param>
  5709. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5710. {
  5711. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5712. {
  5713. GetDateList(true);
  5714. }
  5715. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5716. {
  5717. GetDateList(false);
  5718. }
  5719. else
  5720. {
  5721. comboBox_CheckModeCfgFile.Text = "";
  5722. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5723. }
  5724. }
  5725. /// <summary>
  5726. /// 配置模式选择文件日期
  5727. /// </summary>
  5728. /// <param name="sender"></param>
  5729. /// <param name="e"></param>
  5730. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5731. {
  5732. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5733. {
  5734. GetDateList(true);
  5735. }
  5736. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5737. {
  5738. GetDateList(false);
  5739. }
  5740. else
  5741. {
  5742. comboBox_FacModeCfgFile.Text = "";
  5743. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5744. }
  5745. }
  5746. /// <summary>
  5747. /// 选中量产模式
  5748. /// </summary>
  5749. /// <param name="sender"></param>
  5750. /// <param name="e"></param>
  5751. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5752. {
  5753. //更新生产配置文件目录
  5754. GetDateList(false);
  5755. }
  5756. /// <summary>
  5757. /// 量产测试结束
  5758. /// </summary>
  5759. /// <param name=""></param>
  5760. private void FacMode_Stop(bool OK_Flag)
  5761. {
  5762. //打开开始按钮
  5763. button__FacMode_Start.Enabled = true;
  5764. //系统关机
  5765. var Code = new byte[32];//发送的指令数据
  5766. Code[0] = 0xF0;
  5767. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5768. //关闭串口
  5769. //mySerialProcess.SerialClose(false);
  5770. //路径设置
  5771. string LocalSavePath = "";
  5772. string ServerSavePath = "";
  5773. if (OK_Flag)
  5774. {
  5775. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5776. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5777. }
  5778. else
  5779. {
  5780. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5781. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5782. }
  5783. if (Directory.Exists(LocalSavePath) == false)
  5784. {
  5785. Directory.CreateDirectory(LocalSavePath);
  5786. }
  5787. //保存和上传
  5788. string LogSavePath = "";
  5789. string LogSaveFileName = "";
  5790. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_").Replace("/", "-");
  5791. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5792. if (Directory.Exists(LogSavePath) == false)
  5793. {
  5794. Directory.CreateDirectory(LogSavePath);
  5795. }
  5796. //测试页面
  5797. Double scaleX = PrimaryScreen.ScaleX;
  5798. Double scaleY = PrimaryScreen.ScaleY;
  5799. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5800. Graphics g = Graphics.FromImage(bit);
  5801. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5802. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5803. bit.Save(LogSaveFileName);
  5804. //上传测试页面到服务器
  5805. if (myFtp.IsNetConnected == true)
  5806. {
  5807. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5808. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5809. {
  5810. myFtp.MakeDir(ServerSavePath + DateNow);
  5811. }
  5812. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5813. {
  5814. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5815. }
  5816. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5817. if (result == true)
  5818. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5819. }
  5820. else
  5821. {
  5822. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5823. }
  5824. //测试记录
  5825. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5826. string file_str = "";
  5827. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5828. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5829. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5830. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5831. file_str += Local_HdInformation;
  5832. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5833. //上传测试记录到服务器
  5834. if (myFtp.IsNetConnected == true)
  5835. {
  5836. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5837. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5838. {
  5839. myFtp.MakeDir(ServerSavePath + DateNow);
  5840. }
  5841. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5842. {
  5843. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5844. }
  5845. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5846. if (result == true)
  5847. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5848. }
  5849. else
  5850. {
  5851. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5852. }
  5853. //扫码框清空
  5854. textBox_FacModeScan.Text = "";
  5855. }
  5856. /// <summary>
  5857. /// 量产测试开始
  5858. /// </summary>
  5859. /// <param name="sender"></param>
  5860. /// <param name="e"></param>
  5861. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5862. {
  5863. //关闭测试项目编辑
  5864. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5865. foreach (Control c in groupBox2.Controls)
  5866. {
  5867. if (c is CheckBox)
  5868. c.Enabled = false;
  5869. }
  5870. WriteLockStatus = true;
  5871. //检查配置文件
  5872. if (comboBox_FacModeCfgFile.Text == "")
  5873. {
  5874. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5875. return;
  5876. }
  5877. //开始测试
  5878. TestStart();
  5879. }
  5880. /// <summary>
  5881. /// 测试子函数
  5882. /// </summary>
  5883. private void TestStart()
  5884. {
  5885. //初始化标签
  5886. FacModelLabelInit();
  5887. richTextBox_FacModeLog.Clear();
  5888. //按钮禁止操作
  5889. button__FacMode_Start.Enabled = false;
  5890. //记录配置文件
  5891. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5892. //检查打标信息格式
  5893. label_FacModeStatus.Text = "检查扫码信息";
  5894. Delay_ms(500);
  5895. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5896. if (textBox_FacModeScan.Text == string.Empty)
  5897. {
  5898. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5899. button__FacMode_Start.Enabled = true;
  5900. return;
  5901. }
  5902. try
  5903. {
  5904. if (中置电机ToolStripMenuItem.Checked == true)
  5905. {
  5906. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5907. {
  5908. label_FacModeStatus.Text = "存在故障!";
  5909. label_FacModeResult.BackColor = Color.Red;
  5910. label_FacModeResult.Text = "标签格式错误";
  5911. button__FacMode_Start.Enabled = true;
  5912. return;
  5913. }
  5914. }
  5915. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5916. {
  5917. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5918. {
  5919. label_FacModeStatus.Text = "存在故障!";
  5920. label_FacModeResult.BackColor = Color.Red;
  5921. label_FacModeResult.Text = "标签格式错误";
  5922. button__FacMode_Start.Enabled = true;
  5923. return;
  5924. }
  5925. }
  5926. }
  5927. catch (System.Exception)
  5928. {
  5929. label_FacModeStatus.Text = "存在故障!";
  5930. label_FacModeResult.BackColor = Color.Red;
  5931. label_FacModeResult.Text = "标签格式错误";
  5932. button__FacMode_Start.Enabled = true;
  5933. return;
  5934. }
  5935. //打开串口
  5936. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5937. if (!mySerialProcess.mySerial.IsOpen)
  5938. {
  5939. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5940. //按钮禁止操作
  5941. button__FacMode_Start.Enabled = true;
  5942. return;
  5943. }
  5944. //流水号计数
  5945. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5946. serial += 1;
  5947. label_FacModeSerial.Text = serial.ToString();
  5948. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5949. //创建线程,执行测试任务
  5950. Thread th = new Thread(FacModeTest_Task);
  5951. th.Start();
  5952. }
  5953. /// <summary>
  5954. /// 执行一次测试任务
  5955. /// </summary>
  5956. private void FacModeTest_Task()
  5957. {
  5958. //开始测试
  5959. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5960. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5961. //变量定义
  5962. var Code = new byte[255];//发送的指令数据
  5963. label_FacModeStatus.Text = "开始测试";
  5964. BootInfo = "";
  5965. Delay_ms(500);
  5966. label_FacModeStatus.Text = "系统开机";
  5967. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5968. if (uARTToolStripMenuItem.Checked)
  5969. {
  5970. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5971. Code[0] = (byte)'R';
  5972. Code[1] = (byte)'E';
  5973. Code[2] = (byte)'S';
  5974. Code[3] = (byte)'E';
  5975. Code[4] = (byte)'T';
  5976. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5977. Delay_ms(500);
  5978. }
  5979. //发送开机指令
  5980. //确保测试前先关机,发送关机指令再发送开机指令
  5981. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5982. Code[0] = 0xF0;
  5983. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5984. Delay_ms(1500);
  5985. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5986. Code[0] = 0xF1;
  5987. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5988. ACK_WaitCnt = 0;
  5989. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5990. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5991. //检查BOOT版本
  5992. if (BootInfo != string.Empty)
  5993. {
  5994. label_FacModeBootVer.BackColor = Color.Green;
  5995. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5996. Delay_ms(500);
  5997. }
  5998. else
  5999. {
  6000. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  6001. label_FacModeStatus.Text = "存在故障!";
  6002. label_FacModeResult.BackColor = Color.Red;
  6003. label_FacModeResult.Text = "测试异常";
  6004. Delay_ms(500);
  6005. //存储异常并上传
  6006. FacMode_Stop(false);
  6007. return;
  6008. }
  6009. //系统清除
  6010. if (checkBox_FacModeSysClear.Checked)
  6011. {
  6012. do
  6013. {
  6014. #if false
  6015. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6016. {
  6017. Code[0] = 0x00;//5S协议
  6018. Code[1] = 0x00;
  6019. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6020. Delay_ms(500);
  6021. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6022. Delay_ms(500);
  6023. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6024. }
  6025. #endif
  6026. //发送系统清除指令
  6027. label_FacModeStatus.Text = "系统清除";
  6028. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  6029. Code[0] = (byte)'C';
  6030. Code[1] = (byte)'L';
  6031. Code[2] = (byte)'E';
  6032. Code[3] = (byte)'A';
  6033. Code[4] = (byte)'R';
  6034. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6035. WriteACK = false;
  6036. ACK_WaitCnt = 0;
  6037. while (ACK_WaitCnt <= 6); //3s
  6038. //等待系统清除完成指令
  6039. if (WriteACK == true)
  6040. {
  6041. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6042. label_FacModeSysClear.BackColor = Color.Green;
  6043. }
  6044. else
  6045. {
  6046. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  6047. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6048. ACK_WaitCnt = 0;
  6049. while (ACK_WaitCnt <= 6) ; //3s
  6050. //等待系统清除完成指令
  6051. if (WriteACK == true)
  6052. {
  6053. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6054. label_FacModeSysClear.BackColor = Color.Green;
  6055. }
  6056. else
  6057. {
  6058. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  6059. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  6060. ACK_WaitCnt = 0;
  6061. while (ACK_WaitCnt <= 6) ; //3s
  6062. //等待系统清除完成指令
  6063. if (WriteACK == true)
  6064. {
  6065. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  6066. label_FacModeSysClear.BackColor = Color.Green;
  6067. }
  6068. else
  6069. {
  6070. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  6071. label_FacModeStatus.Text = "存在故障!";
  6072. label_FacModeResult.BackColor = Color.Red;
  6073. label_FacModeResult.Text = "测试异常";
  6074. Delay_ms(500);
  6075. //存储异常并上传
  6076. FacMode_Stop(false);
  6077. return;
  6078. }
  6079. }
  6080. }
  6081. BootInfo = "";
  6082. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  6083. if (uARTToolStripMenuItem.Checked)
  6084. {
  6085. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  6086. Code[0] = (byte)'R';
  6087. Code[1] = (byte)'E';
  6088. Code[2] = (byte)'S';
  6089. Code[3] = (byte)'E';
  6090. Code[4] = (byte)'T';
  6091. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  6092. Delay_ms(500);
  6093. }
  6094. //系统清除后需重新开机
  6095. label_FacModeStatus.Text = "重新开机";
  6096. //确保测试前先关机,发送关机指令再发送开机指令
  6097. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  6098. Code[0] = 0xF0;
  6099. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6100. Delay_ms(1500);
  6101. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  6102. Code[0] = 0xF1;
  6103. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6104. ACK_WaitCnt = 0;
  6105. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6106. while (ACK_WaitCnt <= 20); //10s
  6107. //获取Boot版本信息
  6108. if (BootInfo != string.Empty)
  6109. {
  6110. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6111. Delay_ms(500);
  6112. }
  6113. else
  6114. {
  6115. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6116. label_FacModeStatus.Text = "存在故障!";
  6117. label_FacModeResult.BackColor = Color.Red;
  6118. label_FacModeResult.Text = "测试异常";
  6119. Delay_ms(500);
  6120. //存储异常并上传
  6121. FacMode_Stop(false);
  6122. return;
  6123. }
  6124. } while (false);
  6125. }
  6126. else
  6127. {
  6128. label_FacModeSysClear.BackColor = Color.Yellow;
  6129. label_FacModeStatus.Text = "跳过系统清除!";
  6130. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  6131. Delay_ms(500);
  6132. }
  6133. #if false
  6134. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6135. {
  6136. Code[0] = 0x00;//5S协议
  6137. Code[1] = 0x00;
  6138. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6139. Delay_ms(500);
  6140. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6141. Delay_ms(500);
  6142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6143. }
  6144. #endif
  6145. //检查是否有故障
  6146. if (textBox_ErrorCode.Text.Contains("H"))
  6147. {
  6148. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  6149. label_FacModeStatus.Text = "电机存在故障!";
  6150. label_FacModeResult.BackColor = Color.Red;
  6151. label_FacModeResult.Text = "测试异常";
  6152. Delay_ms(500);
  6153. //存储异常并上传
  6154. FacMode_Stop(false);
  6155. return;
  6156. }
  6157. //MOS内阻校准
  6158. if (checkBox_FacMode_MosCal.Checked)
  6159. {
  6160. label_FacModeStatus.Text = "MOS内阻校准";
  6161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  6162. Delay_ms(500);
  6163. //提示进行负载切换
  6164. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  6165. {
  6166. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  6167. label_FacModeStatus.Text = "存在故障!";
  6168. label_FacModeResult.BackColor = Color.Red;
  6169. label_FacModeResult.Text = "测试异常";
  6170. Delay_ms(500);
  6171. //存储异常并上传
  6172. FacMode_Stop(false);
  6173. return;
  6174. }
  6175. //确认后发送校准指令
  6176. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  6177. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  6178. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  6179. ushort uwDataTemp = 0;
  6180. uwDataTemp = Convert.ToUInt16(K[0]);
  6181. Code[2] = (byte)(uwDataTemp & 0xFF);
  6182. Code[3] = (byte)(uwDataTemp >> 8);
  6183. uwDataTemp = Convert.ToUInt16(K[1]);
  6184. Code[4] = (byte)(uwDataTemp & 0xFF);
  6185. Code[5] = (byte)(uwDataTemp >> 8);
  6186. uwDataTemp = Convert.ToUInt16(K[2]);
  6187. Code[6] = (byte)(uwDataTemp & 0xFF);
  6188. Code[7] = (byte)(uwDataTemp >> 8);
  6189. uwDataTemp = Convert.ToUInt16(K[3]);
  6190. Code[8] = (byte)(uwDataTemp & 0xFF);
  6191. Code[9] = (byte)(uwDataTemp >> 8);
  6192. uwDataTemp = Convert.ToUInt16(K[4]);
  6193. Code[10] = (byte)(uwDataTemp & 0xFF);
  6194. Code[11] = (byte)(uwDataTemp >> 8);
  6195. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6196. WriteACK = false;
  6197. ACK_WaitCnt = 0;
  6198. while (ACK_WaitCnt <= 6) ; //3s
  6199. if (WriteACK == true)
  6200. {
  6201. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6202. }
  6203. else
  6204. {
  6205. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  6206. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6207. ACK_WaitCnt = 0;
  6208. while (ACK_WaitCnt <= 6) ; //3s
  6209. if (WriteACK == true)
  6210. {
  6211. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6212. }
  6213. else
  6214. {
  6215. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  6216. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  6217. ACK_WaitCnt = 0;
  6218. while (ACK_WaitCnt <= 6) ; //3s
  6219. if (WriteACK == true)
  6220. {
  6221. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  6222. }
  6223. else
  6224. {
  6225. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  6226. label_FacModeStatus.Text = "存在故障!";
  6227. label_FacModeResult.BackColor = Color.Red;
  6228. label_FacModeResult.Text = "测试异常";
  6229. Delay_ms(500);
  6230. //存储异常并上传
  6231. FacMode_Stop(false);
  6232. return;
  6233. }
  6234. }
  6235. }
  6236. #if false
  6237. //因控制器复位需发送指令重新进入5S协议
  6238. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  6239. {
  6240. Code[0] = 0x00;//5S协议
  6241. Code[1] = 0x00;
  6242. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6243. Delay_ms(500);
  6244. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  6245. Delay_ms(500);
  6246. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  6247. }
  6248. #endif
  6249. //读取显示校准返回数据
  6250. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  6251. foreach (Control c in groupBox21.Controls)
  6252. {
  6253. if (c is TextBox)
  6254. c.Text = "";
  6255. }
  6256. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6257. ACK_WaitCnt = 0;
  6258. while (ACK_WaitCnt <= 2) ; //1s
  6259. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6260. {
  6261. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  6262. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6263. ACK_WaitCnt = 0;
  6264. while (ACK_WaitCnt <= 2) ; //1s
  6265. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6266. {
  6267. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  6268. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  6269. ACK_WaitCnt = 0;
  6270. while (ACK_WaitCnt <= 2) ; //1s
  6271. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  6272. {
  6273. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  6274. label_FacModeStatus.Text = "存在故障!";
  6275. label_FacModeResult.BackColor = Color.Red;
  6276. label_FacModeResult.Text = "测试异常";
  6277. Delay_ms(500);
  6278. //存储异常并上传
  6279. FacMode_Stop(false);
  6280. return;
  6281. }
  6282. }
  6283. }
  6284. else
  6285. {
  6286. 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");
  6287. }
  6288. //与校准返回数据对比
  6289. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  6290. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  6291. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  6292. 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])) &&
  6293. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6294. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6295. )
  6296. {
  6297. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6298. label_FacModeMosCal.BackColor = Color.Green;
  6299. //提示切换负载
  6300. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6301. }
  6302. else
  6303. {
  6304. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6305. label_FacModeStatus.Text = "存在故障!";
  6306. label_FacModeResult.BackColor = Color.Red;
  6307. label_FacModeResult.Text = "测试异常";
  6308. Delay_ms(500);
  6309. //存储异常并上传
  6310. FacMode_Stop(false);
  6311. //提示切换负载
  6312. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6313. return;
  6314. }
  6315. }
  6316. else
  6317. {
  6318. label_FacModeMosCal.BackColor = Color.Yellow;
  6319. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6320. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6321. Delay_ms(500);
  6322. }
  6323. //位置校准
  6324. if (checkBox_FacMode_AngleCal.Checked)
  6325. {
  6326. //校准前进行一次开关机保存初始化数据
  6327. BootInfo = "";
  6328. label_FacModeStatus.Text = "位置校准";
  6329. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6330. //确保测试前先关机,发送关机指令再发送开机指令
  6331. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6332. Code[0] = 0xF0;
  6333. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6334. Delay_ms(1500);
  6335. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6336. Code[0] = 0xF1;
  6337. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6338. ACK_WaitCnt = 0;
  6339. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6340. while (ACK_WaitCnt <= 10) ; //5s
  6341. //获取Boot版本信息
  6342. if (BootInfo != string.Empty)
  6343. {
  6344. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6345. Delay_ms(500);
  6346. }
  6347. else
  6348. {
  6349. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6350. label_FacModeStatus.Text = "存在故障!";
  6351. label_FacModeResult.BackColor = Color.Red;
  6352. label_FacModeResult.Text = "测试异常";
  6353. Delay_ms(500);
  6354. //存储异常并上传
  6355. FacMode_Stop(false);
  6356. return;
  6357. }
  6358. //发送位置校准指令
  6359. for (int i = 0; i < 7; i++)
  6360. for (int j = 0; j < 6; j++)
  6361. {
  6362. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6363. }
  6364. foreach (Control cr in tabPage_AngleCal.Controls)
  6365. {
  6366. if (cr is TextBox)
  6367. {
  6368. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6369. cr.Text = "";
  6370. }
  6371. }
  6372. Code[0] = 0;
  6373. Code[1] = 0;
  6374. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6375. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6376. ACK_WaitCnt = 0;
  6377. while (ACK_WaitCnt <= 50) ; //25s
  6378. //读取位置校准数据
  6379. if (textBox_AngleDiffAvg.Text == string.Empty)
  6380. {
  6381. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6382. label_FacModeStatus.Text = "存在故障!";
  6383. label_FacModeResult.BackColor = Color.Red;
  6384. label_FacModeResult.Text = "测试异常";
  6385. Delay_ms(500);
  6386. //存储异常并上传
  6387. FacMode_Stop(false);
  6388. return;
  6389. }
  6390. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6391. for (int i = 0; i < 7; i++)
  6392. {
  6393. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6394. for (int j = 0; j < 6; j++)
  6395. {
  6396. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6397. }
  6398. richTextBox_FacModeLog.AppendText("\r\n");
  6399. Delay_ms(200);
  6400. }
  6401. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6402. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6403. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6404. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6405. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6406. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6407. //比较位置偏差
  6408. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6409. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6410. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6411. )
  6412. {
  6413. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6414. label_FacModeStatus.Text = "存在故障!";
  6415. label_FacModeResult.BackColor = Color.Red;
  6416. label_FacModeResult.Text = "测试异常";
  6417. Delay_ms(500);
  6418. //存储异常并上传
  6419. FacMode_Stop(false);
  6420. return;
  6421. }
  6422. //写入校准偏差值
  6423. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6424. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6425. if (data1 > 360)
  6426. {
  6427. data1 -= 360;
  6428. }
  6429. else if (data1 < -360)
  6430. {
  6431. data1 += 360;
  6432. }
  6433. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6434. Code[0] = 0x01;
  6435. Code[1] = 0x00;
  6436. Code[2] = (byte)(data2);
  6437. Code[3] = (byte)(data2 >> 8);
  6438. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6439. WriteACK = false;
  6440. ACK_WaitCnt = 0;
  6441. while (ACK_WaitCnt <= 2) ; //1s
  6442. if (WriteACK == true)
  6443. {
  6444. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6445. }
  6446. else
  6447. {
  6448. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6449. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6450. WriteACK = false;
  6451. ACK_WaitCnt = 0;
  6452. while (ACK_WaitCnt <= 2) ; //1s
  6453. if (WriteACK == true)
  6454. {
  6455. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6456. }
  6457. else
  6458. {
  6459. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6460. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6461. WriteACK = false;
  6462. ACK_WaitCnt = 0;
  6463. while (ACK_WaitCnt <= 2) ; //1s
  6464. if (WriteACK == true)
  6465. {
  6466. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6467. }
  6468. else
  6469. {
  6470. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6471. label_FacModeStatus.Text = "存在故障!";
  6472. label_FacModeResult.BackColor = Color.Red;
  6473. label_FacModeResult.Text = "测试异常";
  6474. Delay_ms(500);
  6475. //存储异常并上传
  6476. FacMode_Stop(false);
  6477. return;
  6478. }
  6479. }
  6480. }
  6481. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6482. label_FacModeAngleCal.BackColor = Color.Green;
  6483. }
  6484. else
  6485. {
  6486. label_FacModeAngleCal.BackColor = Color.Yellow;
  6487. label_FacModeStatus.Text = "跳过位置校准!";
  6488. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6489. Delay_ms(500);
  6490. }
  6491. //参数写入
  6492. if (checkBox_FacModeCfgWrite.Checked)
  6493. {
  6494. label_FacModeStatus.Text = "参数写入";
  6495. //写入产品型号和SN
  6496. do
  6497. {
  6498. //根据扫码信息获取型号和SN
  6499. string ScanInfo = textBox_FacModeScan.Text;
  6500. string regexInfo = "";
  6501. string[] InfoList = { "" };
  6502. try
  6503. {
  6504. if (中置电机ToolStripMenuItem.Checked == true)
  6505. {
  6506. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6507. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6508. }
  6509. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6510. {
  6511. if (!ScanInfo.Contains("/")) //老编码规则
  6512. {
  6513. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6514. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6515. string Spec = InfoList[1];
  6516. string Sn = InfoList[2];
  6517. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6518. InfoList[1] = Sn;
  6519. }
  6520. else //新编码规则
  6521. {
  6522. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  6523. {
  6524. { "01", "A" },
  6525. { "02", "B" },
  6526. { "03", "C" },
  6527. { "04", "D" },
  6528. { "05", "E" },
  6529. { "06", "F" },
  6530. { "07", "G" },
  6531. { "08", "H" },
  6532. { "09", "I" }
  6533. };
  6534. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  6535. {
  6536. { "24V", "A" },
  6537. { "36V", "B" },
  6538. { "42V", "C" },
  6539. { "48V", "D" },
  6540. { "52V", "E" },
  6541. { "60V", "F" }
  6542. };
  6543. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6544. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  6545. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  6546. string Sn = InfoList[2];
  6547. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  6548. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  6549. InfoList[1] = Sn;
  6550. }
  6551. }
  6552. }
  6553. catch
  6554. {
  6555. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6556. label_FacModeStatus.Text = "存在故障!";
  6557. label_FacModeResult.BackColor = Color.Red;
  6558. label_FacModeResult.Text = "标签格式错误";
  6559. Delay_ms(500);
  6560. //存储异常并上传
  6561. FacMode_Stop(false);
  6562. return;
  6563. }
  6564. if (InfoList.Length >= 2)
  6565. {
  6566. //检查配置文件是否与打标信息一致
  6567. //...
  6568. //写入型号
  6569. label_FacModeStatus.Text = "写入型号";
  6570. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6571. textBox_FacModeName.Text = InfoList[0];
  6572. string Mode = textBox_FacModeName.Text;
  6573. var ModeArray = new byte[16];
  6574. for (ushort i = 0; i < Mode.Length; i++)
  6575. {
  6576. ModeArray[i] = (byte)Mode[i];
  6577. }
  6578. if (Mode.Length < 16)
  6579. {
  6580. ModeArray[Mode.Length] = (byte)'.';
  6581. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6582. {
  6583. ModeArray[Mode.Length + 1 + i] = 0x20;
  6584. }
  6585. }
  6586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6587. WriteACK = false;
  6588. ACK_WaitCnt = 0;
  6589. while (ACK_WaitCnt <= 2); //1s
  6590. if (WriteACK == true)
  6591. {
  6592. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6593. }
  6594. else
  6595. {
  6596. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6597. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6598. ACK_WaitCnt = 0;
  6599. while (ACK_WaitCnt <= 2) ; //1s
  6600. if (WriteACK == true)
  6601. {
  6602. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6603. }
  6604. else
  6605. {
  6606. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6607. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6608. ACK_WaitCnt = 0;
  6609. while (ACK_WaitCnt <= 2) ; //1s
  6610. if (WriteACK == true)
  6611. {
  6612. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6613. }
  6614. else
  6615. {
  6616. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6617. label_FacModeStatus.Text = "存在故障!";
  6618. label_FacModeResult.BackColor = Color.Red;
  6619. label_FacModeResult.Text = "测试异常";
  6620. Delay_ms(500);
  6621. //存储异常并上传
  6622. FacMode_Stop(false);
  6623. return;
  6624. }
  6625. }
  6626. }
  6627. //写入SN
  6628. label_FacModeStatus.Text = "写入SN";
  6629. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6630. textBox_FacModeNum.Text = InfoList[1];
  6631. string SN = textBox_FacModeNum.Text;
  6632. var SNArray = new byte[16];
  6633. for (ushort i = 0; i < SN.Length; i++)
  6634. {
  6635. SNArray[i] = (byte)SN[i];
  6636. }
  6637. if (SN.Length < 16)
  6638. {
  6639. SNArray[SN.Length] = (byte)'.';
  6640. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6641. {
  6642. SNArray[SN.Length + 1 + i] = 0x20;
  6643. }
  6644. }
  6645. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6646. WriteACK = false;
  6647. ACK_WaitCnt = 0;
  6648. while (ACK_WaitCnt <= 2); //1s
  6649. if (WriteACK == true)
  6650. {
  6651. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6652. }
  6653. else
  6654. {
  6655. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6656. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6657. ACK_WaitCnt = 0;
  6658. while (ACK_WaitCnt <= 2) ; //1s
  6659. if (WriteACK == true)
  6660. {
  6661. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6662. }
  6663. else
  6664. {
  6665. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6666. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6667. ACK_WaitCnt = 0;
  6668. while (ACK_WaitCnt <= 2) ; //1s
  6669. if (WriteACK == true)
  6670. {
  6671. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6672. }
  6673. else
  6674. {
  6675. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6676. label_FacModeStatus.Text = "存在故障!";
  6677. label_FacModeResult.BackColor = Color.Red;
  6678. label_FacModeResult.Text = "测试异常";
  6679. Delay_ms(500);
  6680. //存储异常并上传
  6681. FacMode_Stop(false);
  6682. return;
  6683. }
  6684. }
  6685. }
  6686. }
  6687. else
  6688. {
  6689. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6690. return;
  6691. }
  6692. } while (false);
  6693. //写入配置文件
  6694. do
  6695. {
  6696. label_FacModeStatus.Text = "写入配置文件";
  6697. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6698. //配置文件
  6699. List<byte[]> CmdList = new List<byte[]>();
  6700. //从服务器下载文件
  6701. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6702. {
  6703. string SelectFile = "";
  6704. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6705. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6706. {
  6707. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6708. }
  6709. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6710. //打开文件
  6711. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6712. CmdList.Clear();
  6713. while (streamReader.Peek() != -1)
  6714. {
  6715. string fileLineInfo = streamReader.ReadLine();
  6716. if (fileLineInfo.IndexOf("[") != -1)
  6717. {
  6718. continue;
  6719. }
  6720. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6721. }
  6722. streamReader.Close();
  6723. }
  6724. //加载本地文件
  6725. else
  6726. {
  6727. string SelectFile = "";
  6728. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6729. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6730. CmdList.Clear();
  6731. while (streamReader.Peek() != -1)
  6732. {
  6733. string fileLineInfo = streamReader.ReadLine();
  6734. if (fileLineInfo.IndexOf("[") != -1)
  6735. {
  6736. continue;
  6737. }
  6738. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6739. }
  6740. streamReader.Close();
  6741. }
  6742. int CmdNum = CmdList.Count(); //指令个数
  6743. Delay_ms(500);
  6744. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6745. Delay_ms(500);
  6746. //开始写入
  6747. for (int i = 0; i < CmdList.Count; i++)
  6748. {
  6749. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6750. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6751. WriteACK = false;
  6752. ACK_WaitCnt = 0;
  6753. while (ACK_WaitCnt <= 2) ; //1s
  6754. if (WriteACK == true)
  6755. {
  6756. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6757. }
  6758. else
  6759. {
  6760. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6761. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6762. WriteACK = false;
  6763. ACK_WaitCnt = 0;
  6764. while (ACK_WaitCnt <= 2) ; //1s
  6765. if (WriteACK == true)
  6766. {
  6767. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6768. }
  6769. else
  6770. {
  6771. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6772. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6773. WriteACK = false;
  6774. ACK_WaitCnt = 0;
  6775. while (ACK_WaitCnt <= 2) ; //1s
  6776. if (WriteACK == true)
  6777. {
  6778. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6779. }
  6780. else
  6781. {
  6782. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6783. label_FacModeStatus.Text = "存在故障!";
  6784. label_FacModeResult.BackColor = Color.Red;
  6785. label_FacModeResult.Text = "测试异常";
  6786. Delay_ms(500);
  6787. //存储异常并上传
  6788. FacMode_Stop(false);
  6789. return;
  6790. }
  6791. }
  6792. }
  6793. }
  6794. //写入完成
  6795. label_FacMode_CfgWrite.BackColor = Color.Green;
  6796. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6797. Delay_ms(500);
  6798. } while (false);
  6799. }
  6800. else
  6801. {
  6802. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6803. label_FacModeStatus.Text = "跳过参数写入!";
  6804. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6805. Delay_ms(500);
  6806. }
  6807. //BMS通讯
  6808. if (checkBox_FacModeBMS.Checked)
  6809. {
  6810. if (label_FacModeBMS.BackColor == Color.Red)
  6811. {
  6812. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6813. label_FacModeStatus.Text = "存在故障!";
  6814. label_FacModeResult.BackColor = Color.Red;
  6815. label_FacModeResult.Text = "测试异常";
  6816. Delay_ms(500);
  6817. //存储异常并上传
  6818. FacMode_Stop(false);
  6819. return;
  6820. }
  6821. }
  6822. else
  6823. {
  6824. label_FacModeBMS.BackColor = Color.Yellow;
  6825. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6826. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6827. Delay_ms(500);
  6828. }
  6829. //基础功能检测
  6830. if (checkBox_FacBaseFucTest.Checked)
  6831. {
  6832. label_FacModeStatus.Text = "基础功能检测";
  6833. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6834. //确认负载位置
  6835. if (checkBox_FacMode_MosCal.Checked)
  6836. {
  6837. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6838. {
  6839. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6840. }
  6841. else
  6842. {
  6843. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6844. label_FacModeStatus.Text = "存在故障!";
  6845. label_FacModeResult.BackColor = Color.Red;
  6846. label_FacModeResult.Text = "测试异常";
  6847. Delay_ms(500);
  6848. //存储异常并上传
  6849. FacMode_Stop(false);
  6850. return;
  6851. }
  6852. }
  6853. //发送指令进入配置模式
  6854. do
  6855. {
  6856. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6857. Code[0] = 0x01;
  6858. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6859. WriteACK = false;
  6860. ACK_WaitCnt = 0;
  6861. while (ACK_WaitCnt <= 2); //1s
  6862. if (textBox_RunInfo_Vol.Text != "---")
  6863. {
  6864. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6865. }
  6866. else
  6867. {
  6868. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6869. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6870. ACK_WaitCnt = 0;
  6871. while (ACK_WaitCnt <= 2) ; //1s
  6872. if (textBox_RunInfo_Vol.Text != "---")
  6873. {
  6874. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6875. }
  6876. else
  6877. {
  6878. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6879. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6880. ACK_WaitCnt = 0;
  6881. while (ACK_WaitCnt <= 2) ; //1s
  6882. if (textBox_RunInfo_Vol.Text != "---")
  6883. {
  6884. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6885. }
  6886. else
  6887. {
  6888. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6889. label_FacModeStatus.Text = "存在故障!";
  6890. label_FacModeResult.BackColor = Color.Red;
  6891. label_FacModeResult.Text = "测试异常";
  6892. Delay_ms(500);
  6893. //存储异常并上传
  6894. FacMode_Stop(false);
  6895. return;
  6896. }
  6897. }
  6898. }
  6899. } while (false);
  6900. //发送指令启动电机
  6901. do
  6902. {
  6903. #if false //通过运行模式3启动电机
  6904. //发送指令读取调试信息
  6905. richTextBox_DebugParam.Clear();
  6906. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6907. WriteACK = false;
  6908. ACK_WaitCnt = 0;
  6909. while (ACK_WaitCnt <= 2); //1s
  6910. //获取调试信息
  6911. string DebugDefaultInfo = "";
  6912. if (richTextBox_DebugParam.Text == string.Empty)
  6913. {
  6914. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6915. label_FacModeStatus.Text = "存在故障!";
  6916. label_FacModeResult.BackColor = Color.Red;
  6917. label_FacModeResult.Text = "测试异常";
  6918. Delay_ms(500);
  6919. //存储异常并上传
  6920. FacMode_Stop(false);
  6921. return;
  6922. }
  6923. else
  6924. {
  6925. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6926. }
  6927. //设置模式
  6928. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6929. strDataTemp[0] = "整体运行模式=3";
  6930. //发送数据
  6931. Code[0] = 0;
  6932. Code[1] = 0;
  6933. for (int i = 0; i < strDataTemp.Length; i++)
  6934. {
  6935. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6936. Code[2 * i + 2] = (byte)uwDataTemp;
  6937. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6938. }
  6939. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6940. label_FacModeStatus.Text = "启动电机";
  6941. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6942. #else //通过Walk模式启动电机
  6943. //设置转速100%
  6944. var Data = new byte[1];
  6945. Data[0] = (byte)100;
  6946. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6947. Delay_ms(500);
  6948. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6949. Delay_ms(500);
  6950. //启动电机进入WALK模式
  6951. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6952. Code[0] = 0x22;
  6953. Code[1] = 0xF0;
  6954. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6955. WriteACK = false;
  6956. ACK_WaitCnt = 0;
  6957. while (ACK_WaitCnt <= 2) ; //1s
  6958. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6959. {
  6960. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6961. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6962. ACK_WaitCnt = 0;
  6963. while (ACK_WaitCnt <= 2) ; //1s
  6964. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6965. {
  6966. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6967. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6968. ACK_WaitCnt = 0;
  6969. while (ACK_WaitCnt <= 2) ; //1s
  6970. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6971. {
  6972. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6973. label_FacModeStatus.Text = "存在故障!";
  6974. label_FacModeResult.BackColor = Color.Red;
  6975. label_FacModeResult.Text = "测试异常";
  6976. Delay_ms(500);
  6977. //存储异常并上传
  6978. FacMode_Stop(false);
  6979. return;
  6980. }
  6981. }
  6982. }
  6983. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6984. #endif
  6985. Delay_ms(3000);
  6986. } while (false);
  6987. //判断车速
  6988. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6989. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6990. {
  6991. label_FacModeSpeed.BackColor = Color.Green;
  6992. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6993. }
  6994. else
  6995. {
  6996. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6997. label_FacModeStatus.Text = "存在故障!";
  6998. label_FacModeResult.BackColor = Color.Red;
  6999. label_FacModeResult.Text = "测试异常";
  7000. Delay_ms(500);
  7001. //存储异常并上传
  7002. FacMode_Stop(false);
  7003. return;
  7004. }
  7005. //判断电压
  7006. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  7007. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  7008. {
  7009. label_FacModeVolTest.BackColor = Color.Green;
  7010. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  7011. }
  7012. else
  7013. {
  7014. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\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. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  7025. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  7026. {
  7027. label_FacModeCurrentTest.BackColor = Color.Green;
  7028. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7029. }
  7030. else
  7031. {
  7032. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  7033. label_FacModeStatus.Text = "存在故障!";
  7034. label_FacModeResult.BackColor = Color.Red;
  7035. label_FacModeResult.Text = "测试异常";
  7036. Delay_ms(500);
  7037. //存储异常并上传
  7038. FacMode_Stop(false);
  7039. return;
  7040. }
  7041. //判断温度
  7042. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  7043. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  7044. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  7045. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  7046. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  7047. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  7048. {
  7049. label_FacModeNTC.BackColor = Color.Green;
  7050. 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");
  7051. }
  7052. else
  7053. {
  7054. 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");
  7055. label_FacModeStatus.Text = "存在故障!";
  7056. label_FacModeResult.BackColor = Color.Red;
  7057. label_FacModeResult.Text = "测试异常";
  7058. Delay_ms(500);
  7059. //存储异常并上传
  7060. FacMode_Stop(false);
  7061. return;
  7062. }
  7063. //判断转速
  7064. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  7065. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  7066. {
  7067. label_FacModeMotorSpeed.BackColor = Color.Green;
  7068. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7069. }
  7070. else
  7071. {
  7072. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  7073. label_FacModeStatus.Text = "存在故障!";
  7074. label_FacModeResult.BackColor = Color.Red;
  7075. label_FacModeResult.Text = "测试异常";
  7076. Delay_ms(500);
  7077. //存储异常并上传
  7078. FacMode_Stop(false);
  7079. return;
  7080. }
  7081. //发送指令停止电机
  7082. do
  7083. {
  7084. //设置转速0%
  7085. var Data = new byte[1];
  7086. Data[0] = (byte)0;
  7087. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7088. Delay_ms(500);
  7089. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7090. Delay_ms(500);
  7091. #if false //通过修改调试模式停止电机
  7092. //获取调试信息
  7093. string DebugDefaultInfo = "";
  7094. if (richTextBox_DebugParam.Text == string.Empty)
  7095. {
  7096. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  7097. label_FacModeStatus.Text = "存在故障!";
  7098. label_FacModeResult.BackColor = Color.Red;
  7099. label_FacModeResult.Text = "测试异常";
  7100. Delay_ms(500);
  7101. //存储异常并上传
  7102. FacMode_Stop(false);
  7103. return;
  7104. }
  7105. else
  7106. {
  7107. DebugDefaultInfo = richTextBox_DebugParam.Text;
  7108. }
  7109. //设置模式
  7110. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  7111. //发送数据
  7112. Code[0] = 0;
  7113. Code[1] = 0;
  7114. for (int i = 0; i < strDataTemp.Length; i++)
  7115. {
  7116. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  7117. Code[2 * i + 2] = (byte)uwDataTemp;
  7118. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  7119. }
  7120. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  7121. label_FacModeStatus.Text = "停止电机";
  7122. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  7123. #else //通过调整档位停止电机
  7124. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  7125. Code[0] = 0x00;
  7126. Code[1] = 0xF0;
  7127. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7128. WriteACK = false;
  7129. ACK_WaitCnt = 0;
  7130. while (ACK_WaitCnt <= 2) ; //1s
  7131. if (textBox_RunInfo_GearSt.Text != "OFF")
  7132. {
  7133. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  7134. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7135. ACK_WaitCnt = 0;
  7136. while (ACK_WaitCnt <= 2) ; //1s
  7137. if (textBox_RunInfo_GearSt.Text != "OFF")
  7138. {
  7139. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  7140. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7141. ACK_WaitCnt = 0;
  7142. while (ACK_WaitCnt <= 2) ; //1s
  7143. if (textBox_RunInfo_GearSt.Text != "OFF")
  7144. {
  7145. }
  7146. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7147. label_FacModeStatus.Text = "存在故障!";
  7148. label_FacModeResult.BackColor = Color.Red;
  7149. label_FacModeResult.Text = "测试异常";
  7150. Delay_ms(500);
  7151. //存储异常并上传
  7152. FacMode_Stop(false);
  7153. return;
  7154. }
  7155. }
  7156. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  7157. #endif
  7158. Delay_ms(2000);
  7159. } while (false);
  7160. }
  7161. else
  7162. {
  7163. label_FacModeSpeed.BackColor = Color.Yellow;
  7164. label_FacModeVolTest.BackColor = Color.Yellow;
  7165. label_FacModeCurrentTest.BackColor = Color.Yellow;
  7166. label_FacModeNTC.BackColor = Color.Yellow;
  7167. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  7168. label_FacModeStatus.Text = "跳过基础功能检测!";
  7169. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  7170. Delay_ms(500);
  7171. }
  7172. //力矩检测
  7173. if (checkBox_FacTor.Checked)
  7174. {
  7175. label_FacModeStatus.Text = "力矩传感器检测!";
  7176. //发送指令进入配置模式
  7177. do
  7178. {
  7179. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7180. {
  7181. break;
  7182. }
  7183. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7184. Code[0] = 0x01;
  7185. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7186. WriteACK = false;
  7187. ACK_WaitCnt = 0;
  7188. while (ACK_WaitCnt <= 2) ; //1s
  7189. if (textBox_RunInfo_Vol.Text != "---")
  7190. {
  7191. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7192. Delay_ms(500);
  7193. }
  7194. else
  7195. {
  7196. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7197. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7198. ACK_WaitCnt = 0;
  7199. while (ACK_WaitCnt <= 2) ; //1s
  7200. if (textBox_RunInfo_Vol.Text != "---")
  7201. {
  7202. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7203. Delay_ms(500);
  7204. }
  7205. else
  7206. {
  7207. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7208. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7209. ACK_WaitCnt = 0;
  7210. while (ACK_WaitCnt <= 2) ; //1s
  7211. if (textBox_RunInfo_Vol.Text != "---")
  7212. {
  7213. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7214. Delay_ms(500);
  7215. }
  7216. else
  7217. {
  7218. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7219. label_FacModeStatus.Text = "存在故障!";
  7220. label_FacModeResult.BackColor = Color.Red;
  7221. label_FacModeResult.Text = "测试异常";
  7222. Delay_ms(500);
  7223. //存储异常并上传
  7224. FacMode_Stop(false);
  7225. return;
  7226. }
  7227. }
  7228. }
  7229. } while (false);
  7230. ushort Max = 0, Torque = 0;
  7231. //提示输入力矩信号
  7232. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  7233. ACK_WaitCnt = 0;
  7234. while (ACK_WaitCnt <= 20) //10s
  7235. {
  7236. //获取力矩值
  7237. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  7238. if (Torque > Max)
  7239. Max = Torque;
  7240. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  7241. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  7242. (ACK_WaitCnt >= 6))
  7243. {
  7244. label_FacModeTq.BackColor = Color.Green;
  7245. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7246. break;
  7247. }
  7248. }
  7249. if (ACK_WaitCnt >= 20)
  7250. {
  7251. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  7252. label_FacModeStatus.Text = "存在故障!";
  7253. label_FacModeResult.BackColor = Color.Red;
  7254. label_FacModeResult.Text = "测试异常";
  7255. Delay_ms(500);
  7256. //存储异常并上传
  7257. FacMode_Stop(false);
  7258. return;
  7259. }
  7260. }
  7261. else
  7262. {
  7263. label_FacModeTq.BackColor = Color.Yellow;
  7264. label_FacModeStatus.Text = "跳过力矩检测!";
  7265. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  7266. Delay_ms(500);
  7267. }
  7268. //踏频检测
  7269. if (checkBox_FacCad.Checked)
  7270. {
  7271. label_FacModeStatus.Text = "踏频传感器检测!";
  7272. //发送指令进入配置模式
  7273. do
  7274. {
  7275. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7276. {
  7277. break;
  7278. }
  7279. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7280. Code[0] = 0x01;
  7281. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7282. WriteACK = false;
  7283. ACK_WaitCnt = 0;
  7284. while (ACK_WaitCnt <= 2) ; //1s
  7285. if (textBox_RunInfo_Vol.Text != "---")
  7286. {
  7287. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7288. Delay_ms(500);
  7289. }
  7290. else
  7291. {
  7292. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7293. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7294. ACK_WaitCnt = 0;
  7295. while (ACK_WaitCnt <= 2) ; //1s
  7296. if (textBox_RunInfo_Vol.Text != "---")
  7297. {
  7298. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7299. Delay_ms(500);
  7300. }
  7301. else
  7302. {
  7303. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7304. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7305. ACK_WaitCnt = 0;
  7306. while (ACK_WaitCnt <= 2) ; //1s
  7307. if (textBox_RunInfo_Vol.Text != "---")
  7308. {
  7309. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7310. Delay_ms(500);
  7311. }
  7312. else
  7313. {
  7314. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7315. label_FacModeStatus.Text = "存在故障!";
  7316. label_FacModeResult.BackColor = Color.Red;
  7317. label_FacModeResult.Text = "测试异常";
  7318. Delay_ms(500);
  7319. //存储异常并上传
  7320. FacMode_Stop(false);
  7321. return;
  7322. }
  7323. }
  7324. }
  7325. } while (false);
  7326. ushort Max = 0, Cadence = 0;
  7327. //提示输入踏频信号
  7328. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7329. ACK_WaitCnt = 0;
  7330. while (ACK_WaitCnt <= 20) //10s
  7331. {
  7332. //获取踏频
  7333. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7334. if (Cadence > Max)
  7335. Max = Cadence;
  7336. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7337. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7338. (ACK_WaitCnt >= 6))
  7339. {
  7340. label_FacModeCad.BackColor = Color.Green;
  7341. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7342. break;
  7343. }
  7344. }
  7345. if (ACK_WaitCnt >= 20)
  7346. {
  7347. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7348. label_FacModeStatus.Text = "存在故障!";
  7349. label_FacModeResult.BackColor = Color.Red;
  7350. label_FacModeResult.Text = "测试异常";
  7351. Delay_ms(500);
  7352. //存储异常并上传
  7353. FacMode_Stop(false);
  7354. return;
  7355. }
  7356. }
  7357. else
  7358. {
  7359. label_FacModeCad.BackColor = Color.Yellow;
  7360. label_FacModeStatus.Text = "跳过踏频检测!";
  7361. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7362. Delay_ms(500);
  7363. }
  7364. //转把检测
  7365. if (checkBox_FacThrrotleTest.Checked)
  7366. {
  7367. label_FacModeStatus.Text = "转把检测";
  7368. //发送指令进入配置模式
  7369. do
  7370. {
  7371. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7372. {
  7373. break;
  7374. }
  7375. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7376. Code[0] = 0x01;
  7377. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7378. WriteACK = false;
  7379. ACK_WaitCnt = 0;
  7380. while (ACK_WaitCnt <= 2) ; //1s
  7381. if (textBox_RunInfo_Vol.Text != "---")
  7382. {
  7383. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7384. Delay_ms(500);
  7385. }
  7386. else
  7387. {
  7388. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7389. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7390. ACK_WaitCnt = 0;
  7391. while (ACK_WaitCnt <= 2) ; //1s
  7392. if (textBox_RunInfo_Vol.Text != "---")
  7393. {
  7394. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7395. Delay_ms(500);
  7396. }
  7397. else
  7398. {
  7399. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7400. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7401. ACK_WaitCnt = 0;
  7402. while (ACK_WaitCnt <= 2) ; //1s
  7403. if (textBox_RunInfo_Vol.Text != "---")
  7404. {
  7405. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7406. Delay_ms(500);
  7407. }
  7408. else
  7409. {
  7410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7411. label_FacModeStatus.Text = "存在故障!";
  7412. label_FacModeResult.BackColor = Color.Red;
  7413. label_FacModeResult.Text = "测试异常";
  7414. Delay_ms(500);
  7415. //存储异常并上传
  7416. FacMode_Stop(false);
  7417. return;
  7418. }
  7419. }
  7420. }
  7421. } while (false);
  7422. //进入TURBO档
  7423. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7424. Code[0] = 0x04;
  7425. Code[1] = 0xF0;
  7426. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7427. WriteACK = false;
  7428. ACK_WaitCnt = 0;
  7429. while (ACK_WaitCnt <= 2) ; //1s
  7430. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7431. {
  7432. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7433. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7434. ACK_WaitCnt = 0;
  7435. while (ACK_WaitCnt <= 2) ; //1s
  7436. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7437. {
  7438. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7439. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7440. ACK_WaitCnt = 0;
  7441. while (ACK_WaitCnt <= 2) ; //1s
  7442. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7443. {
  7444. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7445. label_FacModeStatus.Text = "存在故障!";
  7446. label_FacModeResult.BackColor = Color.Red;
  7447. label_FacModeResult.Text = "测试异常";
  7448. Delay_ms(500);
  7449. //存储异常并上传
  7450. FacMode_Stop(false);
  7451. return;
  7452. }
  7453. }
  7454. }
  7455. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7456. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请松开转把" + "\r\n");
  7457. Delay_ms(3000);
  7458. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7459. {
  7460. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7461. label_FacModeStatus.Text = "存在故障!";
  7462. label_FacModeResult.BackColor = Color.Red;
  7463. label_FacModeResult.Text = "测试异常";
  7464. Delay_ms(500);
  7465. //存储异常并上传
  7466. FacMode_Stop(false);
  7467. return;
  7468. }
  7469. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7470. Delay_ms(500);
  7471. //提示转动转把
  7472. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7473. ACK_WaitCnt = 0;
  7474. while (ACK_WaitCnt <= 20)
  7475. {
  7476. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7477. {
  7478. label_FacModeGas.BackColor = Color.Green;
  7479. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7480. break;
  7481. }
  7482. }
  7483. if (ACK_WaitCnt >= 20) //转把超时
  7484. {
  7485. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7486. label_FacModeStatus.Text = "存在故障!";
  7487. label_FacModeResult.BackColor = Color.Red;
  7488. label_FacModeResult.Text = "测试异常";
  7489. Delay_ms(500);
  7490. //存储异常并上传
  7491. FacMode_Stop(false);
  7492. return;
  7493. }
  7494. }
  7495. else
  7496. {
  7497. label_FacModeGas.BackColor = Color.Yellow;
  7498. label_FacModeStatus.Text = "跳过转把检测!";
  7499. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7500. Delay_ms(500);
  7501. }
  7502. //刹车检测
  7503. if (checkBox_FacBreakTest.Checked)
  7504. {
  7505. label_FacModeStatus.Text = "刹把检测";
  7506. //发送指令进入配置模式
  7507. do
  7508. {
  7509. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7510. {
  7511. break;
  7512. }
  7513. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7514. Code[0] = 0x01;
  7515. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7516. WriteACK = false;
  7517. ACK_WaitCnt = 0;
  7518. while (ACK_WaitCnt <= 2) ; //1s
  7519. if (textBox_RunInfo_Vol.Text != "---")
  7520. {
  7521. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7522. Delay_ms(500);
  7523. }
  7524. else
  7525. {
  7526. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7527. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7528. ACK_WaitCnt = 0;
  7529. while (ACK_WaitCnt <= 2) ; //1s
  7530. if (textBox_RunInfo_Vol.Text != "---")
  7531. {
  7532. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7533. Delay_ms(500);
  7534. }
  7535. else
  7536. {
  7537. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7538. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7539. ACK_WaitCnt = 0;
  7540. while (ACK_WaitCnt <= 2) ; //1s
  7541. if (textBox_RunInfo_Vol.Text != "---")
  7542. {
  7543. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7544. Delay_ms(500);
  7545. }
  7546. else
  7547. {
  7548. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7549. label_FacModeStatus.Text = "存在故障!";
  7550. label_FacModeResult.BackColor = Color.Red;
  7551. label_FacModeResult.Text = "测试异常";
  7552. Delay_ms(500);
  7553. //存储异常并上传
  7554. FacMode_Stop(false);
  7555. return;
  7556. }
  7557. }
  7558. }
  7559. } while (false);
  7560. //测试前先确定电机已停止
  7561. UInt16 WaitTime = 10;
  7562. do
  7563. {
  7564. WaitTime--;
  7565. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7566. {
  7567. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机停止,开始进行剎把检测,进入WALK" + "\r\n");
  7568. break;
  7569. }
  7570. if (WaitTime == 0)
  7571. {
  7572. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机无法停止,剎把检测异常" + "\r\n");
  7573. label_FacModeStatus.Text = "存在故障!";
  7574. label_FacModeResult.BackColor = Color.Red;
  7575. label_FacModeResult.Text = "测试异常";
  7576. Delay_ms(500);
  7577. //存储异常并上传
  7578. FacMode_Stop(false);
  7579. return;
  7580. }
  7581. Delay_ms(500);
  7582. } while (true);
  7583. //设置转速100%
  7584. var Data = new byte[1];
  7585. Data[0] = (byte)100;
  7586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7587. Delay_ms(500);
  7588. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7589. Delay_ms(500);
  7590. //启动电机进入WALK模式
  7591. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7592. Code[0] = 0x22;
  7593. Code[1] = 0xF0;
  7594. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7595. WriteACK = false;
  7596. ACK_WaitCnt = 0;
  7597. while (ACK_WaitCnt <= 2) ; //1s
  7598. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7599. {
  7600. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7601. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7602. ACK_WaitCnt = 0;
  7603. while (ACK_WaitCnt <= 2) ; //1s
  7604. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7605. {
  7606. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7607. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7608. ACK_WaitCnt = 0;
  7609. while (ACK_WaitCnt <= 2) ; //1s
  7610. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 500))
  7611. {
  7612. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7613. label_FacModeStatus.Text = "存在故障!";
  7614. label_FacModeResult.BackColor = Color.Red;
  7615. label_FacModeResult.Text = "测试异常";
  7616. Delay_ms(500);
  7617. //存储异常并上传
  7618. FacMode_Stop(false);
  7619. return;
  7620. }
  7621. }
  7622. }
  7623. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7624. ACK_WaitCnt = 0;
  7625. while (ACK_WaitCnt <= 20)
  7626. {
  7627. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7628. {
  7629. label_FacModeBreak.BackColor = Color.Green;
  7630. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7631. break;
  7632. }
  7633. }
  7634. if (ACK_WaitCnt >= 20) //剎把超时
  7635. {
  7636. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速:" + textBox_RunInfo_MotorSpeed.Text + "," + "剎把功能异常,松开剎把" + "\r\n");
  7637. label_FacModeStatus.Text = "存在故障!";
  7638. label_FacModeResult.BackColor = Color.Red;
  7639. label_FacModeResult.Text = "测试异常";
  7640. Delay_ms(500);
  7641. //存储异常并上传
  7642. FacMode_Stop(false);
  7643. return;
  7644. }
  7645. //停止电机
  7646. Code[0] = 0x00;
  7647. Code[1] = 0xF0;
  7648. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7649. WriteACK = false;
  7650. ACK_WaitCnt = 0;
  7651. while (ACK_WaitCnt <= 2) ; //1s
  7652. if (textBox_RunInfo_GearSt.Text != "OFF")
  7653. {
  7654. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7655. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7656. ACK_WaitCnt = 0;
  7657. while (ACK_WaitCnt <= 2) ; //1s
  7658. if (textBox_RunInfo_GearSt.Text != "OFF")
  7659. {
  7660. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7661. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7662. ACK_WaitCnt = 0;
  7663. while (ACK_WaitCnt <= 2) ; //1s
  7664. if (textBox_RunInfo_GearSt.Text != "OFF")
  7665. {
  7666. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7667. label_FacModeStatus.Text = "存在故障!";
  7668. label_FacModeResult.BackColor = Color.Red;
  7669. label_FacModeResult.Text = "测试异常";
  7670. Delay_ms(500);
  7671. //存储异常并上传
  7672. FacMode_Stop(false);
  7673. return;
  7674. }
  7675. }
  7676. }
  7677. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7678. Delay_ms(500);
  7679. }
  7680. else
  7681. {
  7682. label_FacModeBreak.BackColor = Color.Yellow;
  7683. label_FacModeStatus.Text = "跳过刹车检测!";
  7684. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7685. Delay_ms(500);
  7686. }
  7687. //前后灯检测
  7688. if (checkBox_FacLightTest.Checked)
  7689. {
  7690. //前后灯检测
  7691. label_FacModeStatus.Text = "前后灯检测";
  7692. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7693. //发送指令打开车灯
  7694. Code[0] = 0x00;
  7695. Code[1] = 0xF1;
  7696. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7697. WriteACK = false;
  7698. ACK_WaitCnt = 0;
  7699. while (ACK_WaitCnt <= 2) ; //1s
  7700. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7701. {
  7702. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7703. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7704. ACK_WaitCnt = 0;
  7705. while (ACK_WaitCnt <= 2); //1s
  7706. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7707. {
  7708. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7709. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7710. ACK_WaitCnt = 0;
  7711. while (ACK_WaitCnt <= 2) ; //1s
  7712. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7713. {
  7714. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7715. label_FacModeStatus.Text = "存在故障!";
  7716. label_FacModeResult.BackColor = Color.Red;
  7717. label_FacModeResult.Text = "测试异常";
  7718. Delay_ms(500);
  7719. //存储异常并上传
  7720. FacMode_Stop(false);
  7721. return;
  7722. }
  7723. }
  7724. }
  7725. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7726. Delay_ms(500);
  7727. //提示检查灯压是否正确
  7728. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7729. {
  7730. label_FacModeLightF.BackColor = Color.Green;
  7731. label_FacModeLightB.BackColor = Color.Green;
  7732. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7733. Delay_ms(500);
  7734. }
  7735. else
  7736. {
  7737. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7738. label_FacModeStatus.Text = "存在故障!";
  7739. label_FacModeResult.BackColor = Color.Red;
  7740. label_FacModeResult.Text = "测试异常";
  7741. Delay_ms(500);
  7742. //存储异常并上传
  7743. FacMode_Stop(false);
  7744. return;
  7745. }
  7746. //发送指令关闭车灯
  7747. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7748. Code[0] = 0x00;
  7749. Code[1] = 0xF0;
  7750. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7751. WriteACK = false;
  7752. ACK_WaitCnt = 0;
  7753. while (ACK_WaitCnt <= 2) ; //1s
  7754. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7755. {
  7756. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7757. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7758. ACK_WaitCnt = 0;
  7759. while (ACK_WaitCnt <= 2) ; //1s
  7760. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7761. {
  7762. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7763. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7764. ACK_WaitCnt = 0;
  7765. while (ACK_WaitCnt <= 2) ; //1s
  7766. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7767. {
  7768. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7769. label_FacModeStatus.Text = "存在故障!";
  7770. label_FacModeResult.BackColor = Color.Red;
  7771. label_FacModeResult.Text = "测试异常";
  7772. Delay_ms(500);
  7773. //存储异常并上传
  7774. FacMode_Stop(false);
  7775. return;
  7776. }
  7777. }
  7778. }
  7779. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7780. Delay_ms(500);
  7781. }
  7782. else
  7783. {
  7784. label_FacModeLightF.BackColor = Color.Yellow;
  7785. label_FacModeLightB.BackColor = Color.Yellow;
  7786. label_FacModeStatus.Text = "跳过前后灯检测!";
  7787. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7788. Delay_ms(500);
  7789. }
  7790. //软件版本检测
  7791. do
  7792. {
  7793. label_FacModeStatus.Text = "软件版本确认";
  7794. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7795. //发送指令读取版本
  7796. Class_Motor_Ver.Mode = "---";
  7797. Class_Motor_Ver.SN = "---";
  7798. Class_Motor_Ver.HW = "---";
  7799. Class_Motor_Ver.FW = "---";
  7800. Class_Motor_Ver.Special = "---";
  7801. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7802. ACK_WaitCnt = 0;
  7803. while (ACK_WaitCnt <= 2) ; //1s
  7804. if (Class_Motor_Ver.Mode == "---")
  7805. {
  7806. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7807. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7808. ACK_WaitCnt = 0;
  7809. while (ACK_WaitCnt <= 2) ; //1s
  7810. if (Class_Motor_Ver.Mode == "---")
  7811. {
  7812. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7813. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7814. ACK_WaitCnt = 0;
  7815. while (ACK_WaitCnt <= 2) ; //1s
  7816. if (Class_Motor_Ver.Mode == "---")
  7817. {
  7818. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7819. label_FacModeStatus.Text = "存在故障!";
  7820. label_FacModeResult.BackColor = Color.Red;
  7821. label_FacModeResult.Text = "测试异常";
  7822. Delay_ms(500);
  7823. //存储异常并上传
  7824. FacMode_Stop(false);
  7825. return;
  7826. }
  7827. }
  7828. }
  7829. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7830. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7831. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7832. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7833. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7834. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7835. //判断版本是否正确
  7836. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7837. string VerRead = "";
  7838. try
  7839. {
  7840. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7841. }
  7842. catch (System.Exception)
  7843. {
  7844. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7845. label_FacModeStatus.Text = "存在故障!";
  7846. label_FacModeResult.BackColor = Color.Red;
  7847. label_FacModeResult.Text = "测试异常";
  7848. Delay_ms(500);
  7849. //存储异常并上传
  7850. FacMode_Stop(false);
  7851. return;
  7852. }
  7853. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7854. {
  7855. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7856. label_FacModeStatus.Text = "存在故障!";
  7857. label_FacModeResult.BackColor = Color.Red;
  7858. label_FacModeResult.Text = "测试异常";
  7859. Delay_ms(500);
  7860. //存储异常并上传
  7861. FacMode_Stop(false);
  7862. return;
  7863. }
  7864. label_FacModeFWVersion.BackColor = Color.Green;
  7865. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7866. Delay_ms(500);
  7867. } while (false);
  7868. //测试合格
  7869. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7870. label_FacModeStatus.Text = "测试结束!";
  7871. label_FacModeResult.BackColor = Color.Green;
  7872. label_FacModeResult.Text = "测试合格";
  7873. Delay_ms(500);
  7874. //存储并上传
  7875. FacMode_Stop(true);
  7876. return;
  7877. }
  7878. private void FacModelLabelInit()
  7879. {
  7880. //测试状态标签
  7881. label_FacModeResult.BackColor = Color.Yellow;
  7882. label_FacModeResult.Text = "测试中";
  7883. //测试过程标签
  7884. label_FacModeStatus.Text = "测试就绪";
  7885. //测试结果标签
  7886. foreach (Control c in groupBox28.Controls)
  7887. {
  7888. if (c is Label)
  7889. {
  7890. if (c.Text == string.Empty)
  7891. c.BackColor = Color.Red;
  7892. }
  7893. }
  7894. }
  7895. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7896. {
  7897. //更新生产配置文件目录
  7898. GetDateList(false);
  7899. }
  7900. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7901. {
  7902. //更新生产配置文件目录
  7903. GetDateList(false);
  7904. }
  7905. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7906. {
  7907. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7908. richTextBox_FacModeLog.ScrollToCaret();
  7909. }
  7910. /// <summary>
  7911. /// 参数检验测试停止
  7912. /// </summary>
  7913. /// <param name="OK_Flag"></param>
  7914. private void CheckMode_Stop(bool OK_Flag)
  7915. {
  7916. //打开开始按钮
  7917. button_CheckModeStart.Enabled = true;
  7918. //导出电机参数
  7919. string Params = "";
  7920. do
  7921. {
  7922. if (!OK_Flag)
  7923. {
  7924. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7925. break;
  7926. }
  7927. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7928. //读取一次马达参数
  7929. richTextBox_MotorParam.Clear();
  7930. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7931. Delay_ms(100);
  7932. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7933. Params += "\r\n";
  7934. //读取一次整车参数
  7935. richTextBox_BikeParam.Clear();
  7936. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7937. Delay_ms(100);
  7938. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7939. Params += "\r\n";
  7940. //读取一次控制参数
  7941. richTextBox_ControlParam.Clear();
  7942. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7943. Delay_ms(100);
  7944. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7945. Params += "\r\n";
  7946. //查询传感器
  7947. richTextBox_SensorParam.Clear();
  7948. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7949. Delay_ms(100);
  7950. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7951. Params += "\r\n";
  7952. //读取15次助力参数
  7953. Params += "[助力参数]" + "\r\n";
  7954. for (int i = 1; i <= 15; i++)
  7955. {
  7956. var ConfigParam = new byte[4];
  7957. richTextBox_AssistParam.Clear();
  7958. ConfigParam[0] = (byte)(i & 0xFF);
  7959. ConfigParam[1] = (byte)(i >> 8);
  7960. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7961. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7962. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7963. Delay_ms(200);
  7964. Params += richTextBox_AssistParam.Text + "\r\n";
  7965. Params += "\r\n";
  7966. }
  7967. //读取一次调试信息
  7968. richTextBox_DebugParam.Clear();
  7969. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7970. Delay_ms(100);
  7971. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7972. Params += "\r\n";
  7973. //读取一次历史信息
  7974. richTextBox_Record.Clear();
  7975. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7976. Delay_ms(100);
  7977. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7978. Params += "\r\n";
  7979. //读取一次MOS内阻校准参数
  7980. foreach (Control c in groupBox21.Controls)
  7981. {
  7982. if (c is TextBox)
  7983. c.Text = "";
  7984. }
  7985. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7986. Delay_ms(100);
  7987. Params += "[MOS内阻校准参数]" + "\r\n";
  7988. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7989. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7990. Params += "\r\n";
  7991. //读取一次整车参数2
  7992. richTextBox_BikeParam2.Clear();
  7993. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7994. Delay_ms(100);
  7995. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  7996. Params += "\r\n";
  7997. //读取一次用户骑行参数
  7998. richTextBox_UsrRidesParam.Clear();
  7999. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  8000. Delay_ms(100);
  8001. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  8002. Params += "\r\n";
  8003. //读取一次生产信息
  8004. textBox_MAC.Text = "";
  8005. textBox_MACAdd.Text = "";
  8006. textBox_MACDate.Text = "";
  8007. textBox_PP.Text = "";
  8008. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  8009. Delay_ms(100);
  8010. Params += "[生产信息]" + "\r\n";
  8011. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  8012. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  8013. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  8014. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  8015. Params += "\r\n";
  8016. //读取一次自定义信息
  8017. textBox_User1.Text = "---";
  8018. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  8019. Delay_ms(100);
  8020. textBox_User2.Text = "---";
  8021. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  8022. Delay_ms(100);
  8023. textBox_User3.Text = "---";
  8024. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  8025. Delay_ms(100);
  8026. Params += "[自定义信息]" + "\r\n";
  8027. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  8028. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  8029. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  8030. Params += "\r\n";
  8031. //读取一次密钥
  8032. textBox_Key.Text = "---";
  8033. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  8034. Delay_ms(100);
  8035. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  8036. Params += "\r\n";
  8037. //读取一次存储标志
  8038. radioButton_EE_SaveYes.Checked = false;
  8039. radioButton_EE_SaveNo.Checked = false;
  8040. radioButton_SIP_SaveYes.Checked = false;
  8041. radioButton_SIP_SaveNo.Checked = false;
  8042. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  8043. Delay_ms(100);
  8044. Params += "[存储标志]" + "\r\n";
  8045. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  8046. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  8047. Params += "\r\n";
  8048. } while (false);
  8049. //系统关机
  8050. var Code = new byte[32];//发送的指令数据
  8051. Code[0] = 0xF0;
  8052. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8053. //关闭串口
  8054. //mySerialProcess.SerialClose(false);
  8055. //路径设置
  8056. string LocalSavePath = "";
  8057. string ServerSavePath = "";
  8058. if (OK_Flag)
  8059. {
  8060. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  8061. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  8062. }
  8063. else
  8064. {
  8065. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  8066. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  8067. }
  8068. if (Directory.Exists(LocalSavePath) == false)
  8069. {
  8070. Directory.CreateDirectory(LocalSavePath);
  8071. }
  8072. //保存和上传
  8073. string LogSavePath = "";
  8074. string LogSaveFileName = "";
  8075. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_").Replace("/", "-"); ;
  8076. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  8077. if (Directory.Exists(LogSavePath) == false)
  8078. {
  8079. Directory.CreateDirectory(LogSavePath);
  8080. }
  8081. //测试页面
  8082. Double scaleX = PrimaryScreen.ScaleX;
  8083. Double scaleY = PrimaryScreen.ScaleY;
  8084. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  8085. Graphics g = Graphics.FromImage(bit);
  8086. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  8087. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  8088. bit.Save(LogSaveFileName);
  8089. //上传测试页面到服务器
  8090. if (myFtp.IsNetConnected == true)
  8091. {
  8092. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8093. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8094. {
  8095. myFtp.MakeDir(ServerSavePath + DateNow);
  8096. }
  8097. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8098. {
  8099. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8100. }
  8101. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8102. if (result == true)
  8103. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  8104. }
  8105. //测试记录
  8106. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  8107. string file_str = "";
  8108. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  8109. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  8110. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  8111. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  8112. file_str += Local_HdInformation;
  8113. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  8114. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  8115. //上传测试记录到服务器
  8116. if (myFtp.IsNetConnected == true)
  8117. {
  8118. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  8119. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  8120. {
  8121. myFtp.MakeDir(ServerSavePath + DateNow);
  8122. }
  8123. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  8124. {
  8125. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  8126. }
  8127. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  8128. if (result == true)
  8129. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  8130. }
  8131. //扫码框清空
  8132. textBox_CheckModeScan.Text = "";
  8133. }
  8134. /// <summary>
  8135. /// 参数检验开始
  8136. /// </summary>
  8137. /// <param name="sender"></param>
  8138. /// <param name="e"></param>
  8139. private void button_CheckModeStart_Click(object sender, EventArgs e)
  8140. {
  8141. //测试项目关闭编辑
  8142. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8143. foreach (Control c in groupBox29.Controls)
  8144. {
  8145. if (c is CheckBox)
  8146. c.Enabled = false;
  8147. }
  8148. ReadLockStatus = true;
  8149. //检查配置文件
  8150. if (comboBox_CheckModeCfgFile.Text == "")
  8151. {
  8152. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8153. return;
  8154. }
  8155. //开始测试
  8156. CheckTestStart();
  8157. }
  8158. /// <summary>
  8159. /// 参数检验测试子函数
  8160. /// </summary>
  8161. private void CheckTestStart()
  8162. {
  8163. //初始化标签
  8164. CheckModeLabelInit();
  8165. richTextBox_CheckModeLog.Clear();
  8166. //按钮禁止操作
  8167. button_CheckModeStart.Enabled = false;
  8168. //记录配置文件
  8169. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  8170. //检查打标信息
  8171. label_CheckModeStatus.Text = "检查扫码信息";
  8172. Delay_ms(500);
  8173. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  8174. if (textBox_CheckModeScan.Text == string.Empty)
  8175. {
  8176. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8177. button__FacMode_Start.Enabled = false;
  8178. return;
  8179. }
  8180. try
  8181. {
  8182. if (中置电机ToolStripMenuItem.Checked == true)
  8183. {
  8184. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  8185. {
  8186. label_CheckModeStatus.Text = "存在故障!";
  8187. label_CheckModeResult.BackColor = Color.Red;
  8188. label_CheckModeResult.Text = "标签格式错误";
  8189. button_CheckModeStart.Enabled = true;
  8190. return;
  8191. }
  8192. }
  8193. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8194. {
  8195. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  8196. {
  8197. label_CheckModeStatus.Text = "存在故障!";
  8198. label_CheckModeResult.BackColor = Color.Red;
  8199. label_CheckModeResult.Text = "标签格式错误";
  8200. button_CheckModeStart.Enabled = true;
  8201. return;
  8202. }
  8203. }
  8204. }
  8205. catch (System.Exception)
  8206. {
  8207. label_CheckModeStatus.Text = "存在故障!";
  8208. label_CheckModeResult.BackColor = Color.Red;
  8209. label_CheckModeResult.Text = "标签格式错误";
  8210. button_CheckModeStart.Enabled = true;
  8211. return;
  8212. }
  8213. //打开串口
  8214. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  8215. if (!mySerialProcess.mySerial.IsOpen)
  8216. {
  8217. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8218. button__FacMode_Start.Enabled = false;
  8219. return;
  8220. }
  8221. //流水号计数
  8222. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  8223. serial += 1;
  8224. label_CheckModeSerial.Text = serial.ToString();
  8225. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  8226. //创建线程,执行测试任务
  8227. Thread th = new Thread(CheckModeTest_Task);
  8228. th.Start();
  8229. }
  8230. /// <summary>
  8231. /// 执行一次测试任务
  8232. /// </summary>
  8233. private void CheckModeTest_Task()
  8234. {
  8235. //开始测试
  8236. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  8237. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  8238. //变量定义
  8239. var Code = new byte[255];//发送的指令数据
  8240. ushort DataTemp;
  8241. short DataTemp_Int16;
  8242. string ResultPathName = "";
  8243. label_CheckModeStatus.Text = "开始测试";
  8244. BootInfo = "";
  8245. Delay_ms(500);
  8246. label_CheckModeStatus.Text = "系统开机";
  8247. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  8248. if (uARTToolStripMenuItem.Checked)
  8249. {
  8250. Code[0] = (byte)'R';
  8251. Code[1] = (byte)'E';
  8252. Code[2] = (byte)'S';
  8253. Code[3] = (byte)'E';
  8254. Code[4] = (byte)'T';
  8255. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  8256. Delay_ms(500);
  8257. }
  8258. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  8259. //确保测试前先关机,发送关机指令再发送开机指令
  8260. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  8261. Code[0] = 0xF0;
  8262. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8263. Delay_ms(1500);
  8264. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  8265. Code[0] = 0xF1;
  8266. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  8267. ACK_WaitCnt = 0;
  8268. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  8269. while (ACK_WaitCnt <= 20) ; //10s
  8270. //检查BOOT版本
  8271. if (BootInfo != string.Empty)
  8272. {
  8273. label_CheckModeBoot.BackColor = Color.Green;
  8274. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  8275. Delay_ms(500);
  8276. }
  8277. else
  8278. {
  8279. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  8280. label_CheckModeStatus.Text = "存在故障!";
  8281. label_CheckModeResult.BackColor = Color.Red;
  8282. label_CheckModeResult.Text = "测试异常";
  8283. Delay_ms(500);
  8284. //存储异常并上传
  8285. CheckMode_Stop(false);
  8286. return;
  8287. }
  8288. #if false
  8289. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  8290. {
  8291. Code[0] = 0x00;//5S协议
  8292. Code[1] = 0x00;
  8293. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8294. Delay_ms(500);
  8295. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8296. Delay_ms(500);
  8297. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  8298. }
  8299. #endif
  8300. //发送指令读取版本信息
  8301. do
  8302. {
  8303. label_CheckModeStatus.Text = "读取版本信息";
  8304. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  8305. //发送指令读取版本
  8306. Class_Motor_Ver.Mode = "---";
  8307. Class_Motor_Ver.SN = "---";
  8308. Class_Motor_Ver.HW = "---";
  8309. Class_Motor_Ver.FW = "---";
  8310. Class_Motor_Ver.Special = "---";
  8311. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8312. ACK_WaitCnt = 0;
  8313. while (ACK_WaitCnt <= 2) ; //1s
  8314. if (Class_Motor_Ver.Mode == "---")
  8315. {
  8316. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  8317. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8318. ACK_WaitCnt = 0;
  8319. while (ACK_WaitCnt <= 2) ; //1s
  8320. if (Class_Motor_Ver.Mode == "---")
  8321. {
  8322. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  8323. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  8324. ACK_WaitCnt = 0;
  8325. while (ACK_WaitCnt <= 2) ; //1s
  8326. if (Class_Motor_Ver.Mode == "---")
  8327. {
  8328. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  8329. label_CheckModeStatus.Text = "存在故障!";
  8330. label_CheckModeResult.BackColor = Color.Red;
  8331. label_CheckModeResult.Text = "测试异常";
  8332. Delay_ms(500);
  8333. //存储异常并上传
  8334. CheckMode_Stop(false);
  8335. return;
  8336. }
  8337. }
  8338. }
  8339. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8340. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8341. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8342. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8343. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8344. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8345. Delay_ms(500);
  8346. } while (false);
  8347. //软件版本检查
  8348. if (checkBox_CheckModeFWVer.Checked)
  8349. {
  8350. //判断版本是否正确
  8351. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8352. string VerRead = "";
  8353. try
  8354. {
  8355. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8356. }
  8357. catch (System.Exception)
  8358. {
  8359. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8360. label_CheckModeStatus.Text = "存在故障!";
  8361. label_CheckModeResult.BackColor = Color.Red;
  8362. label_CheckModeResult.Text = "测试异常";
  8363. Delay_ms(500);
  8364. //存储异常并上传
  8365. CheckMode_Stop(false);
  8366. return;
  8367. }
  8368. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8369. {
  8370. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8371. label_CheckModeStatus.Text = "存在故障!";
  8372. label_CheckModeResult.BackColor = Color.Red;
  8373. label_CheckModeResult.Text = "测试异常";
  8374. Delay_ms(500);
  8375. //存储异常并上传
  8376. CheckMode_Stop(false);
  8377. return;
  8378. }
  8379. label_CheckModeFWVer.BackColor = Color.Green;
  8380. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8381. Delay_ms(500);
  8382. }
  8383. else
  8384. {
  8385. label_CheckModeFWVer.BackColor = Color.Yellow;
  8386. label_CheckModeStatus.Text = "跳过软件版本查询";
  8387. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8388. Delay_ms(500);
  8389. }
  8390. //打标信息核对
  8391. if (checkBox_CheckModeSN.Checked)
  8392. {
  8393. label_CheckModeStatus.Text = "核对打标信息";
  8394. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8395. //根据扫码信息获取型号和SN
  8396. string ScanInfo = textBox_CheckModeScan.Text;
  8397. string regexInfo = "";
  8398. string[] InfoList = { "" };
  8399. try
  8400. {
  8401. if (中置电机ToolStripMenuItem.Checked == true)
  8402. {
  8403. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8404. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8405. }
  8406. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8407. {
  8408. if (!ScanInfo.Contains("/")) //老编码规则
  8409. {
  8410. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8411. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8412. string Spec = InfoList[1];
  8413. string Sn = InfoList[2];
  8414. InfoList[0] = Model.Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8415. InfoList[1] = Sn;
  8416. }
  8417. else //新编码规则
  8418. {
  8419. Dictionary<string, string> Dic_Ver = new Dictionary<string, string>
  8420. {
  8421. { "01", "A" },
  8422. { "02", "B" },
  8423. { "03", "C" },
  8424. { "04", "D" },
  8425. { "05", "E" },
  8426. { "06", "F" },
  8427. { "07", "G" },
  8428. { "08", "H" },
  8429. { "09", "I" }
  8430. };
  8431. Dictionary<string, string> Dic_Vol = new Dictionary<string, string>
  8432. {
  8433. { "24V", "A" },
  8434. { "36V", "B" },
  8435. { "42V", "C" },
  8436. { "48V", "D" },
  8437. { "52V", "E" },
  8438. { "60V", "F" }
  8439. };
  8440. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8441. string Model = InfoList[0].Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC");
  8442. string Spec = InfoList[1].Replace("-", "").Replace("/", "");
  8443. string Sn = InfoList[2];
  8444. InfoList[0] = Model[2] + Dic_Ver[Model.Substring(3, 2)] + Model[5] + Dic_Ver[Model.Substring(6, 2)] + Model[9];
  8445. InfoList[0] += Dic_Vol[Spec.Substring(0, 3)] + Spec.Substring(3, 3) + Spec.Substring(13, 4) + Spec.Substring(Spec.Length - 4, 3);
  8446. InfoList[1] = Sn;
  8447. }
  8448. }
  8449. }
  8450. catch
  8451. {
  8452. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8453. label_FacModeStatus.Text = "存在故障!";
  8454. label_FacModeResult.BackColor = Color.Red;
  8455. label_FacModeResult.Text = "标签格式错误";
  8456. Delay_ms(500);
  8457. //存储异常并上传
  8458. CheckMode_Stop(false);
  8459. return;
  8460. }
  8461. //核对型号
  8462. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8463. {
  8464. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8465. label_CheckModeStatus.Text = "存在故障!";
  8466. label_CheckModeResult.BackColor = Color.Red;
  8467. label_CheckModeResult.Text = "测试异常";
  8468. Delay_ms(500);
  8469. //存储异常并上传
  8470. CheckMode_Stop(false);
  8471. return;
  8472. }
  8473. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8474. Delay_ms(500);
  8475. //核对SN
  8476. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8477. {
  8478. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8479. label_CheckModeStatus.Text = "存在故障!";
  8480. label_CheckModeResult.BackColor = Color.Red;
  8481. label_CheckModeResult.Text = "测试异常";
  8482. Delay_ms(500);
  8483. //存储异常并上传
  8484. CheckMode_Stop(false);
  8485. return;
  8486. }
  8487. label_CheckModeSN.BackColor = Color.Green;
  8488. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8489. Delay_ms(500);
  8490. }
  8491. else
  8492. {
  8493. label_CheckModeSN.BackColor = Color.Yellow;
  8494. label_CheckModeStatus.Text = "跳过打标信息确认";
  8495. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8496. Delay_ms(500);
  8497. }
  8498. //参数检验
  8499. if (checkBox_CheckModeCfg.Checked)
  8500. {
  8501. //读取配置文件信息
  8502. label_CheckModeStatus.Text = "参数检查";
  8503. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8504. //配置文件
  8505. List<byte[]> CmdList = new List<byte[]>();
  8506. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8507. //从服务器下载文件
  8508. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8509. {
  8510. string SelectFile = "";
  8511. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8512. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8513. {
  8514. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8515. }
  8516. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8517. //打开文件
  8518. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8519. ConfigCmd.Clear();
  8520. while (streamReader.Peek() != -1)
  8521. {
  8522. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8523. if (fileLineInfo.Contains("["))
  8524. {
  8525. if (fileLineInfo.Contains("助力参数"))
  8526. {
  8527. fileLineInfo = streamReader.ReadLine();
  8528. }
  8529. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8530. }
  8531. }
  8532. streamReader.Close();
  8533. }
  8534. //从本地加载文件
  8535. else
  8536. {
  8537. string SelectFile = "";
  8538. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8539. //打开文件
  8540. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8541. ConfigCmd.Clear();
  8542. while (streamReader.Peek() != -1)
  8543. {
  8544. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8545. if (fileLineInfo.Contains("["))
  8546. {
  8547. if (fileLineInfo.Contains("助力参数"))
  8548. {
  8549. fileLineInfo = streamReader.ReadLine();
  8550. }
  8551. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8552. }
  8553. }
  8554. streamReader.Close();
  8555. }
  8556. int CmdNum = ConfigCmd.Count(); //指令个数
  8557. Delay_ms(500);
  8558. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8559. Delay_ms(500);
  8560. //逐条读取比较
  8561. try
  8562. {
  8563. foreach (string key in ConfigCmd.Keys)
  8564. {
  8565. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8566. CmdRevStrTemp = "";
  8567. if (key.Contains("曲线"))
  8568. {
  8569. byte LineNum = 0;
  8570. var code = new byte[4];
  8571. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8572. if (LineNum <= 5)
  8573. {
  8574. code[0] = (byte)(LineNum & 0xFF);
  8575. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8576. code[2] = (byte)(LineNum & 0xFF);
  8577. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8578. }
  8579. else
  8580. {
  8581. code[0] = (byte)(LineNum & 0xFF);
  8582. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8583. code[2] = (byte)(5 & 0xFF);
  8584. code[3] = (byte)((5 >> 8) & 0xFF);
  8585. }
  8586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8587. }
  8588. else
  8589. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8590. Delay_ms(500);
  8591. if (CmdRevStrTemp == string.Empty)
  8592. {
  8593. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8594. if (key.Contains("曲线"))
  8595. {
  8596. byte LineNum = 0;
  8597. var code = new byte[4];
  8598. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8599. if (LineNum <= 5)
  8600. {
  8601. code[0] = (byte)(LineNum & 0xFF);
  8602. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8603. code[2] = (byte)(LineNum & 0xFF);
  8604. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8605. }
  8606. else
  8607. {
  8608. code[0] = (byte)(LineNum & 0xFF);
  8609. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8610. code[2] = (byte)(5 & 0xFF);
  8611. code[3] = (byte)((5 >> 8) & 0xFF);
  8612. }
  8613. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8614. }
  8615. else
  8616. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8617. Delay_ms(500);
  8618. if (CmdRevStrTemp == string.Empty)
  8619. {
  8620. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8621. if (key.Contains("曲线"))
  8622. {
  8623. byte LineNum = 0;
  8624. var code = new byte[4];
  8625. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8626. if (LineNum <= 5)
  8627. {
  8628. code[0] = (byte)(LineNum & 0xFF);
  8629. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8630. code[2] = (byte)(LineNum & 0xFF);
  8631. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8632. }
  8633. else
  8634. {
  8635. code[0] = (byte)(LineNum & 0xFF);
  8636. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8637. code[2] = (byte)(5 & 0xFF);
  8638. code[3] = (byte)((5 >> 8) & 0xFF);
  8639. }
  8640. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8641. }
  8642. else
  8643. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8644. Delay_ms(500);
  8645. if (CmdRevStrTemp == string.Empty)
  8646. {
  8647. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8648. label_CheckModeStatus.Text = "存在故障!";
  8649. label_CheckModeResult.BackColor = Color.Red;
  8650. label_CheckModeResult.Text = "测试异常";
  8651. Delay_ms(500);
  8652. //存储异常并上传
  8653. CheckMode_Stop(false);
  8654. return;
  8655. }
  8656. }
  8657. }
  8658. //比较当前指令,读取的配置文件和返回数据比较
  8659. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8660. string ParamRead = "";
  8661. ushort CmdGet = Convert.ToUInt16(CmdRevStrTemp.Substring(0, 6).Trim().Replace(" ", ""), 16);//接收到指令的命令字
  8662. ushort CmdRev = myParams.ConfigCheckRevCmd[key];//接收指令设计值
  8663. if (CmdGet != CmdRev)
  8664. {
  8665. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "接收指令不正确" + "\r\n");
  8666. richTextBox_CheckModeLog.AppendText("接收指令:" + "0x" + CmdGet.ToString("X2") + "\r\n");
  8667. richTextBox_CheckModeLog.AppendText("正确指令应为:" + "0x" + CmdRev.ToString("X2") + "\r\n");
  8668. label_CheckModeStatus.Text = "存在故障!";
  8669. label_CheckModeResult.BackColor = Color.Red;
  8670. label_CheckModeResult.Text = "测试异常";
  8671. Delay_ms(500);
  8672. //存储异常并上传
  8673. CheckMode_Stop(false);
  8674. return;
  8675. }
  8676. if (string.Compare(key, "[其它传感器参数]") == 0)
  8677. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉命令字、力矩传感器标定参数
  8678. else if (string.Compare(key, "[力矩传感器参数]") == 0)
  8679. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6 - 36).Trim(); //去掉命令字、其它传感器参数
  8680. else if (string.Compare(key, "[控制参数]") == 0)
  8681. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉命令字、位置零点
  8682. else
  8683. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8684. if (ParamWrite.Contains(ParamRead))
  8685. {
  8686. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8687. continue;
  8688. }
  8689. else
  8690. {
  8691. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8692. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8693. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8694. label_CheckModeStatus.Text = "存在故障!";
  8695. label_CheckModeResult.BackColor = Color.Red;
  8696. label_CheckModeResult.Text = "测试异常";
  8697. Delay_ms(500);
  8698. //存储异常并上传
  8699. CheckMode_Stop(false);
  8700. return;
  8701. }
  8702. }
  8703. }
  8704. catch (System.Exception)
  8705. {
  8706. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验失败" + "\r\n");
  8707. label_CheckModeStatus.Text = "存在故障!";
  8708. label_CheckModeResult.BackColor = Color.Red;
  8709. label_CheckModeResult.Text = "测试异常";
  8710. Delay_ms(500);
  8711. //存储异常并上传
  8712. CheckMode_Stop(false);
  8713. return;
  8714. }
  8715. label_CheckModeCfg.BackColor = Color.Green;
  8716. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8717. Delay_ms(500);
  8718. }
  8719. else
  8720. {
  8721. label_CheckModeCfg.BackColor = Color.Yellow;
  8722. label_CheckModeStatus.Text = "跳过参数检验";
  8723. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8724. Delay_ms(500);
  8725. }
  8726. //读取力矩传感器
  8727. do
  8728. {
  8729. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8730. //发送指令读取力矩传感器标定数据
  8731. CmdRevStrTemp = "";
  8732. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8733. ACK_WaitCnt = 0;
  8734. while (ACK_WaitCnt <= 2) ; //1s
  8735. if (CmdRevStrTemp == string.Empty)
  8736. {
  8737. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8738. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8739. ACK_WaitCnt = 0;
  8740. while (ACK_WaitCnt <= 2) ; //1s
  8741. if (CmdRevStrTemp == string.Empty)
  8742. {
  8743. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8744. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8745. ACK_WaitCnt = 0;
  8746. while (ACK_WaitCnt <= 2) ; //1s
  8747. if (CmdRevStrTemp == string.Empty)
  8748. {
  8749. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8750. label_CheckModeStatus.Text = "存在故障!";
  8751. label_CheckModeResult.BackColor = Color.Red;
  8752. label_CheckModeResult.Text = "测试异常";
  8753. Delay_ms(500);
  8754. //存储异常并上传
  8755. CheckMode_Stop(false);
  8756. return;
  8757. }
  8758. }
  8759. }
  8760. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8761. //取力矩传感器数据
  8762. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8763. ushort MaxTorque;
  8764. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8765. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8766. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8767. if (Cmd != 0xB528)
  8768. {
  8769. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8770. label_CheckModeStatus.Text = "存在故障!";
  8771. label_CheckModeResult.BackColor = Color.Red;
  8772. label_CheckModeResult.Text = "测试异常";
  8773. Delay_ms(500);
  8774. //存储异常并上传
  8775. CheckMode_Stop(false);
  8776. return;
  8777. }
  8778. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8779. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8780. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8781. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8782. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8783. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8784. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8785. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8786. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8787. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8788. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8789. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8790. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8791. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8792. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8793. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8794. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8795. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8796. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8797. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8798. //传感器标定检验
  8799. if (checkBox_CheckModeTorque.Checked)
  8800. {
  8801. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8802. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8803. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8804. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8805. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8806. //与设置值比较
  8807. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8808. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8809. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8810. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8811. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8812. )
  8813. {
  8814. label_CheckModeTorque.BackColor = Color.Green;
  8815. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8816. Delay_ms(500);
  8817. }
  8818. else
  8819. {
  8820. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8821. label_CheckModeStatus.Text = "存在故障!";
  8822. label_CheckModeResult.BackColor = Color.Red;
  8823. label_CheckModeResult.Text = "测试异常";
  8824. Delay_ms(500);
  8825. //存储异常并上传
  8826. CheckMode_Stop(false);
  8827. return;
  8828. }
  8829. }
  8830. else
  8831. {
  8832. label_CheckModeTorque.BackColor = Color.Yellow;
  8833. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8834. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8835. Delay_ms(500);
  8836. }
  8837. } while (false);
  8838. //读取MOS内阻校准参数
  8839. do
  8840. {
  8841. if (checkBox_CheckModeMos.Checked)
  8842. {
  8843. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8844. //读取显示校准返回数据
  8845. foreach (Control c in groupBox21.Controls)
  8846. {
  8847. if (c is TextBox)
  8848. c.Text = "";
  8849. }
  8850. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8851. ACK_WaitCnt = 0;
  8852. while (ACK_WaitCnt <= 2) ; //1s
  8853. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8854. {
  8855. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8856. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8857. ACK_WaitCnt = 0;
  8858. while (ACK_WaitCnt <= 2) ; //1s
  8859. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8860. {
  8861. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8862. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8863. ACK_WaitCnt = 0;
  8864. while (ACK_WaitCnt <= 2) ; //1s
  8865. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8866. {
  8867. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8868. label_CheckModeStatus.Text = "存在故障!";
  8869. label_CheckModeResult.BackColor = Color.Red;
  8870. label_CheckModeResult.Text = "测试异常";
  8871. Delay_ms(500);
  8872. //存储异常并上传
  8873. CheckMode_Stop(false);
  8874. return;
  8875. }
  8876. }
  8877. }
  8878. else
  8879. {
  8880. 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");
  8881. }
  8882. //与校准返回数据对比
  8883. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8884. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8885. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8886. 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])) &&
  8887. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8888. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8889. )
  8890. {
  8891. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8892. label_CheckModeMos.BackColor = Color.Green;
  8893. }
  8894. else
  8895. {
  8896. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8897. label_CheckModeStatus.Text = "存在故障!";
  8898. label_CheckModeResult.BackColor = Color.Red;
  8899. label_CheckModeResult.Text = "测试异常";
  8900. Delay_ms(500);
  8901. //存储异常并上传
  8902. CheckMode_Stop(false);
  8903. return;
  8904. }
  8905. }
  8906. else
  8907. {
  8908. label_CheckModeMos.BackColor = Color.Yellow;
  8909. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8910. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8911. Delay_ms(500);
  8912. }
  8913. } while (false);
  8914. //读取位置校准参数
  8915. do
  8916. {
  8917. if (checkBox_CheckModeAngle.Checked)
  8918. {
  8919. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据" + "\r\n");
  8920. //发送指令读取位置
  8921. CmdRevStrTemp = "";
  8922. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  8923. ACK_WaitCnt = 0;
  8924. while (ACK_WaitCnt <= 2) ; //1s
  8925. if (CmdRevStrTemp == string.Empty)
  8926. {
  8927. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第1次重发" + "\r\n");
  8928. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8929. ACK_WaitCnt = 0;
  8930. while (ACK_WaitCnt <= 2) ; //1s
  8931. if (CmdRevStrTemp == string.Empty)
  8932. {
  8933. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取位置校准数据,第2次重发" + "\r\n");
  8934. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x3E00, null);
  8935. ACK_WaitCnt = 0;
  8936. while (ACK_WaitCnt <= 2) ; //1s
  8937. if (CmdRevStrTemp == string.Empty)
  8938. {
  8939. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取失败" + "\r\n");
  8940. label_CheckModeStatus.Text = "存在故障!";
  8941. label_CheckModeResult.BackColor = Color.Red;
  8942. label_CheckModeResult.Text = "测试异常";
  8943. Delay_ms(500);
  8944. //存储异常并上传
  8945. CheckMode_Stop(false);
  8946. return;
  8947. }
  8948. }
  8949. }
  8950. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据读取成功" + "\r\n");
  8951. //取零点数据
  8952. UInt16 AngleZero_Init = 0, AngleZero_Cur = 0;
  8953. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8954. ushort Cmd = (ushort)((DataArray[0] << 8) + DataArray[1]);
  8955. if (Cmd != 0xB420)
  8956. {
  8957. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器参数错误,CMD: 0x" + Convert.ToString(Cmd, 16).PadLeft(2, '0').ToUpper() + "\r\n");
  8958. label_CheckModeStatus.Text = "存在故障!";
  8959. label_CheckModeResult.BackColor = Color.Red;
  8960. label_CheckModeResult.Text = "测试异常";
  8961. Delay_ms(500);
  8962. //存储异常并上传
  8963. CheckMode_Stop(false);
  8964. return;
  8965. }
  8966. AngleZero_Init = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8967. AngleZero_Cur = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8968. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置出厂零点: " + AngleZero_Init.ToString() + ",位置当前零点: " + AngleZero_Cur.ToString() + "\r\n");
  8969. int AngleZeroDiff = Math.Abs(AngleZero_Cur - AngleZero_Init);
  8970. int AngleZeroTH = Convert.ToInt32(textBox_AngleZeroTh.Text);
  8971. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置零点校准值: " + AngleZeroDiff.ToString() + ",判断阈值: " + AngleZeroTH.ToString() + "\r\n");
  8972. //判断
  8973. if (AngleZeroDiff <= AngleZeroTH)
  8974. {
  8975. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准合格" + "\r\n");
  8976. label_CheckModeAngle.BackColor = Color.Green;
  8977. }
  8978. else
  8979. {
  8980. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置传感器校准超范围" + "\r\n");
  8981. label_CheckModeStatus.Text = "存在故障!";
  8982. label_CheckModeResult.BackColor = Color.Red;
  8983. label_CheckModeResult.Text = "测试异常";
  8984. Delay_ms(500);
  8985. //存储异常并上传
  8986. CheckMode_Stop(false);
  8987. return;
  8988. }
  8989. }
  8990. else
  8991. {
  8992. label_CheckModeAngle.BackColor = Color.Yellow;
  8993. label_CheckModeStatus.Text = "跳过位置传感器校准检验";
  8994. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置传感器校准检验" + "\r\n");
  8995. Delay_ms(500);
  8996. }
  8997. } while (false);
  8998. //测试合格
  8999. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  9000. label_CheckModeStatus.Text = "测试结束!";
  9001. label_CheckModeResult.BackColor = Color.Green;
  9002. label_CheckModeResult.Text = "测试合格";
  9003. Delay_ms(500);
  9004. //存储并上传
  9005. CheckMode_Stop(true);
  9006. return;
  9007. }
  9008. private void CheckModeLabelInit()
  9009. {
  9010. //测试状态标签
  9011. label_CheckModeResult.BackColor = Color.Yellow;
  9012. label_CheckModeResult.Text = "测试中";
  9013. //测试过程标签
  9014. label_CheckModeStatus.Text = "测试就绪";
  9015. //测试结果标签
  9016. foreach (Control c in groupBox31.Controls)
  9017. {
  9018. if (c is Label)
  9019. {
  9020. if (c.Text == string.Empty)
  9021. c.BackColor = Color.Red;
  9022. }
  9023. }
  9024. }
  9025. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  9026. {
  9027. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  9028. }
  9029. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  9030. {
  9031. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  9032. }
  9033. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  9034. {
  9035. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  9036. UInt32 hour = Time / 3600;
  9037. UInt32 min = (Time % 3600) / 60;
  9038. UInt32 s = (Time % 60);
  9039. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  9040. }
  9041. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  9042. {
  9043. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  9044. richTextBox_CheckModeLog.ScrollToCaret();
  9045. }
  9046. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  9047. {
  9048. TorqueParamsForm.ShowDialog();
  9049. }
  9050. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  9051. {
  9052. if (e.KeyCode == Keys.Enter)
  9053. CheckTestStart();
  9054. }
  9055. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  9056. {
  9057. if (e.KeyCode == Keys.Enter)
  9058. TestStart();
  9059. }
  9060. private void button_SpeedDec10_Click(object sender, EventArgs e)
  9061. {
  9062. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9063. if (Percent <= 10)
  9064. Percent = 0;
  9065. else
  9066. Percent -= 10;
  9067. //生产模式转速设置值更新
  9068. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9069. //设置转速百分比
  9070. var Data = new byte[1];
  9071. Data[0] = (byte)Percent;
  9072. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9073. }
  9074. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  9075. {
  9076. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9077. if (Percent >= 90)
  9078. Percent = 100;
  9079. else
  9080. Percent += 10;
  9081. //生产模式转速设置值更新
  9082. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9083. //设置转速百分比
  9084. var Data = new byte[1];
  9085. Data[0] = (byte)Percent;
  9086. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9087. }
  9088. private void button_SpeedDec1_Click(object sender, EventArgs e)
  9089. {
  9090. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9091. if (Percent <= 1)
  9092. Percent = 0;
  9093. else
  9094. Percent -= 1;
  9095. //生产模式转速设置值更新
  9096. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9097. //设置转速百分比
  9098. var Data = new byte[1];
  9099. Data[0] = (byte)Percent;
  9100. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9101. }
  9102. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  9103. {
  9104. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  9105. if (Percent >= 99)
  9106. Percent = 100;
  9107. else
  9108. Percent += 1;
  9109. //生产模式转速设置值更新
  9110. textBox_MotorSpeedPercent.Text = Percent.ToString();
  9111. //设置转速百分比
  9112. var Data = new byte[1];
  9113. Data[0] = (byte)Percent;
  9114. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  9115. }
  9116. bool WriteLockStatus = true;
  9117. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  9118. {
  9119. if (WriteLockStatus == true)
  9120. {
  9121. EnterForm1.ShowDialog();
  9122. try
  9123. {
  9124. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9125. {
  9126. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9127. {
  9128. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9129. foreach (Control c in groupBox2.Controls)
  9130. {
  9131. if (c is CheckBox)
  9132. c.Enabled = true;
  9133. }
  9134. WriteLockStatus = !WriteLockStatus;
  9135. }
  9136. else
  9137. {
  9138. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9139. }
  9140. }
  9141. else
  9142. {
  9143. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9144. }
  9145. }
  9146. catch (Exception)
  9147. {
  9148. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9149. }
  9150. }
  9151. else
  9152. {
  9153. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9154. foreach (Control c in groupBox2.Controls)
  9155. {
  9156. if (c is CheckBox)
  9157. c.Enabled = false;
  9158. }
  9159. WriteLockStatus = !WriteLockStatus;
  9160. }
  9161. }
  9162. bool ReadLockStatus = true;
  9163. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  9164. {
  9165. if (ReadLockStatus == true)
  9166. {
  9167. EnterForm1.ShowDialog();
  9168. try
  9169. {
  9170. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9171. {
  9172. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  9173. {
  9174. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  9175. foreach (Control c in groupBox29.Controls)
  9176. {
  9177. if (c is CheckBox)
  9178. c.Enabled = true;
  9179. }
  9180. ReadLockStatus = !ReadLockStatus;
  9181. }
  9182. else
  9183. {
  9184. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9185. }
  9186. }
  9187. else
  9188. {
  9189. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9190. }
  9191. }
  9192. catch (Exception)
  9193. {
  9194. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9195. }
  9196. }
  9197. else
  9198. {
  9199. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  9200. foreach (Control c in groupBox29.Controls)
  9201. {
  9202. if (c is CheckBox)
  9203. c.Enabled = false;
  9204. }
  9205. ReadLockStatus = !ReadLockStatus;
  9206. }
  9207. }
  9208. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  9209. {
  9210. System.Diagnostics.Process.Start("osk.exe");
  9211. }
  9212. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  9213. {
  9214. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  9215. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  9216. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  9217. }
  9218. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  9219. {
  9220. comboBox_FacModeCfgDate.SelectedIndex = -1;
  9221. comboBox_FacModeCfgFile.SelectedIndex = -1;
  9222. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  9223. }
  9224. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  9225. {
  9226. VersionForm.ShowDialog();
  9227. }
  9228. private void button_MOS_Cal_Click(object sender, EventArgs e)
  9229. {
  9230. textBox_MOS_R1.Text = "";
  9231. textBox_MOS_R2.Text = "";
  9232. textBox_MOS_R3.Text = "";
  9233. try
  9234. {
  9235. var Code = new byte[18];
  9236. for (int i = 0; i < 18; i++)
  9237. Code[i] = 0;
  9238. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9239. ushort uwDataTemp = 0;
  9240. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9241. Code[2] = (byte)(uwDataTemp & 0xFF);
  9242. Code[3] = (byte)(uwDataTemp >> 8);
  9243. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9244. Code[4] = (byte)(uwDataTemp & 0xFF);
  9245. Code[5] = (byte)(uwDataTemp >> 8);
  9246. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9247. Code[6] = (byte)(uwDataTemp & 0xFF);
  9248. Code[7] = (byte)(uwDataTemp >> 8);
  9249. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9250. Code[8] = (byte)(uwDataTemp & 0xFF);
  9251. Code[9] = (byte)(uwDataTemp >> 8);
  9252. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9253. Code[10] = (byte)(uwDataTemp & 0xFF);
  9254. Code[11] = (byte)(uwDataTemp >> 8);
  9255. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  9256. }
  9257. catch (Exception)
  9258. {
  9259. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9260. }
  9261. }
  9262. private void button_MOS_Read_Click(object sender, EventArgs e)
  9263. {
  9264. foreach (Control c in groupBox21.Controls)
  9265. {
  9266. if (c is TextBox)
  9267. c.Text = "";
  9268. }
  9269. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  9270. }
  9271. private void button_MOS_Write_Click(object sender, EventArgs e)
  9272. {
  9273. try
  9274. {
  9275. var Code = new byte[34];
  9276. for (int i = 0; i < 34; i++)
  9277. Code[i] = 0;
  9278. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9279. ushort uwDataTemp = 0;
  9280. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  9281. Code[2] = (byte)(uwDataTemp & 0xFF);
  9282. Code[3] = (byte)(uwDataTemp >> 8);
  9283. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  9284. Code[4] = (byte)(uwDataTemp & 0xFF);
  9285. Code[5] = (byte)(uwDataTemp >> 8);
  9286. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  9287. Code[6] = (byte)(uwDataTemp & 0xFF);
  9288. Code[7] = (byte)(uwDataTemp >> 8);
  9289. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  9290. Code[8] = (byte)(uwDataTemp & 0xFF);
  9291. Code[9] = (byte)(uwDataTemp >> 8);
  9292. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  9293. Code[10] = (byte)(uwDataTemp & 0xFF);
  9294. Code[11] = (byte)(uwDataTemp >> 8);
  9295. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  9296. Code[12] = (byte)(uwDataTemp & 0xFF);
  9297. Code[13] = (byte)(uwDataTemp >> 8);
  9298. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  9299. Code[14] = (byte)(uwDataTemp & 0xFF);
  9300. Code[15] = (byte)(uwDataTemp >> 8);
  9301. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  9302. Code[16] = (byte)(uwDataTemp & 0xFF);
  9303. Code[17] = (byte)(uwDataTemp >> 8);
  9304. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  9305. }
  9306. catch (Exception)
  9307. {
  9308. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9309. }
  9310. }
  9311. /// <summary>
  9312. /// 测试模式点击文本框自动全选
  9313. /// </summary>
  9314. /// <param name="sender"></param>
  9315. /// <param name="e"></param>
  9316. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  9317. {
  9318. textBox_FacModeScan.SelectAll();
  9319. }
  9320. /// <summary>
  9321. /// 检验模式点击文本框自动全选
  9322. /// </summary>
  9323. /// <param name="sender"></param>
  9324. /// <param name="e"></param>
  9325. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  9326. {
  9327. textBox_CheckModeScan.SelectAll();
  9328. }
  9329. /// <summary>
  9330. /// 鼠标放置显示连接服务器信息
  9331. /// </summary>
  9332. /// <param name="sender"></param>
  9333. /// <param name="e"></param>
  9334. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  9335. {
  9336. // 创建the ToolTip
  9337. ToolTip toolTip1 = new ToolTip();
  9338. // 设置显示样式
  9339. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  9340. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9341. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9342. toolTip1.ShowAlways = true;//是否显示提示框
  9343. if (myFtp.IsNetConnected)
  9344. {
  9345. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  9346. }
  9347. else
  9348. {
  9349. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  9350. }
  9351. }
  9352. /// <summary>
  9353. /// UART协议类型修改
  9354. /// </summary>
  9355. /// <param name="sender"></param>
  9356. /// <param name="e"></param>
  9357. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  9358. {
  9359. var Code = new byte[2];
  9360. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  9361. Code[1] = 0x00;
  9362. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  9363. }
  9364. /// <summary>
  9365. /// 显示本机信息
  9366. /// </summary>
  9367. /// <param name="sender"></param>
  9368. /// <param name="e"></param>
  9369. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  9370. {
  9371. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9372. }
  9373. /// <summary>
  9374. /// 量产模式删除当前选中文件
  9375. /// </summary>
  9376. /// <param name="sender"></param>
  9377. /// <param name="e"></param>
  9378. private void label112_DoubleClick(object sender, EventArgs e)
  9379. {
  9380. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9381. {
  9382. EnterForm1.ShowDialog();
  9383. try
  9384. {
  9385. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9386. {
  9387. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9388. {
  9389. try
  9390. {
  9391. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  9392. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  9393. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  9394. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9395. }
  9396. catch (Exception)
  9397. {
  9398. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9399. }
  9400. }
  9401. else
  9402. {
  9403. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9404. }
  9405. }
  9406. }
  9407. catch (Exception)
  9408. {
  9409. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9410. }
  9411. }
  9412. }
  9413. /// <summary>
  9414. /// 检验模式删除当前选中文件
  9415. /// </summary>
  9416. /// <param name="sender"></param>
  9417. /// <param name="e"></param>
  9418. private void label138_DoubleClick(object sender, EventArgs e)
  9419. {
  9420. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9421. {
  9422. EnterForm1.ShowDialog();
  9423. try
  9424. {
  9425. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9426. {
  9427. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9428. {
  9429. try
  9430. {
  9431. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  9432. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  9433. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  9434. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9435. }
  9436. catch (Exception)
  9437. {
  9438. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9439. }
  9440. }
  9441. else
  9442. {
  9443. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9444. }
  9445. }
  9446. }
  9447. catch (Exception)
  9448. {
  9449. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9450. }
  9451. }
  9452. }
  9453. /// <summary>
  9454. /// 读取整车信息2
  9455. /// </summary>
  9456. /// <param name="sender"></param>
  9457. /// <param name="e"></param>
  9458. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  9459. {
  9460. richTextBox_BikeParam2.Clear();
  9461. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  9462. }
  9463. /// <summary>
  9464. /// 写入整车信息2
  9465. /// </summary>
  9466. /// <param name="sender"></param>
  9467. /// <param name="e"></param>
  9468. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  9469. {
  9470. var ConfigParam = new byte[34];
  9471. for (int i = 0; i < 34; i++)
  9472. ConfigParam[i] = 0;
  9473. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9474. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9475. try
  9476. {
  9477. for (int i = 0; i < strDataTemp.Length; i++)
  9478. {
  9479. short wDataTemp = 0;
  9480. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9481. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  9482. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  9483. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  9484. }
  9485. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9486. }
  9487. catch (Exception)
  9488. {
  9489. timer_500ms.Enabled = false;
  9490. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9491. timer_500ms.Enabled = true;
  9492. }
  9493. }
  9494. /// <summary>
  9495. /// 读取用户骑行参数
  9496. /// </summary>
  9497. /// <param name="sender"></param>
  9498. /// <param name="e"></param>
  9499. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9500. {
  9501. richTextBox_UsrRidesParam.Clear();
  9502. if (checkBox_UserRideParam_OBC.Checked)
  9503. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9504. else
  9505. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9506. }
  9507. /// <summary>
  9508. /// 写入用户骑行参数
  9509. /// </summary>
  9510. /// <param name="sender"></param>
  9511. /// <param name="e"></param>
  9512. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9513. {
  9514. var ConfigParam = new byte[34];
  9515. for (int i = 0; i < 34; i++)
  9516. ConfigParam[i] = 0;
  9517. if (checkBox_UserRideParam_OBC.Checked)
  9518. {
  9519. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9520. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9521. try
  9522. {
  9523. for (int i = 0; i < strDataTemp.Length; i++)
  9524. {
  9525. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9526. }
  9527. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9528. }
  9529. catch (Exception)
  9530. {
  9531. timer_500ms.Enabled = false;
  9532. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9533. timer_500ms.Enabled = true;
  9534. }
  9535. }
  9536. else
  9537. {
  9538. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9539. try
  9540. {
  9541. for (int i = 0; i < strDataTemp.Length; i++)
  9542. {
  9543. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9544. }
  9545. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9546. }
  9547. catch (Exception)
  9548. {
  9549. timer_500ms.Enabled = false;
  9550. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9551. timer_500ms.Enabled = true;
  9552. }
  9553. }
  9554. }
  9555. /// <summary>
  9556. /// 读取产品标签
  9557. /// </summary>
  9558. /// <param name="sender"></param>
  9559. /// <param name="e"></param>
  9560. private void button_ReadTag_Click(object sender, EventArgs e)
  9561. {
  9562. textBox_TagInfo.Text = "---";
  9563. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9564. }
  9565. /// <summary>
  9566. /// 写入产品标签
  9567. /// </summary>
  9568. /// <param name="sender"></param>
  9569. /// <param name="e"></param>
  9570. private void button_WriteTag_Click(object sender, EventArgs e)
  9571. {
  9572. string User = textBox_TagInfo.Text;
  9573. var UserArray = new byte[32];
  9574. for (ushort i = 0; i < User.Length; i++)
  9575. {
  9576. UserArray[i] = (byte)User[i];
  9577. }
  9578. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9579. }
  9580. /// <summary>
  9581. /// 上位机读取骑行历史
  9582. /// </summary>
  9583. /// <param name="sender"></param>
  9584. /// <param name="e"></param>
  9585. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9586. {
  9587. textBox_ODO_KM.Text = "---";
  9588. textBox_ODO_TIME.Text = "---";
  9589. textBox_TRIP_KM.Text = "---";
  9590. textBox_TRIP_TIME.Text = "---";
  9591. textBox_OBC_TRIP_KM.Text = "";
  9592. textBox_OBC_TRIP_TIME.Text = "";
  9593. textBox_OBC_ODO_KM.Text = "";
  9594. textBox_OBC_ODO_TIME.Text = "";
  9595. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9596. }
  9597. /// <summary>
  9598. /// 上位机写入骑行历史
  9599. /// </summary>
  9600. /// <param name="sender"></param>
  9601. /// <param name="e"></param>
  9602. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9603. {
  9604. UInt32 Data;
  9605. var UserArray = new byte[16];
  9606. try
  9607. {
  9608. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9609. UserArray[0] = (byte)(Data & 0xFF);
  9610. UserArray[1] = (byte)(Data >> 8);
  9611. UserArray[2] = (byte)(Data >> 16);
  9612. UserArray[3] = (byte)(Data >> 24);
  9613. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9614. UserArray[4] = (byte)(Data & 0xFF);
  9615. UserArray[5] = (byte)(Data >> 8);
  9616. UserArray[6] = (byte)(Data >> 16);
  9617. UserArray[7] = (byte)(Data >> 24);
  9618. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9619. UserArray[8] = (byte)(Data & 0xFF);
  9620. UserArray[9] = (byte)(Data >> 8);
  9621. UserArray[10] = (byte)(Data >> 16);
  9622. UserArray[11] = (byte)(Data >> 24);
  9623. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9624. UserArray[12] = (byte)(Data & 0xFF);
  9625. UserArray[13] = (byte)(Data >> 8);
  9626. UserArray[14] = (byte)(Data >> 16);
  9627. UserArray[15] = (byte)(Data >> 24);
  9628. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9629. }
  9630. catch (Exception ex)
  9631. {
  9632. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9633. }
  9634. }
  9635. /// <summary>
  9636. /// 获取删除配置文件日期列表
  9637. /// </summary>
  9638. /// <param name="sender"></param>
  9639. /// <param name="e"></param>
  9640. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9641. {
  9642. string[] DateList = { "" };
  9643. //网络断开时直接退出
  9644. if (!myFtp.IsNetConnected)
  9645. return;
  9646. //从服务器更新日期列表
  9647. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9648. toolStripTextBox_DelCfgFile.Items.Clear();
  9649. //日期列表加载,显示最近30条
  9650. if (DateList.Length > 30)
  9651. {
  9652. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9653. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9654. }
  9655. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9656. {
  9657. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9658. }
  9659. }
  9660. /// <summary>
  9661. /// 删除指定配置文件
  9662. /// </summary>
  9663. /// <param name="sender"></param>
  9664. /// <param name="e"></param>
  9665. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9666. {
  9667. //提示输入文件名
  9668. Scan scan_form = new Scan();
  9669. scan_form.ShowDialog();
  9670. do
  9671. {
  9672. if (scan_form.textBox_Scan.Text == string.Empty)
  9673. {
  9674. timer_500ms.Enabled = false;
  9675. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9676. timer_500ms.Enabled = true;
  9677. break;
  9678. }
  9679. string DelFile = scan_form.textBox_Scan.Text;
  9680. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9681. {
  9682. EnterForm1.ShowDialog();
  9683. try
  9684. {
  9685. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9686. {
  9687. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9688. {
  9689. try
  9690. {
  9691. if (DelFile.Contains("."))
  9692. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9693. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9694. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9695. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9696. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9697. }
  9698. catch (Exception)
  9699. {
  9700. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9701. }
  9702. }
  9703. else
  9704. {
  9705. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9706. }
  9707. }
  9708. }
  9709. catch (Exception)
  9710. {
  9711. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9712. }
  9713. }
  9714. } while (false);
  9715. }
  9716. /// <summary>
  9717. /// 获取删除样机测试记录日期列表
  9718. /// </summary>
  9719. /// <param name="sender"></param>
  9720. /// <param name="e"></param>
  9721. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9722. {
  9723. string[] DateList = { "" };
  9724. //网络断开时直接退出
  9725. if (!myFtp.IsNetConnected)
  9726. return;
  9727. //从服务器更新日期列表
  9728. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9729. toolStripTextBox_DelLogFile.Items.Clear();
  9730. //日期列表加载,显示最近30天
  9731. if (DateList.Length > 30)
  9732. {
  9733. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9734. toolStripTextBox_DelLogFile.Items.Add("-----");
  9735. }
  9736. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9737. {
  9738. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9739. }
  9740. }
  9741. /// <summary>
  9742. /// 删除指定的样机测试记录
  9743. /// </summary>
  9744. /// <param name="sender"></param>
  9745. /// <param name="e"></param>
  9746. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9747. {
  9748. //提示输入文件名
  9749. Scan scan_form = new Scan();
  9750. scan_form.ShowDialog();
  9751. do
  9752. {
  9753. if (scan_form.textBox_Scan.Text == string.Empty)
  9754. {
  9755. timer_500ms.Enabled = false;
  9756. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9757. timer_500ms.Enabled = true;
  9758. break;
  9759. }
  9760. string DelFile = scan_form.textBox_Scan.Text;
  9761. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9762. {
  9763. EnterForm1.ShowDialog();
  9764. try
  9765. {
  9766. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9767. {
  9768. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9769. {
  9770. try
  9771. {
  9772. //删除指定目录下面所有文件和文件夹
  9773. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9774. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9775. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9776. }
  9777. catch (Exception)
  9778. {
  9779. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9780. }
  9781. }
  9782. else
  9783. {
  9784. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9785. }
  9786. }
  9787. }
  9788. catch (Exception)
  9789. {
  9790. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9791. }
  9792. }
  9793. } while (false);
  9794. }
  9795. /// <summary>
  9796. /// CAN协议选择
  9797. /// </summary>
  9798. /// <param name="sender"></param>
  9799. /// <param name="e"></param>
  9800. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9801. {
  9802. cANToolStripMenuItem.Checked= true;
  9803. uARTToolStripMenuItem.Checked = false;
  9804. UART协议ToolStripMenuItem.Visible = false;
  9805. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9806. }
  9807. /// <summary>
  9808. /// UART协议选择
  9809. /// </summary>
  9810. /// <param name="sender"></param>
  9811. /// <param name="e"></param>
  9812. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9813. {
  9814. cANToolStripMenuItem.Checked = false;
  9815. uARTToolStripMenuItem.Checked = true;
  9816. UART协议ToolStripMenuItem.Visible = true;
  9817. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9818. }
  9819. /// <summary>
  9820. /// 清除流水号
  9821. /// </summary>
  9822. /// <param name="sender"></param>
  9823. /// <param name="e"></param>
  9824. private void label131_DoubleClick(object sender, EventArgs e)
  9825. {
  9826. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9827. {
  9828. label_FacModeSerial.Text = "0";
  9829. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9830. }
  9831. }
  9832. /// <summary>
  9833. /// 清除流水号
  9834. /// </summary>
  9835. /// <param name="sender"></param>
  9836. /// <param name="e"></param>
  9837. private void label135_DoubleClick(object sender, EventArgs e)
  9838. {
  9839. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9840. {
  9841. label_CheckModeSerial.Text = "0";
  9842. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9843. }
  9844. }
  9845. /// <summary>
  9846. /// 打开自动更新
  9847. /// </summary>
  9848. /// <param name="sender"></param>
  9849. /// <param name="e"></param>
  9850. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9851. {
  9852. 打开ToolStripMenuItem.Checked = true;
  9853. 关闭ToolStripMenuItem.Checked = false;
  9854. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9855. }
  9856. /// <summary>
  9857. /// 关闭自动更新
  9858. /// </summary>
  9859. /// <param name="sender"></param>
  9860. /// <param name="e"></param>
  9861. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9862. {
  9863. 打开ToolStripMenuItem.Checked = false;
  9864. 关闭ToolStripMenuItem.Checked = true;
  9865. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9866. }
  9867. /// <summary>
  9868. /// 显示完整配置文件
  9869. /// </summary>
  9870. /// <param name="sender"></param>
  9871. /// <param name="e"></param>
  9872. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9873. {
  9874. // 创建the ToolTip
  9875. ToolTip toolTip1 = new ToolTip();
  9876. // 设置显示样式
  9877. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9878. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9879. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9880. toolTip1.ShowAlways = true;//是否显示提示框
  9881. // 设置伴随的对象.
  9882. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9883. }
  9884. /// <summary>
  9885. /// 显示完整配置文件
  9886. /// </summary>
  9887. /// <param name="sender"></param>
  9888. /// <param name="e"></param>
  9889. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9890. {
  9891. // 创建the ToolTip
  9892. ToolTip toolTip1 = new ToolTip();
  9893. // 设置显示样式
  9894. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9895. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9896. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9897. toolTip1.ShowAlways = true;//是否显示提示框
  9898. // 设置伴随的对象.
  9899. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9900. }
  9901. /// <summary>
  9902. /// 手动发送指令
  9903. /// </summary>
  9904. /// <param name="sender"></param>
  9905. /// <param name="e"></param>
  9906. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9907. {
  9908. //提示
  9909. Scan scan_form = new Scan();
  9910. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9911. scan_form.ShowDialog();
  9912. //发送写入的指令,填写ID、类型、命令字、数据
  9913. do
  9914. {
  9915. if (scan_form.textBox_Scan.Text == string.Empty)
  9916. {
  9917. timer_500ms.Enabled = false;
  9918. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9919. timer_500ms.Enabled = true;
  9920. break;
  9921. }
  9922. //输入文本转换为字节流
  9923. var InputData = new byte[256];
  9924. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9925. //ID
  9926. ushort ID;
  9927. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9928. //Mode
  9929. byte Mode;
  9930. Mode = InputData[2];
  9931. //Cmd
  9932. ushort Cmd;
  9933. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9934. //Data
  9935. var Data = new byte[Cmd & 0x00FF];
  9936. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9937. Data[i] = InputData[5 + i];
  9938. //发送数据
  9939. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9940. } while (false);
  9941. }
  9942. /// <summary>
  9943. /// 启动位置传感器校准
  9944. /// </summary>
  9945. /// <param name="sender"></param>
  9946. /// <param name="e"></param>
  9947. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9948. {
  9949. for (int i = 0; i < 7; i++)
  9950. for (int j = 0; j < 6; j++)
  9951. {
  9952. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9953. }
  9954. foreach (Control cr in tabPage_AngleCal.Controls)
  9955. {
  9956. if (cr is TextBox)
  9957. {
  9958. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9959. cr.Text = "";
  9960. }
  9961. }
  9962. var Data = new byte[2];
  9963. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9964. }
  9965. /// <summary>
  9966. /// 导出位置传感器校准数据
  9967. /// </summary>
  9968. /// <param name="sender"></param>
  9969. /// <param name="e"></param>
  9970. private void button_AngleExportData_Click(object sender, EventArgs e)
  9971. {
  9972. //读出产品信息
  9973. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9974. Delay_ms(200);
  9975. SaveFileDialog sfd = new SaveFileDialog
  9976. {
  9977. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9978. Filter = "文本文档(*.txt)|*.txt",
  9979. Title = "Save"
  9980. };
  9981. if (sfd.ShowDialog() != DialogResult.OK)
  9982. {
  9983. return;
  9984. }
  9985. string filepath = sfd.FileName;
  9986. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9987. using (StreamWriter sw = new StreamWriter(fs))
  9988. {
  9989. sw.Write("标准值 ");
  9990. sw.Write("60.00 ");
  9991. sw.Write("120.00 ");
  9992. sw.Write("180.00 ");
  9993. sw.Write("240.00 ");
  9994. sw.Write("300.00 ");
  9995. sw.Write("360.00 ");
  9996. for (int i = 0; i < 42; i++)
  9997. {
  9998. if ((i % 6 == 0))
  9999. {
  10000. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  10001. }
  10002. sw.Write(AngledataRecord[i] + " ");
  10003. }
  10004. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  10005. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  10006. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  10007. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  10008. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  10009. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  10010. sw.Flush();
  10011. }
  10012. fs.Close();
  10013. }
  10014. /// <summary>
  10015. /// 写入校准数据
  10016. /// </summary>
  10017. /// <param name="sender"></param>
  10018. /// <param name="e"></param>
  10019. private void button_AngleWrite_Click(object sender, EventArgs e)
  10020. {
  10021. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  10022. {
  10023. timer_500ms.Enabled = false;
  10024. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  10025. timer_500ms.Enabled = true;
  10026. return;
  10027. }
  10028. timer_500ms.Enabled = false;
  10029. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  10030. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10031. {
  10032. var SaveFlag = new byte[4];
  10033. for (int i = 0; i < 4; i++)
  10034. SaveFlag[i] = 0;
  10035. SaveFlag[0] = (byte)(1);
  10036. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  10037. if (data1 > 360)
  10038. {
  10039. data1 -= 360;
  10040. }
  10041. else if (data1 < -360)
  10042. {
  10043. data1 += 360;
  10044. }
  10045. Int16 data2 = (Int16)(data1 * 32768 / 360);
  10046. SaveFlag[2] = (byte)(data2);
  10047. SaveFlag[3] = (byte)(data2 >> 8);
  10048. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  10049. timer_500ms.Enabled = true;
  10050. }
  10051. else
  10052. {
  10053. timer_500ms.Enabled = true;
  10054. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10055. }
  10056. }
  10057. /// <summary>
  10058. /// 存储允许偏差
  10059. /// </summary>
  10060. /// <param name="sender"></param>
  10061. /// <param name="e"></param>
  10062. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  10063. {
  10064. if (e.KeyCode == Keys.Enter)
  10065. {
  10066. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10067. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10068. }
  10069. }
  10070. /// <summary>
  10071. /// 存储零点允许偏差
  10072. /// </summary>
  10073. /// <param name="sender"></param>
  10074. /// <param name="e"></param>
  10075. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  10076. {
  10077. if (e.KeyCode == Keys.Enter)
  10078. {
  10079. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10080. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10081. }
  10082. }
  10083. /// <summary>
  10084. /// 删除服务器配置文件
  10085. /// </summary>
  10086. /// <param name="sender"></param>
  10087. /// <param name="e"></param>
  10088. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  10089. {
  10090. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  10091. {
  10092. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  10093. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  10094. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  10095. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  10096. System.Environment.Exit(0);
  10097. }
  10098. }
  10099. /// <summary>
  10100. /// 按下Enter保存数据
  10101. /// </summary>
  10102. /// <param name="sender"></param>
  10103. /// <param name="e"></param>
  10104. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  10105. {
  10106. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  10107. if (e.KeyCode == Keys.Enter)
  10108. {
  10109. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10110. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10111. }
  10112. }
  10113. /// <summary>
  10114. /// 按下Enter保存数据
  10115. /// </summary>
  10116. /// <param name="sender"></param>
  10117. /// <param name="e"></param>
  10118. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  10119. {
  10120. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  10121. if (e.KeyCode == Keys.Enter)
  10122. {
  10123. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  10124. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  10125. }
  10126. }
  10127. private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
  10128. {
  10129. //检查本地文件
  10130. if (!File.Exists(localInfo.LocalPath + localInfo.HelpFilename))
  10131. {
  10132. if (!OfflineFlag)
  10133. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/help/" + localInfo.HelpFilename, localInfo.LocalPath);
  10134. else
  10135. {
  10136. MessageBoxTimeOut.Show("未找到帮助文件!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10137. return;
  10138. }
  10139. }
  10140. //调用本地浏览器打开帮助文件
  10141. System.Diagnostics.Process.Start("explorer", localInfo.LocalPath + localInfo.HelpFilename);
  10142. }
  10143. /// <summary>
  10144. /// 读取故障日志地址
  10145. /// </summary>
  10146. /// <param name="sender"></param>
  10147. /// <param name="e"></param>
  10148. private void button_ReadLogAddr_Click(object sender, EventArgs e)
  10149. {
  10150. textBox_LogAddrBegin.Text = "";
  10151. textBox_LogAddrEnd.Text = "";
  10152. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5200, null);
  10153. }
  10154. /// <summary>
  10155. /// 写入硬件版本
  10156. /// </summary>
  10157. /// <param name="sender"></param>
  10158. /// <param name="e"></param>
  10159. private void button_WriteHW_Click(object sender, EventArgs e)
  10160. {
  10161. string HW = textBox_HW.Text;
  10162. var HWArray = new byte[16];
  10163. for (ushort i = 0; i < HW.Length; i++)
  10164. {
  10165. HWArray[i] = (byte)HW[i];
  10166. }
  10167. if (HW.Length < 16)
  10168. {
  10169. HWArray[HW.Length] = (byte)'.';
  10170. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10171. {
  10172. HWArray[HW.Length + 1 + i] = 0x20;
  10173. }
  10174. }
  10175. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10176. }
  10177. /// <summary>
  10178. /// 生产模式写入HW
  10179. /// </summary>
  10180. /// <param name="sender"></param>
  10181. /// <param name="e"></param>
  10182. private void Button_FacModeSetHW_Click(object sender, EventArgs e)
  10183. {
  10184. string HW = textBox_FacModeHW.Text;
  10185. var HWArray = new byte[16];
  10186. for (ushort i = 0; i < HW.Length; i++)
  10187. {
  10188. HWArray[i] = (byte)HW[i];
  10189. }
  10190. if (HW.Length < 16)
  10191. {
  10192. HWArray[HW.Length] = (byte)'.';
  10193. for (ushort i = 0; i < 16 - HW.Length - 1; i++)
  10194. {
  10195. HWArray[HW.Length + 1 + i] = 0x20;
  10196. }
  10197. }
  10198. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5310, HWArray);
  10199. }
  10200. /// <summary>
  10201. /// 读取定制编号
  10202. /// </summary>
  10203. /// <param name="sender"></param>
  10204. /// <param name="e"></param>
  10205. private void button_ReadUserNum_Click(object sender, EventArgs e)
  10206. {
  10207. textBox_UserNum.Text = "---";
  10208. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5600, null);
  10209. }
  10210. /// <summary>
  10211. /// 写入定制编号
  10212. /// </summary>
  10213. /// <param name="sender"></param>
  10214. /// <param name="e"></param>
  10215. private void button_WriteUserNum_Click(object sender, EventArgs e)
  10216. {
  10217. string User = textBox_UserNum.Text;
  10218. var UserArray = new byte[32];
  10219. for (ushort i = 0; i < User.Length; i++)
  10220. {
  10221. UserArray[i] = (byte)User[i];
  10222. }
  10223. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5720, UserArray);
  10224. }
  10225. /// <summary>
  10226. /// 读取指定块拓展功能
  10227. /// </summary>
  10228. /// <param name="sender"></param>
  10229. /// <param name="e"></param>
  10230. private void button_FunSet_Read_Click(object sender, EventArgs e)
  10231. {
  10232. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10233. {
  10234. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10235. }
  10236. else
  10237. {
  10238. //清空当前内容
  10239. for (int i = 0; i < 8; i++)
  10240. for (int j = 0; j < 8; j++)
  10241. {
  10242. dataGridView_FunSet.Rows[i].Cells[j + 1].Value = "";
  10243. }
  10244. //发送读取指令
  10245. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10246. var Code = new byte[2];
  10247. Code[0] = (byte)(Num & 0xFF);
  10248. Code[1] = (byte)(Num >> 8);
  10249. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x5402, Code);
  10250. }
  10251. }
  10252. /// <summary>
  10253. /// 写入指定块或指定单元参数
  10254. /// </summary>
  10255. /// <param name="sender"></param>
  10256. /// <param name="e"></param>
  10257. private void button_FunSet_Write_Click(object sender, EventArgs e)
  10258. {
  10259. if (radioButton_WriteByBlock.Checked == true)
  10260. {
  10261. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10262. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10263. else
  10264. {
  10265. //开始按块写入
  10266. ushort Num = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10267. var Code = new byte[66];
  10268. Code[0] = (byte)(Num & 0xFF);
  10269. Code[1] = (byte)(Num >> 8);
  10270. for (int i = 0; i < 8; i++)
  10271. for (int j = 0; j < 8; j++)
  10272. {
  10273. try
  10274. {
  10275. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[i].Cells[j + 1].Value);
  10276. Code[i * 8 + j + 2] = (byte)(Data & 0xFF);
  10277. }
  10278. catch (Exception)
  10279. {
  10280. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + (i + 1).ToString() + "\r\n" + "参数:" + (j + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10281. return;
  10282. }
  10283. }
  10284. if (MessageBox.Show("请核对块编号!\r\n" + "块编号:" + (Num).ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10285. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5542, Code);
  10286. else
  10287. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10288. }
  10289. }
  10290. else if (radioButton_WriteByUnit.Checked == true)
  10291. {
  10292. if (comboBox_FunSet_BlockNum.SelectedIndex < 0)
  10293. MessageBox.Show("请选择块编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10294. else
  10295. {
  10296. if (comboBox_FunSet_UnitNum.SelectedIndex < 0)
  10297. MessageBox.Show("请选择单元编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10298. else
  10299. {
  10300. //开始按单元写入
  10301. ushort Num1 = (ushort)(comboBox_FunSet_BlockNum.SelectedIndex + 1);
  10302. ushort Num2 = (ushort)(comboBox_FunSet_UnitNum.SelectedIndex + 1);
  10303. var Code = new byte[12];
  10304. Code[0] = (byte)(Num1 & 0xFF);
  10305. Code[1] = (byte)(Num1 >> 8);
  10306. Code[2] = (byte)(Num2 & 0xFF);
  10307. Code[3] = (byte)(Num2 >> 8);
  10308. for (int i = 0; i < 8; i++)
  10309. {
  10310. try
  10311. {
  10312. byte Data = Convert.ToByte(dataGridView_FunSet.Rows[Num2 - 1].Cells[i + 1].Value);
  10313. Code[i + 4] = (byte)(Data & 0xFF);
  10314. }
  10315. catch (Exception)
  10316. {
  10317. MessageBox.Show("数据格式错误或超范围!\r\n" + "单元编号:" + Num2.ToString() + "\r\n" + "参数:" + (i + 1).ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10318. return;
  10319. }
  10320. }
  10321. if (MessageBox.Show("请核对块编号和单元编号!\r\n" + "块编号:" + Num1.ToString() + "\r\n" + "单元编号:" + Num2.ToString(), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  10322. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x550C, Code);
  10323. else
  10324. MessageBoxTimeOut.Show("取消写入", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  10325. }
  10326. }
  10327. }
  10328. else
  10329. {
  10330. MessageBox.Show("请选择写入方式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10331. }
  10332. }
  10333. /// <summary>
  10334. /// 按块写入时隐藏单元编号
  10335. /// </summary>
  10336. /// <param name="sender"></param>
  10337. /// <param name="e"></param>
  10338. private void radioButton_WriteByUnit_CheckedChanged(object sender, EventArgs e)
  10339. {
  10340. if (radioButton_WriteByUnit.Checked == true)
  10341. {
  10342. label159.Visible = true;
  10343. comboBox_FunSet_UnitNum.Visible = true;
  10344. }
  10345. else
  10346. {
  10347. label159.Visible = false;
  10348. comboBox_FunSet_UnitNum.Visible = false;
  10349. }
  10350. }
  10351. /// <summary>
  10352. /// 打开或关闭指令窗口
  10353. /// </summary>
  10354. /// <param name="sender"></param>
  10355. /// <param name="e"></param>
  10356. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  10357. {
  10358. if (指令调试ToolStripMenuItem.Checked == false)
  10359. {
  10360. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  10361. {
  10362. DebugForm.debug1 = new DebugForm();
  10363. DebugForm.debug1.Show();
  10364. this.DebugWindowIsOpen = true;
  10365. }
  10366. else
  10367. {
  10368. DebugForm.debug1.Activate();
  10369. this.DebugWindowIsOpen = true;
  10370. }
  10371. 指令调试ToolStripMenuItem.Checked = true;
  10372. }
  10373. else
  10374. {
  10375. if (this.DebugWindowIsOpen == true)
  10376. {
  10377. DebugForm.debug1.Close();
  10378. this.DebugWindowIsOpen = false;
  10379. this.DebugDataDisplayEnable = false;
  10380. }
  10381. 指令调试ToolStripMenuItem.Checked = false;
  10382. }
  10383. }
  10384. }
  10385. }