mainForm.cs 346 KB

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