mainForm.cs 385 KB

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