mainForm.cs 406 KB

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