mainForm.cs 345 KB

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