mainForm.cs 345 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603
  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 += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4017. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4018. FileInfo += "\r\n";
  4019. FileInfo += "[电机信息]\r\n";
  4020. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4021. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4022. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4023. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4024. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4025. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4026. FileInfo += "\r\n";
  4027. FileInfo += "[马达参数]\r\n";
  4028. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4029. FileInfo += "\r\n";
  4030. FileInfo += "[整车参数]\r\n";
  4031. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4032. FileInfo += "\r\n";
  4033. FileInfo += "[控制参数]\r\n";
  4034. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4035. FileInfo += "\r\n";
  4036. FileInfo += "[传感器参数]\r\n";
  4037. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4038. FileInfo += "\r\n";
  4039. FileInfo += "[助力参数]\r\n";
  4040. for(int i=0;i<15;i++)
  4041. {
  4042. FileInfo += AssistParams[i] + "\r\n";
  4043. }
  4044. FileInfo += "[调试参数]\r\n";
  4045. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4046. FileInfo += "\r\n";
  4047. FileInfo += "[历史信息]\r\n";
  4048. FileInfo += richTextBox_Record.Text + "\r\n";
  4049. FileInfo += "\r\n";
  4050. FileInfo += "[MOS内阻校准参数]\r\n";
  4051. FileInfo += textBox_MOS_K1.Text + ", ";
  4052. FileInfo += textBox_MOS_K2.Text + ", ";
  4053. FileInfo += textBox_MOS_K3.Text + ", ";
  4054. FileInfo += textBox_MOS_K4.Text + ", ";
  4055. FileInfo += textBox_MOS_K5.Text + ", ";
  4056. FileInfo += textBox_MOS_R1.Text + ", ";
  4057. FileInfo += textBox_MOS_R2.Text + ", ";
  4058. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4059. FileInfo += "\r\n";
  4060. FileInfo += "[生产信息]\r\n";
  4061. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4062. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4063. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4064. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4065. FileInfo += "\r\n";
  4066. FileInfo += "[自定义信息]\r\n";
  4067. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4068. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4069. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4070. FileInfo += "\r\n";
  4071. FileInfo += "[校验密钥]\r\n";
  4072. FileInfo += textBox_Key.Text + "\r\n";
  4073. FileInfo += "\r\n";
  4074. FileInfo += "[存储标志]\r\n";
  4075. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4076. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4077. FileInfo += "\r\n";
  4078. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4079. Delay_ms(1000);
  4080. timer_1s.Enabled = false;
  4081. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4082. timer_1s.Enabled = true;
  4083. //数据上传
  4084. if (myFtp.IsNetConnected == true)
  4085. {
  4086. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4087. //检查路径
  4088. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4089. {
  4090. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4091. }
  4092. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4093. {
  4094. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4095. }
  4096. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4097. {
  4098. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4099. }
  4100. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\" + DataNow, PD_PathName) == false)
  4101. {
  4102. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4103. }
  4104. //上传文件
  4105. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4106. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4107. if ((result1 & result2) == true)
  4108. {
  4109. timer_1s.Enabled = false;
  4110. MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4111. timer_1s.Enabled = true;
  4112. }
  4113. else
  4114. {
  4115. timer_1s.Enabled = false;
  4116. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4117. timer_1s.Enabled = true;
  4118. }
  4119. }
  4120. else
  4121. {
  4122. timer_1s.Enabled = false;
  4123. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4124. timer_1s.Enabled = true;
  4125. }
  4126. Button_FacModeSaveResult.Text = "保存数据";
  4127. return;
  4128. } while (false);
  4129. timer_1s.Enabled = false;
  4130. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4131. timer_1s.Enabled = true;
  4132. Button_FacModeSaveResult.Text = "保存数据";
  4133. }
  4134. /// <summary>
  4135. /// 工具箱页面保存
  4136. /// </summary>
  4137. /// <param name="sender"></param>
  4138. /// <param name="e"></param>
  4139. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4140. {
  4141. //保存页面
  4142. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  4143. Graphics g = Graphics.FromImage(bit);
  4144. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  4145. SaveFileDialog sf = new SaveFileDialog();
  4146. sf.Title = "页面保存";
  4147. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4148. sf.Filter = "图片|*.png";
  4149. timer_1s.Enabled = false;
  4150. if (sf.ShowDialog() == DialogResult.OK)
  4151. {
  4152. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4153. }
  4154. timer_1s.Enabled = true;
  4155. }
  4156. /// <summary>
  4157. /// 生产模式关机
  4158. /// </summary>
  4159. /// <param name="sender"></param>
  4160. /// <param name="e"></param>
  4161. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4162. {
  4163. var Code_Off = new byte[5];
  4164. var Code_Reset = new byte[5];
  4165. Code_Off[0] = (byte)'O';
  4166. Code_Off[1] = (byte)'F';
  4167. Code_Off[2] = (byte)'F';
  4168. Code_Off[3] = (byte)'.';
  4169. Code_Off[4] = (byte)'.';
  4170. Code_Reset[0] = (byte)'R';
  4171. Code_Reset[1] = (byte)'E';
  4172. Code_Reset[2] = (byte)'S';
  4173. Code_Reset[3] = (byte)'E';
  4174. Code_Reset[4] = (byte)'T';
  4175. timer_1s.Enabled = false;
  4176. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4177. {
  4178. timer_1s.Enabled = true;
  4179. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4180. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4181. PowerOffAckStatus = false;
  4182. Delay_ms(250);
  4183. int TryCnt = 3;
  4184. while ((TryCnt--) >= 0)
  4185. {
  4186. if (!PowerOffAckStatus)
  4187. {
  4188. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4189. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4190. PowerOffAckStatus = false;
  4191. Delay_ms(250);
  4192. }
  4193. else break;
  4194. }
  4195. if (PowerOffAckStatus)
  4196. {
  4197. timer_1s.Enabled = false;
  4198. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4199. timer_1s.Enabled = true;
  4200. }
  4201. else
  4202. {
  4203. timer_1s.Enabled = false;
  4204. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4205. timer_1s.Enabled = true;
  4206. }
  4207. }
  4208. timer_1s.Enabled = true;
  4209. }
  4210. //仪表电源键按下
  4211. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4212. {
  4213. var Code = new byte[2];
  4214. Code[0] = 0;
  4215. Code[1] = 0b00100000;
  4216. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4217. }
  4218. /// <summary>
  4219. /// 仪表加键按下
  4220. /// </summary>
  4221. /// <param name="sender"></param>
  4222. /// <param name="e"></param>
  4223. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4224. {
  4225. var Code = new byte[2];
  4226. Code[0] = 0;
  4227. Code[1] = 0b00010000;
  4228. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4229. }
  4230. /// <summary>
  4231. /// 仪表减键按下
  4232. /// </summary>
  4233. /// <param name="sender"></param>
  4234. /// <param name="e"></param>
  4235. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4236. {
  4237. var Code = new byte[2];
  4238. Code[0] = 0;
  4239. Code[1] = 0b00001000;
  4240. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4241. }
  4242. /// <summary>
  4243. /// 仪表Walk键按下
  4244. /// </summary>
  4245. /// <param name="sender"></param>
  4246. /// <param name="e"></param>
  4247. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4248. {
  4249. var Code = new byte[2];
  4250. Code[0] = 0;
  4251. Code[1] = 0b00000100;
  4252. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4253. }
  4254. /// <summary>
  4255. /// 仪表Light键按下
  4256. /// </summary>
  4257. /// <param name="sender"></param>
  4258. /// <param name="e"></param>
  4259. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4260. {
  4261. var Code = new byte[2];
  4262. Code[0] = 0;
  4263. Code[1] = 0b00000010;
  4264. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4265. }
  4266. /// <summary>
  4267. /// 仪表Set键按下
  4268. /// </summary>
  4269. /// <param name="sender"></param>
  4270. /// <param name="e"></param>
  4271. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4272. {
  4273. var Code = new byte[2];
  4274. Code[0] = 0;
  4275. Code[1] = 0b00000001;
  4276. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4277. }
  4278. /// <summary>
  4279. /// 导出电机故障日志
  4280. /// </summary>
  4281. /// <param name="sender"></param>
  4282. /// <param name="e"></param>
  4283. private void button_ExportLog_Click(object sender, EventArgs e)
  4284. {
  4285. var Address = new byte[4];
  4286. UInt32 Address_Begin;
  4287. UInt32 Addres_End;
  4288. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4289. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4290. richTextBox_Record.Clear();
  4291. textBox_LogAddrBegin.ReadOnly = true;
  4292. textBox_LogAddrEnd.ReadOnly = true;
  4293. if (!mySerialProcess.mySerial.IsOpen)
  4294. {
  4295. timer_1s.Enabled = false;
  4296. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4297. timer_1s.Enabled = true;
  4298. return;
  4299. }
  4300. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4301. {
  4302. timer_1s.Enabled = false;
  4303. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4304. timer_1s.Enabled = true;
  4305. return;
  4306. }
  4307. else
  4308. {
  4309. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4310. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4311. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4312. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4313. if (Addres_End <= Address_Begin)
  4314. {
  4315. timer_1s.Enabled = false;
  4316. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4317. timer_1s.Enabled = true;
  4318. return;
  4319. }
  4320. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4321. {
  4322. timer_1s.Enabled = false;
  4323. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4324. timer_1s.Enabled = true;
  4325. return;
  4326. }
  4327. else
  4328. {
  4329. UInt32 ReadCount = 0;
  4330. button_ExportLog.Text = "导出中...";
  4331. button_ExportLog.Enabled = false;
  4332. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4333. for (ushort i = 0; i < ReadCount; i++)
  4334. {
  4335. var SendByte = new byte[8];
  4336. UInt32 Address_Temp_Begin;
  4337. UInt32 Address_Temp_End;
  4338. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4339. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4340. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4341. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4342. SendByte[3] = (byte)(Address_Temp_Begin);
  4343. Address_Temp_End = Address_Temp_Begin + 127;
  4344. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4345. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4346. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4347. SendByte[7] = (byte)(Address_Temp_End);
  4348. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4349. Delay_ms(200);//Thread.Sleep(200);
  4350. }
  4351. button_ExportLog.Text = "导出日志";
  4352. button_ExportLog.Enabled = true;
  4353. }
  4354. }
  4355. }
  4356. /// <summary>
  4357. /// 保存日志信息
  4358. /// </summary>
  4359. /// <param name="sender"></param>
  4360. /// <param name="e"></param>
  4361. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4362. {
  4363. string SaveInfo = "";
  4364. if (richTextBox_Record.Text == string.Empty)
  4365. {
  4366. timer_1s.Enabled = false;
  4367. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4368. timer_1s.Enabled = true;
  4369. return;
  4370. }
  4371. //获取保存信息
  4372. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4373. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4374. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4375. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4376. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4377. SaveInfo += "\r\n";
  4378. SaveInfo += richTextBox_Record.Text;
  4379. //设置保存路径和文件名
  4380. SaveFileDialog sf = new SaveFileDialog();
  4381. sf.Title = "数据保存";
  4382. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4383. sf.FileName.Replace(" ", "");
  4384. sf.Filter = "日志|*.ttlog";
  4385. if (sf.ShowDialog() == DialogResult.OK)
  4386. {
  4387. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4388. }
  4389. }
  4390. /// <summary>
  4391. /// 双击修改日志起始地址
  4392. /// </summary>
  4393. /// <param name="sender"></param>
  4394. /// <param name="e"></param>
  4395. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4396. {
  4397. textBox_LogAddrBegin.ReadOnly = false;
  4398. }
  4399. /// <summary>
  4400. /// 双击修改日志结束地址
  4401. /// </summary>
  4402. /// <param name="sender"></param>
  4403. /// <param name="e"></param>
  4404. private void label88_DoubleClick(object sender, EventArgs e)
  4405. {
  4406. textBox_LogAddrEnd.ReadOnly = false;
  4407. }
  4408. /// <summary>
  4409. /// 存储器自动读取选择
  4410. /// </summary>
  4411. /// <param name="sender"></param>
  4412. /// <param name="e"></param>
  4413. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4414. {
  4415. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4416. {
  4417. //检查串口是否打开
  4418. if (!mySerialProcess.mySerial.IsOpen)
  4419. {
  4420. timer_1s.Enabled = false;
  4421. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4422. timer_1s.Enabled = true;
  4423. checkBox_ReadRanFlash_AutoSW.Checked = false;
  4424. return;
  4425. }
  4426. }
  4427. }
  4428. /// <summary>
  4429. /// 系统开机按钮
  4430. /// </summary>
  4431. /// <param name="sender"></param>
  4432. /// <param name="e"></param>
  4433. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4434. {
  4435. byte[] Data = new byte[1];
  4436. Data[0] = 0xF1;
  4437. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4438. }
  4439. /// <summary>
  4440. /// 系统关机按钮
  4441. /// </summary>
  4442. /// <param name="sender"></param>
  4443. /// <param name="e"></param>
  4444. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4445. {
  4446. byte[] Data = new byte[1];
  4447. Data[0] = 0xF0;
  4448. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4449. }
  4450. /// <summary>
  4451. /// 连接开机选择
  4452. /// </summary>
  4453. /// <param name="sender"></param>
  4454. /// <param name="e"></param>
  4455. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4456. {
  4457. //输入用户名
  4458. EnterForm1.ShowDialog();
  4459. try
  4460. {
  4461. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4462. {
  4463. if (EnterForm1.comboBox_User.Text == "管理员")
  4464. {
  4465. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  4466. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4467. }
  4468. else
  4469. {
  4470. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4471. }
  4472. }
  4473. else
  4474. {
  4475. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4476. }
  4477. }
  4478. catch (Exception)
  4479. {
  4480. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4481. }
  4482. }
  4483. /// <summary>
  4484. /// 断开关机选择
  4485. /// </summary>
  4486. /// <param name="sender"></param>
  4487. /// <param name="e"></param>
  4488. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4489. {
  4490. //输入用户名
  4491. EnterForm1.ShowDialog();
  4492. try
  4493. {
  4494. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4495. {
  4496. if (EnterForm1.comboBox_User.Text == "管理员")
  4497. {
  4498. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  4499. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4500. }
  4501. else
  4502. {
  4503. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4504. }
  4505. }
  4506. else
  4507. {
  4508. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4509. }
  4510. }
  4511. catch (Exception)
  4512. {
  4513. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4514. }
  4515. }
  4516. /// <summary>
  4517. /// 识别通讯盒选择
  4518. /// </summary>
  4519. /// <param name="sender"></param>
  4520. /// <param name="e"></param>
  4521. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  4522. {
  4523. //输入用户名
  4524. EnterForm1.ShowDialog();
  4525. try
  4526. {
  4527. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4528. {
  4529. if (EnterForm1.comboBox_User.Text == "管理员")
  4530. {
  4531. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  4532. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4533. }
  4534. else
  4535. {
  4536. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4537. }
  4538. }
  4539. else
  4540. {
  4541. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4542. }
  4543. }
  4544. catch (Exception)
  4545. {
  4546. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4547. }
  4548. }
  4549. /// <summary>
  4550. /// 将配置信息导出为cfg文件
  4551. /// </summary>
  4552. private void ConfigFileSave(bool DeleteFlag, string FileName)
  4553. {
  4554. if (DeleteFlag)
  4555. {
  4556. if (File.Exists(FileName))
  4557. File.Delete(FileName);
  4558. }
  4559. string CfgFileInfo = "";
  4560. CfgFileInfo += "[PortSet]" + "\r\n";
  4561. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  4562. CfgFileInfo += "PortBaudrate:" + toolStripComboBox_Baudrate.Text + "\r\n";
  4563. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4564. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4565. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  4566. CfgFileInfo += "\r\n";
  4567. CfgFileInfo += "[Option]" + "\r\n";
  4568. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  4569. CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
  4570. CfgFileInfo += "\r\n";
  4571. CfgFileInfo += "[ServerSet]" + "\r\n";
  4572. CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
  4573. CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
  4574. CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
  4575. CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
  4576. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  4577. CfgFileInfo += "\r\n";
  4578. CfgFileInfo += "[MacInfo]" + "\r\n";
  4579. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  4580. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  4581. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  4582. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  4583. CfgFileInfo += "\r\n";
  4584. CfgFileInfo += "[LogAddress]" + "\r\n";
  4585. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  4586. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  4587. CfgFileInfo += "\r\n";
  4588. CfgFileInfo += "[MotorType]" + "\r\n";
  4589. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4590. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4591. CfgFileInfo += "\r\n";
  4592. CfgFileInfo += "[CheckValue]" + "\r\n";
  4593. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  4594. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  4595. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  4596. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  4597. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  4598. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  4599. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  4600. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  4601. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  4602. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  4603. }
  4604. /// <summary>
  4605. /// 配置状态更新,点击时保存
  4606. /// </summary>
  4607. private void ConfigFileSave_Click(object sender, EventArgs e)
  4608. {
  4609. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4610. }
  4611. /// <summary>
  4612. /// 文本框修改结束,回车保存
  4613. /// </summary>
  4614. /// <param name="sender"></param>
  4615. /// <param name="e"></param>
  4616. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  4617. {
  4618. if (e.KeyCode == Keys.Enter)
  4619. {
  4620. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4621. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4622. }
  4623. }
  4624. /// <summary>
  4625. /// 允许离线使用
  4626. /// </summary>
  4627. /// <param name="sender"></param>
  4628. /// <param name="e"></param>
  4629. private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
  4630. {
  4631. //输入用户名
  4632. EnterForm1.ShowDialog();
  4633. try
  4634. {
  4635. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4636. {
  4637. if (EnterForm1.comboBox_User.Text == "管理员")
  4638. {
  4639. 允许ToolStripMenuItem.Checked = true;
  4640. 不允许ToolStripMenuItem.Checked = false;
  4641. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4642. }
  4643. else
  4644. {
  4645. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4646. 允许ToolStripMenuItem.Checked = false;
  4647. 不允许ToolStripMenuItem.Checked = true;
  4648. }
  4649. }
  4650. else
  4651. {
  4652. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4653. 允许ToolStripMenuItem.Checked = false;
  4654. 不允许ToolStripMenuItem.Checked = true;
  4655. }
  4656. }
  4657. catch (Exception)
  4658. {
  4659. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4660. 允许ToolStripMenuItem.Checked = false;
  4661. 不允许ToolStripMenuItem.Checked = true;
  4662. }
  4663. }
  4664. /// <summary>
  4665. /// 不允许离线使用
  4666. /// </summary>
  4667. /// <param name="sender"></param>
  4668. /// <param name="e"></param>
  4669. private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
  4670. {
  4671. 允许ToolStripMenuItem.Checked = false;
  4672. 不允许ToolStripMenuItem.Checked = true;
  4673. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4674. }
  4675. /// <summary>
  4676. /// 弹出扫码按钮
  4677. /// </summary>
  4678. /// <param name="sender"></param>
  4679. /// <param name="e"></param>
  4680. private void button_ScanCode_Click(object sender, EventArgs e)
  4681. {
  4682. Scan scan_form = new Scan();
  4683. scan_form.ShowDialog();
  4684. do
  4685. {
  4686. if (scan_form.textBox_Scan.Text == string.Empty)
  4687. {
  4688. timer_1s.Enabled = false;
  4689. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4690. timer_1s.Enabled = true;
  4691. break;
  4692. }
  4693. string ScanInfo = scan_form.textBox_Scan.Text.Replace(" ", "");
  4694. string regexInfo = "";
  4695. string[] InfoList = { "" };
  4696. try
  4697. {
  4698. if (中置电机ToolStripMenuItem.Checked == true)
  4699. {
  4700. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  4701. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  4702. }
  4703. else if (轮毂电机ToolStripMenuItem.Checked == true)
  4704. {
  4705. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  4706. string Model = InfoList[0];
  4707. string Spec = InfoList[1];
  4708. string Sn = InfoList[2];
  4709. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  4710. InfoList[1] = Sn;
  4711. }
  4712. }
  4713. catch (Exception)
  4714. {
  4715. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4716. return;
  4717. }
  4718. if (InfoList.Length >= 2)
  4719. {
  4720. //写入型号
  4721. textBox_FacModeName.Text = InfoList[0];
  4722. string Mode = textBox_FacModeName.Text;
  4723. var ModeArray = new byte[16];
  4724. for (ushort i = 0; i < Mode.Length; i++)
  4725. {
  4726. ModeArray[i] = (byte)Mode[i];
  4727. }
  4728. if (Mode.Length < 16)
  4729. {
  4730. ModeArray[Mode.Length] = (byte)'.';
  4731. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4732. {
  4733. ModeArray[Mode.Length + 1 + i] = 0x20;
  4734. }
  4735. }
  4736. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4737. //写入SN
  4738. textBox_FacModeNum.Text = InfoList[1];
  4739. string SN = textBox_FacModeNum.Text;
  4740. var SNArray = new byte[16];
  4741. for (ushort i = 0; i < SN.Length; i++)
  4742. {
  4743. SNArray[i] = (byte)SN[i];
  4744. }
  4745. if (SN.Length < 16)
  4746. {
  4747. SNArray[SN.Length] = (byte)'.';
  4748. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4749. {
  4750. SNArray[SN.Length + 1 + i] = 0x20;
  4751. }
  4752. }
  4753. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4754. }
  4755. else
  4756. {
  4757. timer_1s.Enabled = false;
  4758. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4759. timer_1s.Enabled = true;
  4760. break;
  4761. }
  4762. } while (false);
  4763. scan_form.Dispose();
  4764. }
  4765. private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
  4766. {
  4767. //输入用户名
  4768. EnterForm1.ShowDialog();
  4769. try
  4770. {
  4771. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4772. {
  4773. if (EnterForm1.comboBox_User.Text == "管理员")
  4774. {
  4775. IP地址ToolStripMenuItem.Visible = true;
  4776. 端口ToolStripMenuItem.Visible = true;
  4777. 用户名ToolStripMenuItem.Visible = true;
  4778. 密码ToolStripMenuItem.Visible = true;
  4779. 存储路径ToolStripMenuItem.Visible = true;
  4780. }
  4781. else
  4782. {
  4783. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4784. IP地址ToolStripMenuItem.Visible = false;
  4785. 端口ToolStripMenuItem.Visible = false;
  4786. 用户名ToolStripMenuItem.Visible = false;
  4787. 密码ToolStripMenuItem.Visible = false;
  4788. 存储路径ToolStripMenuItem.Visible = false;
  4789. }
  4790. }
  4791. else
  4792. {
  4793. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4794. IP地址ToolStripMenuItem.Visible = false;
  4795. 端口ToolStripMenuItem.Visible = false;
  4796. 用户名ToolStripMenuItem.Visible = false;
  4797. 密码ToolStripMenuItem.Visible = false;
  4798. 存储路径ToolStripMenuItem.Visible = false;
  4799. }
  4800. }
  4801. catch (Exception)
  4802. {
  4803. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4804. IP地址ToolStripMenuItem.Visible = false;
  4805. 端口ToolStripMenuItem.Visible = false;
  4806. 用户名ToolStripMenuItem.Visible = false;
  4807. 密码ToolStripMenuItem.Visible = false;
  4808. 存储路径ToolStripMenuItem.Visible = false;
  4809. }
  4810. }
  4811. private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
  4812. {
  4813. //输入用户名
  4814. EnterForm1.ShowDialog();
  4815. try
  4816. {
  4817. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4818. {
  4819. if (EnterForm1.comboBox_User.Text == "管理员")
  4820. {
  4821. 生产商ToolStripMenuItem.Visible = true;
  4822. 生产地ToolStripMenuItem.Visible = true;
  4823. 生产日期ToolStripMenuItem.Visible = true;
  4824. 产品标识ToolStripMenuItem.Visible = true;
  4825. }
  4826. else
  4827. {
  4828. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4829. 生产商ToolStripMenuItem.Visible = false;
  4830. 生产地ToolStripMenuItem.Visible = false;
  4831. 生产日期ToolStripMenuItem.Visible = false;
  4832. 产品标识ToolStripMenuItem.Visible = false;
  4833. }
  4834. }
  4835. else
  4836. {
  4837. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4838. 生产商ToolStripMenuItem.Visible = false;
  4839. 生产地ToolStripMenuItem.Visible = false;
  4840. 生产日期ToolStripMenuItem.Visible = false;
  4841. 产品标识ToolStripMenuItem.Visible = false;
  4842. }
  4843. }
  4844. catch (Exception)
  4845. {
  4846. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4847. 生产商ToolStripMenuItem.Visible = false;
  4848. 生产地ToolStripMenuItem.Visible = false;
  4849. 生产日期ToolStripMenuItem.Visible = false;
  4850. 产品标识ToolStripMenuItem.Visible = false;
  4851. }
  4852. }
  4853. /// <summary>
  4854. /// 切换电机类型
  4855. /// </summary>
  4856. /// <param name="sender"></param>
  4857. /// <param name="e"></param>
  4858. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  4859. {
  4860. 中置电机ToolStripMenuItem.Checked = true;
  4861. 轮毂电机ToolStripMenuItem.Checked = false;
  4862. toolStripTextBox_MACPD.Text = "MM_MC1";
  4863. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  4864. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4865. }
  4866. /// <summary>
  4867. /// 切换电机类型
  4868. /// </summary>
  4869. /// <param name="sender"></param>
  4870. /// <param name="e"></param>
  4871. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  4872. {
  4873. 中置电机ToolStripMenuItem.Checked = false;
  4874. 轮毂电机ToolStripMenuItem.Checked = true;
  4875. toolStripTextBox_MACPD.Text = "GF_250_1";
  4876. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  4877. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4878. }
  4879. /// <summary>
  4880. /// 获取配置文件日期
  4881. /// </summary>
  4882. /// <param name="DisAll"></param>
  4883. private void GetDateList(bool DisAll)
  4884. {
  4885. string[] DateList = { "" };
  4886. //从服务器更新日期列表
  4887. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  4888. {
  4889. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  4890. }
  4891. //从本地更新日期列表
  4892. else
  4893. {
  4894. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  4895. }
  4896. comboBox_FacModeCfgDate.Items.Clear();
  4897. comboBox_CheckModeCfgDate.Items.Clear();
  4898. //日期列表加载
  4899. if (DisAll == true)
  4900. {
  4901. comboBox_FacModeCfgDate.Items.Add("显示近期");
  4902. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  4903. comboBox_FacModeCfgDate.Items.Add("---");
  4904. comboBox_CheckModeCfgDate.Items.Add("---");
  4905. foreach (var file in DateList)
  4906. {
  4907. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  4908. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  4909. }
  4910. }
  4911. else
  4912. {
  4913. if (DateList.Length > 10)
  4914. {
  4915. comboBox_FacModeCfgDate.Items.Add("显示全部");
  4916. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  4917. comboBox_FacModeCfgDate.Items.Add("---");
  4918. comboBox_CheckModeCfgDate.Items.Add("---");
  4919. }
  4920. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  4921. {
  4922. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  4923. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  4924. }
  4925. }
  4926. }
  4927. /// <summary>
  4928. /// 获取配置文件列表
  4929. /// </summary>
  4930. /// <param name="date"></param>
  4931. private void GetFileListFrom(string date)
  4932. {
  4933. string[] FileList = { "" };
  4934. //从服务器更新文件列表
  4935. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  4936. {
  4937. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  4938. }
  4939. else
  4940. {
  4941. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  4942. }
  4943. comboBox_CheckModeCfgFile.Items.Clear();
  4944. comboBox_FacModeCfgFile.Items.Clear();
  4945. foreach (var file in FileList)
  4946. {
  4947. if (file.Contains(".ttcfg"))
  4948. {
  4949. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  4950. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  4951. }
  4952. }
  4953. }
  4954. /// <summary>
  4955. /// 检验模式选择文件日期
  4956. /// </summary>
  4957. /// <param name="sender"></param>
  4958. /// <param name="e"></param>
  4959. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  4960. {
  4961. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  4962. {
  4963. GetDateList(true);
  4964. }
  4965. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  4966. {
  4967. GetDateList(false);
  4968. }
  4969. else
  4970. {
  4971. comboBox_CheckModeCfgFile.Text = "";
  4972. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  4973. }
  4974. }
  4975. /// <summary>
  4976. /// 配置模式选择文件日期
  4977. /// </summary>
  4978. /// <param name="sender"></param>
  4979. /// <param name="e"></param>
  4980. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  4981. {
  4982. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  4983. {
  4984. GetDateList(true);
  4985. }
  4986. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  4987. {
  4988. GetDateList(false);
  4989. }
  4990. else
  4991. {
  4992. comboBox_FacModeCfgFile.Text = "";
  4993. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  4994. }
  4995. }
  4996. /// <summary>
  4997. /// 选中量产模式
  4998. /// </summary>
  4999. /// <param name="sender"></param>
  5000. /// <param name="e"></param>
  5001. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5002. {
  5003. //更新生产配置文件目录
  5004. GetDateList(false);
  5005. }
  5006. /// <summary>
  5007. /// 量产测试结束
  5008. /// </summary>
  5009. /// <param name=""></param>
  5010. private void FacMode_Stop(bool OK_Flag)
  5011. {
  5012. //打开开始按钮
  5013. button__FacMode_Start.Enabled = true;
  5014. //系统关机
  5015. var Code = new byte[32];//发送的指令数据
  5016. Code[0] = 0xF0;
  5017. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5018. //关闭串口
  5019. mySerialProcess.SerialClose(false);
  5020. //路径设置
  5021. string LocalSavePath = "";
  5022. string ServerSavePath = "";
  5023. if (OK_Flag)
  5024. {
  5025. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5026. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5027. }
  5028. else
  5029. {
  5030. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5031. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5032. }
  5033. if (Directory.Exists(LocalSavePath) == false)
  5034. {
  5035. Directory.CreateDirectory(LocalSavePath);
  5036. }
  5037. //保存和上传
  5038. string LogSavePath = "";
  5039. string LogSaveFileName = "";
  5040. string ProductInfo = textBox_FacModeScan.Text;
  5041. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5042. if (Directory.Exists(LogSavePath) == false)
  5043. {
  5044. Directory.CreateDirectory(LogSavePath);
  5045. }
  5046. //测试页面
  5047. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  5048. Graphics g = Graphics.FromImage(bit);
  5049. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  5050. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5051. bit.Save(LogSaveFileName);
  5052. //上传测试页面到服务器
  5053. if (myFtp.IsNetConnected == true)
  5054. {
  5055. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5056. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5057. {
  5058. myFtp.MakeDir(ServerSavePath + DateNow);
  5059. }
  5060. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5061. {
  5062. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5063. }
  5064. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5065. if (result == true)
  5066. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5067. }
  5068. else
  5069. {
  5070. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5071. }
  5072. //测试记录
  5073. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5074. string file_str = "";
  5075. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5076. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5077. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5078. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5079. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5080. //上传测试记录到服务器
  5081. if (myFtp.IsNetConnected == true)
  5082. {
  5083. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5084. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5085. {
  5086. myFtp.MakeDir(ServerSavePath + DateNow);
  5087. }
  5088. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5089. {
  5090. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5091. }
  5092. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5093. if (result == true)
  5094. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5095. }
  5096. else
  5097. {
  5098. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5099. }
  5100. }
  5101. /// <summary>
  5102. /// 量产测试开始
  5103. /// </summary>
  5104. /// <param name="sender"></param>
  5105. /// <param name="e"></param>
  5106. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5107. {
  5108. //关闭测试项目编辑
  5109. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5110. foreach (Control c in groupBox2.Controls)
  5111. {
  5112. if (c is CheckBox)
  5113. c.Enabled = false;
  5114. }
  5115. WriteLockStatus = true;
  5116. //检查配置文件
  5117. if (comboBox_FacModeCfgFile.Text == "")
  5118. {
  5119. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5120. return;
  5121. }
  5122. //开始测试
  5123. TestStart();
  5124. }
  5125. /// <summary>
  5126. /// 测试子函数
  5127. /// </summary>
  5128. private void TestStart()
  5129. {
  5130. //初始化标签
  5131. FacModelLabelInit();
  5132. richTextBox_FacModeLog.Clear();
  5133. //按钮禁止操作
  5134. button__FacMode_Start.Enabled = false;
  5135. //记录配置文件
  5136. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5137. //检查打标信息格式
  5138. label_FacModeStatus.Text = "检查扫码信息";
  5139. Delay_ms(500);
  5140. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5141. if (textBox_FacModeScan.Text == string.Empty)
  5142. {
  5143. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5144. return;
  5145. }
  5146. try
  5147. {
  5148. if (中置电机ToolStripMenuItem.Checked == true)
  5149. {
  5150. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5151. {
  5152. label_FacModeStatus.Text = "存在故障!";
  5153. label_FacModeResult.BackColor = Color.Red;
  5154. label_FacModeResult.Text = "标签格式错误";
  5155. button__FacMode_Start.Enabled = true;
  5156. return;
  5157. }
  5158. }
  5159. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5160. {
  5161. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5162. {
  5163. label_FacModeStatus.Text = "存在故障!";
  5164. label_FacModeResult.BackColor = Color.Red;
  5165. label_FacModeResult.Text = "标签格式错误";
  5166. button__FacMode_Start.Enabled = true;
  5167. return;
  5168. }
  5169. }
  5170. }
  5171. catch (System.Exception)
  5172. {
  5173. label_FacModeStatus.Text = "存在故障!";
  5174. label_FacModeResult.BackColor = Color.Red;
  5175. label_FacModeResult.Text = "标签格式错误";
  5176. button__FacMode_Start.Enabled = true;
  5177. return;
  5178. }
  5179. //打开串口
  5180. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5181. if (!mySerialProcess.mySerial.IsOpen)
  5182. {
  5183. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5184. return;
  5185. }
  5186. //流水号计数
  5187. //...
  5188. //创建线程,执行测试任务
  5189. Thread th = new Thread(FacModeTest_Task);
  5190. th.Start();
  5191. }
  5192. /// <summary>
  5193. /// 执行一次测试任务
  5194. /// </summary>
  5195. private void FacModeTest_Task()
  5196. {
  5197. //开始测试
  5198. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5199. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5200. //变量定义
  5201. var Code = new byte[255];//发送的指令数据
  5202. label_FacModeStatus.Text = "开始测试";
  5203. Delay_ms(500);
  5204. label_FacModeStatus.Text = "系统开机";
  5205. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  5206. BootInfo = "";
  5207. Code[0] = 0xF0;
  5208. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5209. Delay_ms(1500);
  5210. Code[0] = 0xF1;
  5211. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5212. ACK_WaitCnt = 0;
  5213. while (ACK_WaitCnt <= 2); //1s
  5214. //检查BOOT版本
  5215. if (BootInfo != string.Empty)
  5216. {
  5217. label_FacModeBootVer.BackColor = Color.Green;
  5218. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5219. Delay_ms(500);
  5220. }
  5221. else
  5222. {
  5223. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5224. label_FacModeStatus.Text = "存在故障!";
  5225. label_FacModeResult.BackColor = Color.Red;
  5226. label_FacModeResult.Text = "测试异常";
  5227. Delay_ms(500);
  5228. //存储异常并上传
  5229. FacMode_Stop(false);
  5230. return;
  5231. }
  5232. //系统清除
  5233. if (checkBox_FacModeSysClear.Checked)
  5234. {
  5235. do
  5236. {
  5237. //发送系统清除指令
  5238. label_FacModeStatus.Text = "系统清除";
  5239. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5240. Code[0] = (byte)'C';
  5241. Code[1] = (byte)'L';
  5242. Code[2] = (byte)'E';
  5243. Code[3] = (byte)'A';
  5244. Code[4] = (byte)'R';
  5245. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5246. WriteACK = false;
  5247. WriteCnt = 0;
  5248. ACK_WaitCnt = 0;
  5249. while (ACK_WaitCnt <= 6); //3s
  5250. //等待系统清除完成指令
  5251. if (WriteACK == true)
  5252. {
  5253. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5254. label_FacModeSysClear.BackColor = Color.Green;
  5255. }
  5256. else
  5257. {
  5258. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5259. label_FacModeStatus.Text = "存在故障!";
  5260. label_FacModeResult.BackColor = Color.Red;
  5261. label_FacModeResult.Text = "测试异常";
  5262. Delay_ms(500);
  5263. //存储异常并上传
  5264. FacMode_Stop(false);
  5265. return;
  5266. }
  5267. //系统重新开机
  5268. label_FacModeStatus.Text = "重新开机";
  5269. BootInfo = "";
  5270. Code[0] = 0xF1;
  5271. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5272. ACK_WaitCnt = 0;
  5273. while (ACK_WaitCnt <= 4); //2s
  5274. //获取Boot版本信息
  5275. if (BootInfo != string.Empty)
  5276. {
  5277. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5278. }
  5279. else
  5280. {
  5281. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5282. label_FacModeStatus.Text = "存在故障!";
  5283. label_FacModeResult.BackColor = Color.Red;
  5284. label_FacModeResult.Text = "测试异常";
  5285. Delay_ms(500);
  5286. //存储异常并上传
  5287. FacMode_Stop(false);
  5288. return;
  5289. }
  5290. } while (false);
  5291. }
  5292. else
  5293. {
  5294. label_FacModeSysClear.BackColor = Color.Yellow;
  5295. label_FacModeStatus.Text = "跳过系统清除!";
  5296. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5297. Delay_ms(500);
  5298. }
  5299. //检查是否有故障
  5300. if (textBox_ErrorCode.Text.Contains("H"))
  5301. {
  5302. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5303. label_FacModeStatus.Text = "电机存在故障!";
  5304. label_FacModeResult.BackColor = Color.Red;
  5305. label_FacModeResult.Text = "测试异常";
  5306. Delay_ms(500);
  5307. //存储异常并上传
  5308. FacMode_Stop(false);
  5309. return;
  5310. }
  5311. //参数写入
  5312. if (checkBox_FacModeCfgWrite.Checked)
  5313. {
  5314. label_FacModeStatus.Text = "参数写入";
  5315. //写入产品型号和SN
  5316. do
  5317. {
  5318. //根据扫码信息获取型号和SN
  5319. string ScanInfo = textBox_FacModeScan.Text;
  5320. string regexInfo = "";
  5321. string[] InfoList = { "" };
  5322. try
  5323. {
  5324. if (中置电机ToolStripMenuItem.Checked == true)
  5325. {
  5326. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5327. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  5328. }
  5329. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5330. {
  5331. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5332. string Model = InfoList[0];
  5333. string Spec = InfoList[1];
  5334. string Sn = InfoList[2];
  5335. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5336. InfoList[1] = Sn;
  5337. }
  5338. }
  5339. catch
  5340. {
  5341. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  5342. label_FacModeStatus.Text = "存在故障!";
  5343. label_FacModeResult.BackColor = Color.Red;
  5344. label_FacModeResult.Text = "标签格式错误";
  5345. Delay_ms(500);
  5346. //存储异常并上传
  5347. FacMode_Stop(false);
  5348. return;
  5349. }
  5350. if (InfoList.Length >= 2)
  5351. {
  5352. //检查配置文件是否与打标信息一致
  5353. //...
  5354. //写入型号
  5355. label_FacModeStatus.Text = "写入型号";
  5356. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  5357. textBox_FacModeName.Text = InfoList[0];
  5358. string Mode = textBox_FacModeName.Text;
  5359. var ModeArray = new byte[16];
  5360. for (ushort i = 0; i < Mode.Length; i++)
  5361. {
  5362. ModeArray[i] = (byte)Mode[i];
  5363. }
  5364. if (Mode.Length < 16)
  5365. {
  5366. ModeArray[Mode.Length] = (byte)'.';
  5367. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5368. {
  5369. ModeArray[Mode.Length + 1 + i] = 0x20;
  5370. }
  5371. }
  5372. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5373. WriteACK = false;
  5374. WriteCnt = 0;
  5375. ACK_WaitCnt = 0;
  5376. while (ACK_WaitCnt <= 2); //1s
  5377. if (WriteACK == true)
  5378. {
  5379. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  5380. }
  5381. else
  5382. {
  5383. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  5384. label_FacModeStatus.Text = "存在故障!";
  5385. label_FacModeResult.BackColor = Color.Red;
  5386. label_FacModeResult.Text = "测试异常";
  5387. Delay_ms(500);
  5388. //存储异常并上传
  5389. FacMode_Stop(false);
  5390. return;
  5391. }
  5392. //写入SN
  5393. label_FacModeStatus.Text = "写入SN";
  5394. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  5395. textBox_FacModeNum.Text = InfoList[1];
  5396. string SN = textBox_FacModeNum.Text;
  5397. var SNArray = new byte[16];
  5398. for (ushort i = 0; i < SN.Length; i++)
  5399. {
  5400. SNArray[i] = (byte)SN[i];
  5401. }
  5402. if (SN.Length < 16)
  5403. {
  5404. SNArray[SN.Length] = (byte)'.';
  5405. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5406. {
  5407. SNArray[SN.Length + 1 + i] = 0x20;
  5408. }
  5409. }
  5410. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5411. WriteACK = false;
  5412. WriteCnt = 0;
  5413. ACK_WaitCnt = 0;
  5414. while (ACK_WaitCnt <= 2); //1s
  5415. if (WriteACK == true)
  5416. {
  5417. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  5418. }
  5419. else
  5420. {
  5421. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  5422. label_FacModeStatus.Text = "存在故障!";
  5423. label_FacModeResult.BackColor = Color.Red;
  5424. label_FacModeResult.Text = "测试异常";
  5425. Delay_ms(500);
  5426. //存储异常并上传
  5427. FacMode_Stop(false);
  5428. return;
  5429. }
  5430. }
  5431. else
  5432. {
  5433. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5434. return;
  5435. }
  5436. } while (false);
  5437. //写入配置文件
  5438. do
  5439. {
  5440. label_FacModeStatus.Text = "写入配置文件";
  5441. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  5442. //配置文件
  5443. List<byte[]> CmdList = new List<byte[]>();
  5444. //从服务器下载文件
  5445. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5446. {
  5447. string SelectFile = "";
  5448. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  5449. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  5450. {
  5451. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  5452. }
  5453. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  5454. //打开文件
  5455. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  5456. CmdList.Clear();
  5457. while (streamReader.Peek() != -1)
  5458. {
  5459. string fileLineInfo = streamReader.ReadLine();
  5460. if (fileLineInfo.IndexOf("[") != -1)
  5461. {
  5462. continue;
  5463. }
  5464. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  5465. }
  5466. streamReader.Close();
  5467. }
  5468. //加载本地文件
  5469. else
  5470. {
  5471. string SelectFile = "";
  5472. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  5473. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  5474. CmdList.Clear();
  5475. while (streamReader.Peek() != -1)
  5476. {
  5477. string fileLineInfo = streamReader.ReadLine();
  5478. if (fileLineInfo.IndexOf("[") != -1)
  5479. {
  5480. continue;
  5481. }
  5482. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  5483. }
  5484. streamReader.Close();
  5485. }
  5486. int CmdNum = CmdList.Count(); //指令个数
  5487. Delay_ms(500);
  5488. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  5489. Delay_ms(500);
  5490. //开始写入
  5491. WriteCnt = 0;
  5492. for (int i = 0; i < CmdList.Count; i++)
  5493. {
  5494. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  5495. Thread.Sleep(200);
  5496. }
  5497. //判断写入是否完整
  5498. if (CmdNum == WriteCnt)
  5499. {
  5500. label_FacMode_CfgWrite.BackColor = Color.Green;
  5501. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  5502. Delay_ms(500);
  5503. }
  5504. else
  5505. {
  5506. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败" + "\r\n");
  5507. label_FacModeStatus.Text = "存在故障!";
  5508. label_FacModeResult.BackColor = Color.Red;
  5509. label_FacModeResult.Text = "测试异常";
  5510. Delay_ms(500);
  5511. //存储异常并上传
  5512. FacMode_Stop(false);
  5513. return;
  5514. }
  5515. } while (false);
  5516. }
  5517. else
  5518. {
  5519. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  5520. label_FacModeStatus.Text = "跳过参数写入!";
  5521. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  5522. Delay_ms(500);
  5523. }
  5524. //BMS通讯
  5525. if (checkBox_FacModeBMS.Checked)
  5526. {
  5527. if (label_FacModeBMS.BackColor == Color.Red)
  5528. {
  5529. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  5530. label_FacModeStatus.Text = "存在故障!";
  5531. label_FacModeResult.BackColor = Color.Red;
  5532. label_FacModeResult.Text = "测试异常";
  5533. Delay_ms(500);
  5534. //存储异常并上传
  5535. FacMode_Stop(false);
  5536. return;
  5537. }
  5538. }
  5539. else
  5540. {
  5541. label_FacModeBMS.BackColor = Color.Yellow;
  5542. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  5543. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  5544. Delay_ms(500);
  5545. }
  5546. //基础功能检测
  5547. if (checkBox_FacBaseFucTest.Checked)
  5548. {
  5549. label_FacModeStatus.Text = "基础功能检测";
  5550. //发送指令进入配置模式
  5551. do
  5552. {
  5553. Code[0] = 0x01;
  5554. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5555. WriteACK = false;
  5556. WriteCnt = 0;
  5557. ACK_WaitCnt = 0;
  5558. while (ACK_WaitCnt <= 2); //1s
  5559. if (textBox_RunInfo_Vol.Text != "---")
  5560. {
  5561. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5562. }
  5563. else
  5564. {
  5565. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  5566. label_FacModeStatus.Text = "存在故障!";
  5567. label_FacModeResult.BackColor = Color.Red;
  5568. label_FacModeResult.Text = "测试异常";
  5569. Delay_ms(500);
  5570. //存储异常并上传
  5571. FacMode_Stop(false);
  5572. return;
  5573. }
  5574. } while (false);
  5575. //发送指令启动电机
  5576. do
  5577. {
  5578. //发送指令读取调试信息
  5579. richTextBox_DebugParam.Clear();
  5580. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  5581. WriteACK = false;
  5582. WriteCnt = 0;
  5583. ACK_WaitCnt = 0;
  5584. while (ACK_WaitCnt <= 2); //1s
  5585. //获取调试信息
  5586. string DebugDefaultInfo = "";
  5587. if (richTextBox_DebugParam.Text == string.Empty)
  5588. {
  5589. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  5590. label_FacModeStatus.Text = "存在故障!";
  5591. label_FacModeResult.BackColor = Color.Red;
  5592. label_FacModeResult.Text = "测试异常";
  5593. Delay_ms(500);
  5594. //存储异常并上传
  5595. FacMode_Stop(false);
  5596. return;
  5597. }
  5598. else
  5599. {
  5600. DebugDefaultInfo = richTextBox_DebugParam.Text;
  5601. }
  5602. //设置模式
  5603. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  5604. strDataTemp[0] = "整体运行模式=3";
  5605. //发送数据
  5606. Code[0] = 0;
  5607. Code[1] = 0;
  5608. for (int i = 0; i < strDataTemp.Length; i++)
  5609. {
  5610. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  5611. Code[2 * i + 2] = (byte)uwDataTemp;
  5612. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  5613. }
  5614. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  5615. label_FacModeStatus.Text = "启动电机";
  5616. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  5617. //设置转速100%
  5618. var Data = new byte[1];
  5619. Data[0] = (byte)100;
  5620. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  5621. Delay_ms(3000);
  5622. } while (false);
  5623. //判断车速
  5624. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  5625. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  5626. {
  5627. label_FacModeSpeed.BackColor = Color.Green;
  5628. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  5629. }
  5630. else
  5631. {
  5632. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  5633. label_FacModeStatus.Text = "存在故障!";
  5634. label_FacModeResult.BackColor = Color.Red;
  5635. label_FacModeResult.Text = "测试异常";
  5636. Delay_ms(500);
  5637. //存储异常并上传
  5638. FacMode_Stop(false);
  5639. return;
  5640. }
  5641. //判断电压
  5642. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  5643. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  5644. {
  5645. label_FacModeVolTest.BackColor = Color.Green;
  5646. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  5647. }
  5648. else
  5649. {
  5650. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  5651. label_FacModeStatus.Text = "存在故障!";
  5652. label_FacModeResult.BackColor = Color.Red;
  5653. label_FacModeResult.Text = "测试异常";
  5654. Delay_ms(500);
  5655. //存储异常并上传
  5656. FacMode_Stop(false);
  5657. return;
  5658. }
  5659. //判断电流
  5660. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  5661. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  5662. {
  5663. label_FacModeCurrentTest.BackColor = Color.Green;
  5664. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  5665. }
  5666. else
  5667. {
  5668. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  5669. label_FacModeStatus.Text = "存在故障!";
  5670. label_FacModeResult.BackColor = Color.Red;
  5671. label_FacModeResult.Text = "测试异常";
  5672. Delay_ms(500);
  5673. //存储异常并上传
  5674. FacMode_Stop(false);
  5675. return;
  5676. }
  5677. //判断温度
  5678. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  5679. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  5680. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  5681. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  5682. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  5683. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  5684. {
  5685. label_FacModeNTC.BackColor = Color.Green;
  5686. 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");
  5687. }
  5688. else
  5689. {
  5690. 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");
  5691. label_FacModeStatus.Text = "存在故障!";
  5692. label_FacModeResult.BackColor = Color.Red;
  5693. label_FacModeResult.Text = "测试异常";
  5694. Delay_ms(500);
  5695. //存储异常并上传
  5696. FacMode_Stop(false);
  5697. return;
  5698. }
  5699. //判断转速
  5700. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  5701. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  5702. {
  5703. label_FacModeMotorSpeed.BackColor = Color.Green;
  5704. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  5705. }
  5706. else
  5707. {
  5708. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  5709. label_FacModeStatus.Text = "存在故障!";
  5710. label_FacModeResult.BackColor = Color.Red;
  5711. label_FacModeResult.Text = "测试异常";
  5712. Delay_ms(500);
  5713. //存储异常并上传
  5714. FacMode_Stop(false);
  5715. return;
  5716. }
  5717. //发送指令停止电机
  5718. do
  5719. {
  5720. //设置转速0%
  5721. var Data = new byte[1];
  5722. Data[0] = (byte)0;
  5723. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  5724. //获取调试信息
  5725. string DebugDefaultInfo = "";
  5726. if (richTextBox_DebugParam.Text == string.Empty)
  5727. {
  5728. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  5729. label_FacModeStatus.Text = "存在故障!";
  5730. label_FacModeResult.BackColor = Color.Red;
  5731. label_FacModeResult.Text = "测试异常";
  5732. Delay_ms(500);
  5733. //存储异常并上传
  5734. FacMode_Stop(false);
  5735. return;
  5736. }
  5737. else
  5738. {
  5739. DebugDefaultInfo = richTextBox_DebugParam.Text;
  5740. }
  5741. //设置模式
  5742. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  5743. //发送数据
  5744. Code[0] = 0;
  5745. Code[1] = 0;
  5746. for (int i = 0; i < strDataTemp.Length; i++)
  5747. {
  5748. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  5749. Code[2 * i + 2] = (byte)uwDataTemp;
  5750. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  5751. }
  5752. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  5753. label_FacModeStatus.Text = "停止电机";
  5754. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  5755. Delay_ms(2000);
  5756. } while (false);
  5757. }
  5758. else
  5759. {
  5760. label_FacModeSpeed.BackColor = Color.Yellow;
  5761. label_FacModeVolTest.BackColor = Color.Yellow;
  5762. label_FacModeCurrentTest.BackColor = Color.Yellow;
  5763. label_FacModeNTC.BackColor = Color.Yellow;
  5764. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  5765. label_FacModeStatus.Text = "跳过基础功能检测!";
  5766. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  5767. Delay_ms(500);
  5768. }
  5769. //力矩检测
  5770. if (checkBox_FacTor.Checked)
  5771. {
  5772. label_FacModeStatus.Text = "力矩传感器检测!";
  5773. //发送指令进入配置模式
  5774. do
  5775. {
  5776. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  5777. {
  5778. break;
  5779. }
  5780. Code[0] = 0x01;
  5781. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5782. WriteACK = false;
  5783. WriteCnt = 0;
  5784. ACK_WaitCnt = 0;
  5785. while (ACK_WaitCnt <= 2) ; //1s
  5786. if (textBox_RunInfo_Vol.Text != "---")
  5787. {
  5788. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5789. Delay_ms(500);
  5790. }
  5791. else
  5792. {
  5793. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  5794. label_FacModeStatus.Text = "存在故障!";
  5795. label_FacModeResult.BackColor = Color.Red;
  5796. label_FacModeResult.Text = "测试异常";
  5797. Delay_ms(500);
  5798. //存储异常并上传
  5799. FacMode_Stop(false);
  5800. return;
  5801. }
  5802. } while (false);
  5803. ushort Max = 0, Torque = 0;
  5804. //提示输入力矩信号
  5805. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  5806. ACK_WaitCnt = 0;
  5807. while (ACK_WaitCnt <= 20) //10s
  5808. {
  5809. //获取力矩值
  5810. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  5811. if (Torque > Max)
  5812. Max = Torque;
  5813. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  5814. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  5815. (ACK_WaitCnt >= 6))
  5816. {
  5817. label_FacModeTq.BackColor = Color.Green;
  5818. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  5819. break;
  5820. }
  5821. }
  5822. if (ACK_WaitCnt >= 20)
  5823. {
  5824. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + "\r\n");
  5825. label_FacModeStatus.Text = "存在故障!";
  5826. label_FacModeResult.BackColor = Color.Red;
  5827. label_FacModeResult.Text = "测试异常";
  5828. Delay_ms(500);
  5829. //存储异常并上传
  5830. FacMode_Stop(false);
  5831. return;
  5832. }
  5833. }
  5834. else
  5835. {
  5836. label_FacModeTq.BackColor = Color.Yellow;
  5837. label_FacModeCad.BackColor = Color.Yellow;
  5838. label_FacModeStatus.Text = "跳过力矩检测!";
  5839. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  5840. Delay_ms(500);
  5841. }
  5842. //踏频检测
  5843. if (checkBox_FacCad.Checked)
  5844. {
  5845. label_FacModeStatus.Text = "踏频传感器检测!";
  5846. //发送指令进入配置模式
  5847. do
  5848. {
  5849. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  5850. {
  5851. break;
  5852. }
  5853. Code[0] = 0x01;
  5854. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5855. WriteACK = false;
  5856. WriteCnt = 0;
  5857. ACK_WaitCnt = 0;
  5858. while (ACK_WaitCnt <= 2) ; //1s
  5859. if (textBox_RunInfo_Vol.Text != "---")
  5860. {
  5861. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5862. Delay_ms(500);
  5863. }
  5864. else
  5865. {
  5866. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  5867. label_FacModeStatus.Text = "存在故障!";
  5868. label_FacModeResult.BackColor = Color.Red;
  5869. label_FacModeResult.Text = "测试异常";
  5870. Delay_ms(500);
  5871. //存储异常并上传
  5872. FacMode_Stop(false);
  5873. return;
  5874. }
  5875. } while (false);
  5876. ushort Max = 0, Cadence = 0;
  5877. //提示输入踏频信号
  5878. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  5879. ACK_WaitCnt = 0;
  5880. while (ACK_WaitCnt <= 20) //10s
  5881. {
  5882. //获取踏频
  5883. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  5884. if (Cadence > Max)
  5885. Max = Cadence;
  5886. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  5887. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  5888. (ACK_WaitCnt >= 6))
  5889. {
  5890. label_FacModeCad.BackColor = Color.Green;
  5891. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  5892. break;
  5893. }
  5894. }
  5895. if (ACK_WaitCnt >= 20)
  5896. {
  5897. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + "\r\n");
  5898. label_FacModeStatus.Text = "存在故障!";
  5899. label_FacModeResult.BackColor = Color.Red;
  5900. label_FacModeResult.Text = "测试异常";
  5901. Delay_ms(500);
  5902. //存储异常并上传
  5903. FacMode_Stop(false);
  5904. return;
  5905. }
  5906. }
  5907. else
  5908. {
  5909. label_FacModeTq.BackColor = Color.Yellow;
  5910. label_FacModeCad.BackColor = Color.Yellow;
  5911. label_FacModeStatus.Text = "跳过踏频检测!";
  5912. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  5913. Delay_ms(500);
  5914. }
  5915. //转把检测
  5916. if (checkBox_FacThrrotleTest.Checked)
  5917. {
  5918. label_FacModeStatus.Text = "转把检测";
  5919. //发送指令进入配置模式
  5920. do
  5921. {
  5922. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  5923. {
  5924. break;
  5925. }
  5926. Code[0] = 0x01;
  5927. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  5928. WriteACK = false;
  5929. WriteCnt = 0;
  5930. ACK_WaitCnt = 0;
  5931. while (ACK_WaitCnt <= 2) ; //1s
  5932. if (textBox_RunInfo_Vol.Text != "---")
  5933. {
  5934. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  5935. Delay_ms(500);
  5936. }
  5937. else
  5938. {
  5939. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  5940. label_FacModeStatus.Text = "存在故障!";
  5941. label_FacModeResult.BackColor = Color.Red;
  5942. label_FacModeResult.Text = "测试异常";
  5943. Delay_ms(500);
  5944. //存储异常并上传
  5945. FacMode_Stop(false);
  5946. return;
  5947. }
  5948. } while (false);
  5949. //进入TURBO档
  5950. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  5951. Code[0] = 0x04;
  5952. Code[1] = 0xF0;
  5953. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  5954. WriteACK = false;
  5955. WriteCnt = 0;
  5956. ACK_WaitCnt = 0;
  5957. while (ACK_WaitCnt <= 2) ; //1s
  5958. if (textBox_RunInfo_GearSt.Text != "TURBO")
  5959. {
  5960. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  5961. label_FacModeStatus.Text = "存在故障!";
  5962. label_FacModeResult.BackColor = Color.Red;
  5963. label_FacModeResult.Text = "测试异常";
  5964. Delay_ms(500);
  5965. //存储异常并上传
  5966. FacMode_Stop(false);
  5967. return;
  5968. }
  5969. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,10s内转动转把" + "\r\n");
  5970. ACK_WaitCnt = 0;
  5971. while (ACK_WaitCnt <= 20)
  5972. {
  5973. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  5974. {
  5975. label_FacModeGas.BackColor = Color.Green;
  5976. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  5977. break;
  5978. }
  5979. }
  5980. if (ACK_WaitCnt >= 20) //转把超时
  5981. {
  5982. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  5983. label_FacModeStatus.Text = "存在故障!";
  5984. label_FacModeResult.BackColor = Color.Red;
  5985. label_FacModeResult.Text = "测试异常";
  5986. Delay_ms(500);
  5987. //存储异常并上传
  5988. FacMode_Stop(false);
  5989. return;
  5990. }
  5991. }
  5992. else
  5993. {
  5994. label_FacModeGas.BackColor = Color.Yellow;
  5995. label_FacModeStatus.Text = "跳过转把检测!";
  5996. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  5997. Delay_ms(500);
  5998. }
  5999. //刹车检测
  6000. if (checkBox_FacBreakTest.Checked)
  6001. {
  6002. label_FacModeStatus.Text = "刹把检测";
  6003. //发送指令进入配置模式
  6004. do
  6005. {
  6006. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6007. {
  6008. break;
  6009. }
  6010. Code[0] = 0x01;
  6011. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6012. WriteACK = false;
  6013. WriteCnt = 0;
  6014. ACK_WaitCnt = 0;
  6015. while (ACK_WaitCnt <= 2) ; //1s
  6016. if (textBox_RunInfo_Vol.Text != "---")
  6017. {
  6018. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6019. Delay_ms(500);
  6020. }
  6021. else
  6022. {
  6023. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6024. label_FacModeStatus.Text = "存在故障!";
  6025. label_FacModeResult.BackColor = Color.Red;
  6026. label_FacModeResult.Text = "测试异常";
  6027. Delay_ms(500);
  6028. //存储异常并上传
  6029. FacMode_Stop(false);
  6030. return;
  6031. }
  6032. } while (false);
  6033. //启动电机进入WALK模式
  6034. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  6035. Code[0] = 0x22;
  6036. Code[1] = 0xF0;
  6037. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6038. WriteACK = false;
  6039. WriteCnt = 0;
  6040. ACK_WaitCnt = 0;
  6041. while (ACK_WaitCnt <= 2) ; //1s
  6042. if (textBox_RunInfo_GearSt.Text != "WALK")
  6043. {
  6044. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6045. label_FacModeStatus.Text = "存在故障!";
  6046. label_FacModeResult.BackColor = Color.Red;
  6047. label_FacModeResult.Text = "测试异常";
  6048. Delay_ms(500);
  6049. //存储异常并上传
  6050. FacMode_Stop(false);
  6051. return;
  6052. }
  6053. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  6054. ACK_WaitCnt = 0;
  6055. while (ACK_WaitCnt <= 20)
  6056. {
  6057. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  6058. {
  6059. label_FacModeBreak.BackColor = Color.Green;
  6060. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  6061. break;
  6062. }
  6063. }
  6064. if (ACK_WaitCnt >= 20) //剎把超时
  6065. {
  6066. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
  6067. label_FacModeStatus.Text = "存在故障!";
  6068. label_FacModeResult.BackColor = Color.Red;
  6069. label_FacModeResult.Text = "测试异常";
  6070. Delay_ms(500);
  6071. //存储异常并上传
  6072. FacMode_Stop(false);
  6073. return;
  6074. }
  6075. //停止电机
  6076. Code[0] = 0x00;
  6077. Code[1] = 0xF0;
  6078. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6079. WriteACK = false;
  6080. WriteCnt = 0;
  6081. ACK_WaitCnt = 0;
  6082. while (ACK_WaitCnt <= 2) ; //1s
  6083. if (textBox_RunInfo_GearSt.Text != "OFF")
  6084. {
  6085. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6086. label_FacModeStatus.Text = "存在故障!";
  6087. label_FacModeResult.BackColor = Color.Red;
  6088. label_FacModeResult.Text = "测试异常";
  6089. Delay_ms(500);
  6090. //存储异常并上传
  6091. FacMode_Stop(false);
  6092. return;
  6093. }
  6094. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  6095. Delay_ms(500);
  6096. }
  6097. else
  6098. {
  6099. label_FacModeBreak.BackColor = Color.Yellow;
  6100. label_FacModeStatus.Text = "跳过刹车检测!";
  6101. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  6102. Delay_ms(500);
  6103. }
  6104. //前后灯检测
  6105. if (checkBox_FacLightTest.Checked)
  6106. {
  6107. //前后灯检测
  6108. label_FacModeStatus.Text = "前后灯检测";
  6109. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  6110. //发送指令打开车灯
  6111. Code[0] = 0x00;
  6112. Code[1] = 0xF1;
  6113. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6114. WriteACK = false;
  6115. WriteCnt = 0;
  6116. ACK_WaitCnt = 0;
  6117. while (ACK_WaitCnt <= 2) ; //1s
  6118. if (textBox_RunInfo_LightSwitch.Text != "ON")
  6119. {
  6120. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  6121. label_FacModeStatus.Text = "存在故障!";
  6122. label_FacModeResult.BackColor = Color.Red;
  6123. label_FacModeResult.Text = "测试异常";
  6124. Delay_ms(500);
  6125. //存储异常并上传
  6126. FacMode_Stop(false);
  6127. return;
  6128. }
  6129. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  6130. Delay_ms(500);
  6131. //提示检查灯压是否正确
  6132. if (MessageBox.Show("前后灯是否正常?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  6133. {
  6134. label_FacModeLightF.BackColor = Color.Green;
  6135. label_FacModeLightB.BackColor = Color.Green;
  6136. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  6137. Delay_ms(500);
  6138. }
  6139. else
  6140. {
  6141. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  6142. label_FacModeStatus.Text = "存在故障!";
  6143. label_FacModeResult.BackColor = Color.Red;
  6144. label_FacModeResult.Text = "测试异常";
  6145. Delay_ms(500);
  6146. //存储异常并上传
  6147. FacMode_Stop(false);
  6148. return;
  6149. }
  6150. //发送指令关闭车灯
  6151. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  6152. Code[0] = 0x00;
  6153. Code[1] = 0xF0;
  6154. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6155. WriteACK = false;
  6156. WriteCnt = 0;
  6157. ACK_WaitCnt = 0;
  6158. while (ACK_WaitCnt <= 2) ; //1s
  6159. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  6160. {
  6161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  6162. label_FacModeStatus.Text = "存在故障!";
  6163. label_FacModeResult.BackColor = Color.Red;
  6164. label_FacModeResult.Text = "测试异常";
  6165. Delay_ms(500);
  6166. //存储异常并上传
  6167. FacMode_Stop(false);
  6168. return;
  6169. }
  6170. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  6171. Delay_ms(500);
  6172. }
  6173. else
  6174. {
  6175. label_FacModeLightF.BackColor = Color.Yellow;
  6176. label_FacModeLightB.BackColor = Color.Yellow;
  6177. label_FacModeStatus.Text = "跳过前后灯检测!";
  6178. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  6179. Delay_ms(500);
  6180. }
  6181. //软件版本检测
  6182. do
  6183. {
  6184. label_FacModeStatus.Text = "软件版本确认";
  6185. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  6186. //发送指令读取版本
  6187. Class_Motor_Ver.Mode = "---";
  6188. Class_Motor_Ver.SN = "---";
  6189. Class_Motor_Ver.HW = "---";
  6190. Class_Motor_Ver.FW = "---";
  6191. Class_Motor_Ver.Special = "---";
  6192. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  6193. ACK_WaitCnt = 0;
  6194. while (ACK_WaitCnt <= 2) ; //1s
  6195. if (Class_Motor_Ver.Mode == "---")
  6196. {
  6197. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  6198. label_FacModeStatus.Text = "存在故障!";
  6199. label_FacModeResult.BackColor = Color.Red;
  6200. label_FacModeResult.Text = "测试异常";
  6201. Delay_ms(500);
  6202. //存储异常并上传
  6203. FacMode_Stop(false);
  6204. return;
  6205. }
  6206. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  6207. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  6208. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  6209. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  6210. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  6211. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  6212. //判断版本是否正确
  6213. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  6214. string VerRead = "";
  6215. try
  6216. {
  6217. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  6218. }
  6219. catch (System.Exception)
  6220. {
  6221. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  6222. label_FacModeStatus.Text = "存在故障!";
  6223. label_FacModeResult.BackColor = Color.Red;
  6224. label_FacModeResult.Text = "测试异常";
  6225. Delay_ms(500);
  6226. //存储异常并上传
  6227. FacMode_Stop(false);
  6228. return;
  6229. }
  6230. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  6231. {
  6232. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  6233. label_FacModeStatus.Text = "存在故障!";
  6234. label_FacModeResult.BackColor = Color.Red;
  6235. label_FacModeResult.Text = "测试异常";
  6236. Delay_ms(500);
  6237. //存储异常并上传
  6238. FacMode_Stop(false);
  6239. return;
  6240. }
  6241. label_FacModeFWVersion.BackColor = Color.Green;
  6242. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  6243. Delay_ms(500);
  6244. } while (false);
  6245. //测试合格
  6246. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  6247. label_FacModeStatus.Text = "测试结束!";
  6248. label_FacModeResult.BackColor = Color.Green;
  6249. label_FacModeResult.Text = "测试合格";
  6250. Delay_ms(500);
  6251. //存储并上传
  6252. FacMode_Stop(true);
  6253. return;
  6254. }
  6255. private void FacModelLabelInit()
  6256. {
  6257. //测试状态标签
  6258. label_FacModeResult.BackColor = Color.Yellow;
  6259. label_FacModeResult.Text = "测试中";
  6260. //测试过程标签
  6261. label_FacModeStatus.Text = "测试就绪";
  6262. //测试结果标签
  6263. foreach (Control c in groupBox28.Controls)
  6264. {
  6265. if (c is Label)
  6266. {
  6267. if (c.Text == string.Empty)
  6268. c.BackColor = Color.Red;
  6269. }
  6270. }
  6271. }
  6272. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  6273. {
  6274. //更新生产配置文件目录
  6275. GetDateList(false);
  6276. }
  6277. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  6278. {
  6279. //更新生产配置文件目录
  6280. GetDateList(false);
  6281. }
  6282. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  6283. {
  6284. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  6285. richTextBox_FacModeLog.ScrollToCaret();
  6286. }
  6287. /// <summary>
  6288. /// 参数检验测试停止
  6289. /// </summary>
  6290. /// <param name="OK_Flag"></param>
  6291. private void CheckMode_Stop(bool OK_Flag)
  6292. {
  6293. //打开开始按钮
  6294. button_CheckModeStart.Enabled = true;
  6295. //系统关机
  6296. var Code = new byte[32];//发送的指令数据
  6297. Code[0] = 0xF0;
  6298. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6299. //关闭串口
  6300. mySerialProcess.SerialClose(false);
  6301. //路径设置
  6302. string LocalSavePath = "";
  6303. string ServerSavePath = "";
  6304. if (OK_Flag)
  6305. {
  6306. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  6307. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  6308. }
  6309. else
  6310. {
  6311. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  6312. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  6313. }
  6314. if (Directory.Exists(LocalSavePath) == false)
  6315. {
  6316. Directory.CreateDirectory(LocalSavePath);
  6317. }
  6318. //保存和上传
  6319. string LogSavePath = "";
  6320. string LogSaveFileName = "";
  6321. string ProductInfo = textBox_CheckModeScan.Text;
  6322. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  6323. if (Directory.Exists(LogSavePath) == false)
  6324. {
  6325. Directory.CreateDirectory(LogSavePath);
  6326. }
  6327. //测试页面
  6328. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  6329. Graphics g = Graphics.FromImage(bit);
  6330. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  6331. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  6332. bit.Save(LogSaveFileName);
  6333. //上传测试页面到服务器
  6334. if (myFtp.IsNetConnected == true)
  6335. {
  6336. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6337. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6338. {
  6339. myFtp.MakeDir(ServerSavePath + DateNow);
  6340. }
  6341. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6342. {
  6343. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6344. }
  6345. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6346. if (result == true)
  6347. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  6348. }
  6349. //测试记录
  6350. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  6351. string file_str = "";
  6352. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  6353. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  6354. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  6355. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  6356. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  6357. //上传测试记录到服务器
  6358. if (myFtp.IsNetConnected == true)
  6359. {
  6360. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  6361. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  6362. {
  6363. myFtp.MakeDir(ServerSavePath + DateNow);
  6364. }
  6365. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  6366. {
  6367. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  6368. }
  6369. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  6370. if (result == true)
  6371. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  6372. }
  6373. }
  6374. /// <summary>
  6375. /// 参数检验开始
  6376. /// </summary>
  6377. /// <param name="sender"></param>
  6378. /// <param name="e"></param>
  6379. private void button_CheckModeStart_Click(object sender, EventArgs e)
  6380. {
  6381. //测试项目关闭编辑
  6382. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  6383. foreach (Control c in groupBox29.Controls)
  6384. {
  6385. if (c is CheckBox)
  6386. c.Enabled = false;
  6387. }
  6388. ReadLockStatus = true;
  6389. //检查配置文件
  6390. if (comboBox_CheckModeCfgFile.Text == "")
  6391. {
  6392. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6393. return;
  6394. }
  6395. //开始测试
  6396. CheckTestStart();
  6397. }
  6398. /// <summary>
  6399. /// 参数检验测试子函数
  6400. /// </summary>
  6401. private void CheckTestStart()
  6402. {
  6403. //初始化标签
  6404. CheckModeLabelInit();
  6405. richTextBox_CheckModeLog.Clear();
  6406. //按钮禁止操作
  6407. button_CheckModeStart.Enabled = false;
  6408. //记录配置文件
  6409. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  6410. //检查打标信息
  6411. label_CheckModeStatus.Text = "检查扫码信息";
  6412. Delay_ms(500);
  6413. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  6414. if (textBox_CheckModeScan.Text == string.Empty)
  6415. {
  6416. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6417. return;
  6418. }
  6419. try
  6420. {
  6421. if (中置电机ToolStripMenuItem.Checked == true)
  6422. {
  6423. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  6424. {
  6425. label_CheckModeStatus.Text = "存在故障!";
  6426. label_CheckModeResult.BackColor = Color.Red;
  6427. label_CheckModeResult.Text = "标签格式错误";
  6428. button_CheckModeStart.Enabled = true;
  6429. return;
  6430. }
  6431. }
  6432. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6433. {
  6434. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  6435. {
  6436. label_CheckModeStatus.Text = "存在故障!";
  6437. label_CheckModeResult.BackColor = Color.Red;
  6438. label_CheckModeResult.Text = "标签格式错误";
  6439. button_CheckModeStart.Enabled = true;
  6440. return;
  6441. }
  6442. }
  6443. }
  6444. catch (System.Exception)
  6445. {
  6446. label_CheckModeStatus.Text = "存在故障!";
  6447. label_CheckModeResult.BackColor = Color.Red;
  6448. label_CheckModeResult.Text = "标签格式错误";
  6449. button_CheckModeStart.Enabled = true;
  6450. return;
  6451. }
  6452. //打开串口
  6453. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  6454. if (!mySerialProcess.mySerial.IsOpen)
  6455. {
  6456. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6457. return;
  6458. }
  6459. //流水号计数
  6460. //...
  6461. //创建线程,执行测试任务
  6462. Thread th = new Thread(CheckModeTest_Task);
  6463. th.Start();
  6464. }
  6465. /// <summary>
  6466. /// 执行一次测试任务
  6467. /// </summary>
  6468. private void CheckModeTest_Task()
  6469. {
  6470. //开始测试
  6471. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  6472. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  6473. //变量定义
  6474. var Code = new byte[255];//发送的指令数据
  6475. ushort DataTemp;
  6476. short DataTemp_Int16;
  6477. string ResultPathName = "";
  6478. label_CheckModeStatus.Text = "开始测试";
  6479. Delay_ms(500);
  6480. label_CheckModeStatus.Text = "系统开机";
  6481. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  6482. BootInfo = "";
  6483. Code[0] = 0xF0;
  6484. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6485. Delay_ms(1500);
  6486. Code[0] = 0xF1;
  6487. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6488. ACK_WaitCnt = 0;
  6489. while (ACK_WaitCnt <= 2) ; //1s
  6490. //检查BOOT版本
  6491. if (BootInfo != string.Empty)
  6492. {
  6493. label_CheckModeBoot.BackColor = Color.Green;
  6494. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  6495. Delay_ms(500);
  6496. }
  6497. else
  6498. {
  6499. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  6500. label_CheckModeStatus.Text = "存在故障!";
  6501. label_CheckModeResult.BackColor = Color.Red;
  6502. label_CheckModeResult.Text = "测试异常";
  6503. Delay_ms(500);
  6504. //存储异常并上传
  6505. CheckMode_Stop(false);
  6506. return;
  6507. }
  6508. //发送指令读取版本信息
  6509. do
  6510. {
  6511. label_CheckModeStatus.Text = "读取版本信息";
  6512. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  6513. //发送指令读取版本
  6514. Class_Motor_Ver.Mode = "---";
  6515. Class_Motor_Ver.SN = "---";
  6516. Class_Motor_Ver.HW = "---";
  6517. Class_Motor_Ver.FW = "---";
  6518. Class_Motor_Ver.Special = "---";
  6519. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  6520. ACK_WaitCnt = 0;
  6521. while (ACK_WaitCnt <= 2) ; //1s
  6522. if (Class_Motor_Ver.Mode == "---")
  6523. {
  6524. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  6525. label_CheckModeStatus.Text = "存在故障!";
  6526. label_CheckModeResult.BackColor = Color.Red;
  6527. label_CheckModeResult.Text = "测试异常";
  6528. Delay_ms(500);
  6529. //存储异常并上传
  6530. CheckMode_Stop(false);
  6531. return;
  6532. }
  6533. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  6534. Delay_ms(500);
  6535. } while (false);
  6536. //软件版本检查
  6537. if (checkBox_CheckModeFWVer.Checked)
  6538. {
  6539. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  6540. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  6541. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  6542. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  6543. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  6544. //判断版本是否正确
  6545. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  6546. string VerRead = "";
  6547. try
  6548. {
  6549. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  6550. }
  6551. catch (System.Exception)
  6552. {
  6553. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  6554. label_CheckModeStatus.Text = "存在故障!";
  6555. label_CheckModeResult.BackColor = Color.Red;
  6556. label_CheckModeResult.Text = "测试异常";
  6557. Delay_ms(500);
  6558. //存储异常并上传
  6559. CheckMode_Stop(false);
  6560. return;
  6561. }
  6562. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  6563. {
  6564. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  6565. label_CheckModeStatus.Text = "存在故障!";
  6566. label_CheckModeResult.BackColor = Color.Red;
  6567. label_CheckModeResult.Text = "测试异常";
  6568. Delay_ms(500);
  6569. //存储异常并上传
  6570. CheckMode_Stop(false);
  6571. return;
  6572. }
  6573. label_CheckModeFWVer.BackColor = Color.Green;
  6574. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  6575. Delay_ms(500);
  6576. }
  6577. else
  6578. {
  6579. label_CheckModeFWVer.BackColor = Color.Yellow;
  6580. label_CheckModeStatus.Text = "跳过软件版本查询";
  6581. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  6582. Delay_ms(500);
  6583. }
  6584. //打标信息核对
  6585. if (checkBox_CheckModeSN.Checked)
  6586. {
  6587. label_CheckModeStatus.Text = "核对打标信息";
  6588. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  6589. //根据扫码信息获取型号和SN
  6590. string ScanInfo = textBox_CheckModeScan.Text;
  6591. string regexInfo = "";
  6592. string[] InfoList = { "" };
  6593. try
  6594. {
  6595. if (中置电机ToolStripMenuItem.Checked == true)
  6596. {
  6597. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6598. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6599. }
  6600. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6601. {
  6602. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6603. string Model = InfoList[0];
  6604. string Spec = InfoList[1];
  6605. string Sn = InfoList[2];
  6606. InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6607. InfoList[1] = Sn;
  6608. }
  6609. }
  6610. catch
  6611. {
  6612. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6613. label_FacModeStatus.Text = "存在故障!";
  6614. label_FacModeResult.BackColor = Color.Red;
  6615. label_FacModeResult.Text = "标签格式错误";
  6616. Delay_ms(500);
  6617. //存储异常并上传
  6618. CheckMode_Stop(false);
  6619. return;
  6620. }
  6621. //核对型号
  6622. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  6623. {
  6624. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  6625. label_CheckModeStatus.Text = "存在故障!";
  6626. label_CheckModeResult.BackColor = Color.Red;
  6627. label_CheckModeResult.Text = "测试异常";
  6628. Delay_ms(500);
  6629. //存储异常并上传
  6630. CheckMode_Stop(false);
  6631. return;
  6632. }
  6633. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  6634. Delay_ms(500);
  6635. //核对SN
  6636. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  6637. {
  6638. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  6639. label_CheckModeStatus.Text = "存在故障!";
  6640. label_CheckModeResult.BackColor = Color.Red;
  6641. label_CheckModeResult.Text = "测试异常";
  6642. Delay_ms(500);
  6643. //存储异常并上传
  6644. CheckMode_Stop(false);
  6645. return;
  6646. }
  6647. label_CheckModeSN.BackColor = Color.Green;
  6648. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  6649. Delay_ms(500);
  6650. }
  6651. else
  6652. {
  6653. label_CheckModeSN.BackColor = Color.Yellow;
  6654. label_CheckModeStatus.Text = "跳过打标信息确认";
  6655. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  6656. Delay_ms(500);
  6657. }
  6658. //参数检验
  6659. if (checkBox_CheckModeCfg.Checked)
  6660. {
  6661. //读取配置文件信息
  6662. label_CheckModeStatus.Text = "参数检查";
  6663. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6664. //配置文件
  6665. List<byte[]> CmdList = new List<byte[]>();
  6666. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  6667. //从服务器下载文件
  6668. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6669. {
  6670. string SelectFile = "";
  6671. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  6672. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6673. {
  6674. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  6675. }
  6676. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6677. //打开文件
  6678. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  6679. ConfigCmd.Clear();
  6680. while (streamReader.Peek() != -1)
  6681. {
  6682. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  6683. if (fileLineInfo.Contains("["))
  6684. {
  6685. if (fileLineInfo.Contains("助力参数"))
  6686. {
  6687. fileLineInfo = streamReader.ReadLine();
  6688. }
  6689. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  6690. }
  6691. }
  6692. streamReader.Close();
  6693. }
  6694. //从本地加载文件
  6695. else
  6696. {
  6697. string SelectFile = "";
  6698. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  6699. //打开文件
  6700. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6701. ConfigCmd.Clear();
  6702. while (streamReader.Peek() != -1)
  6703. {
  6704. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  6705. if (fileLineInfo.Contains("["))
  6706. {
  6707. if (fileLineInfo.Contains("助力参数"))
  6708. {
  6709. fileLineInfo = streamReader.ReadLine();
  6710. }
  6711. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  6712. }
  6713. }
  6714. streamReader.Close();
  6715. }
  6716. int CmdNum = ConfigCmd.Count(); //指令个数
  6717. Delay_ms(500);
  6718. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  6719. Delay_ms(500);
  6720. //逐条读取比较
  6721. try
  6722. {
  6723. foreach (string key in ConfigCmd.Keys)
  6724. {
  6725. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  6726. CmdRevStrTemp = "";
  6727. if (key.Contains("曲线"))
  6728. {
  6729. byte LineNum = 0;
  6730. var code = new byte[4];
  6731. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  6732. if (LineNum <= 5)
  6733. {
  6734. code[0] = (byte)(LineNum & 0xFF);
  6735. code[1] = (byte)((LineNum >> 8) & 0xFF);
  6736. code[2] = (byte)(LineNum & 0xFF);
  6737. code[3] = (byte)((LineNum >> 8) & 0xFF);
  6738. }
  6739. else
  6740. {
  6741. code[0] = (byte)(LineNum & 0xFF);
  6742. code[1] = (byte)((LineNum >> 8) & 0xFF);
  6743. code[2] = (byte)(5 & 0xFF);
  6744. code[3] = (byte)((5 >> 8) & 0xFF);
  6745. }
  6746. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  6747. }
  6748. else
  6749. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  6750. Delay_ms(500);
  6751. if (CmdRevStrTemp == string.Empty)
  6752. {
  6753. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  6754. label_CheckModeStatus.Text = "存在故障!";
  6755. label_CheckModeResult.BackColor = Color.Red;
  6756. label_CheckModeResult.Text = "测试异常";
  6757. Delay_ms(500);
  6758. //存储异常并上传
  6759. CheckMode_Stop(false);
  6760. return;
  6761. }
  6762. //比较当前指令,读取的配置文件和返回数据比较
  6763. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  6764. string ParamRead = "";
  6765. if (string.Compare(key, "[其它传感器参数]") == 0)
  6766. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //该指令包含力矩参数
  6767. else
  6768. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim();
  6769. if (ParamWrite.Contains(ParamRead))
  6770. {
  6771. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  6772. continue;
  6773. }
  6774. else
  6775. {
  6776. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  6777. label_CheckModeStatus.Text = "存在故障!";
  6778. label_CheckModeResult.BackColor = Color.Red;
  6779. label_CheckModeResult.Text = "测试异常";
  6780. Delay_ms(500);
  6781. //存储异常并上传
  6782. CheckMode_Stop(false);
  6783. return;
  6784. }
  6785. }
  6786. }
  6787. catch (System.Exception)
  6788. {
  6789. timer_1s.Enabled = false;
  6790. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6791. timer_1s.Enabled = true;
  6792. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  6793. }
  6794. }
  6795. else
  6796. {
  6797. label_CheckModeCfg.BackColor = Color.Yellow;
  6798. label_CheckModeStatus.Text = "跳过参数检验";
  6799. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  6800. Delay_ms(500);
  6801. }
  6802. label_CheckModeCfg.BackColor = Color.Green;
  6803. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  6804. Delay_ms(500);
  6805. //读取力矩传感器
  6806. do
  6807. {
  6808. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  6809. //发送指令读取力矩传感器标定数据
  6810. CmdRevStrTemp = "";
  6811. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  6812. ACK_WaitCnt = 0;
  6813. while (ACK_WaitCnt <= 2) ; //1s
  6814. if (CmdRevStrTemp == "---")
  6815. {
  6816. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  6817. label_CheckModeStatus.Text = "存在故障!";
  6818. label_CheckModeResult.BackColor = Color.Red;
  6819. label_CheckModeResult.Text = "测试异常";
  6820. Delay_ms(500);
  6821. //存储异常并上传
  6822. CheckMode_Stop(false);
  6823. return;
  6824. }
  6825. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  6826. //取力矩传感器数据
  6827. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  6828. ushort MaxTorque;
  6829. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  6830. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  6831. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  6832. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  6833. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  6834. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  6835. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  6836. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  6837. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  6838. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  6839. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  6840. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  6841. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  6842. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  6843. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  6844. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  6845. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  6846. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  6847. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  6848. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  6849. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  6850. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  6851. //传感器标定检验
  6852. if (checkBox_CheckModeTorque.Checked)
  6853. {
  6854. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  6855. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  6856. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  6857. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  6858. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  6859. //与设置值比较
  6860. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  6861. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  6862. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  6863. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  6864. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  6865. )
  6866. {
  6867. label_CheckModeTorque.BackColor = Color.Green;
  6868. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  6869. Delay_ms(500);
  6870. }
  6871. else
  6872. {
  6873. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  6874. label_CheckModeStatus.Text = "存在故障!";
  6875. label_CheckModeResult.BackColor = Color.Red;
  6876. label_CheckModeResult.Text = "测试异常";
  6877. Delay_ms(500);
  6878. //存储异常并上传
  6879. CheckMode_Stop(false);
  6880. return;
  6881. }
  6882. }
  6883. else
  6884. {
  6885. label_CheckModeFWVer.BackColor = Color.Yellow;
  6886. label_CheckModeStatus.Text = "跳过传感器标定检验";
  6887. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  6888. Delay_ms(500);
  6889. }
  6890. } while (false);
  6891. //测试合格
  6892. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  6893. label_CheckModeStatus.Text = "测试结束!";
  6894. label_CheckModeResult.BackColor = Color.Green;
  6895. label_CheckModeResult.Text = "测试合格";
  6896. Delay_ms(500);
  6897. //存储并上传
  6898. CheckMode_Stop(true);
  6899. return;
  6900. }
  6901. private void CheckModeLabelInit()
  6902. {
  6903. //测试状态标签
  6904. label_CheckModeResult.BackColor = Color.Yellow;
  6905. label_CheckModeResult.Text = "测试中";
  6906. //测试过程标签
  6907. label_CheckModeStatus.Text = "测试就绪";
  6908. //测试结果标签
  6909. foreach (Control c in groupBox31.Controls)
  6910. {
  6911. if (c is Label)
  6912. {
  6913. if (c.Text == string.Empty)
  6914. c.BackColor = Color.Red;
  6915. }
  6916. }
  6917. }
  6918. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  6919. {
  6920. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  6921. }
  6922. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  6923. {
  6924. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  6925. }
  6926. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  6927. {
  6928. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  6929. UInt32 hour = Time / 3600;
  6930. UInt32 min = (Time % 3600) / 60;
  6931. UInt32 s = (Time % 60);
  6932. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  6933. }
  6934. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  6935. {
  6936. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  6937. richTextBox_CheckModeLog.ScrollToCaret();
  6938. }
  6939. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  6940. {
  6941. EnterForm1.ShowDialog();
  6942. try
  6943. {
  6944. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  6945. {
  6946. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  6947. {
  6948. TorqueParamsForm.ShowDialog();
  6949. }
  6950. else
  6951. {
  6952. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6953. }
  6954. }
  6955. else
  6956. {
  6957. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6958. }
  6959. }
  6960. catch (Exception)
  6961. {
  6962. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6963. }
  6964. }
  6965. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  6966. {
  6967. if (e.KeyCode == Keys.Enter)
  6968. CheckTestStart();
  6969. }
  6970. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  6971. {
  6972. if (e.KeyCode == Keys.Enter)
  6973. TestStart();
  6974. }
  6975. private void button_SpeedDec10_Click(object sender, EventArgs e)
  6976. {
  6977. if (numericUpDown_SpeedAdj.Value <= 10)
  6978. numericUpDown_SpeedAdj.Value = 0;
  6979. else
  6980. numericUpDown_SpeedAdj.Value -= 10;
  6981. }
  6982. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  6983. {
  6984. if (numericUpDown_SpeedAdj.Value >= 90)
  6985. numericUpDown_SpeedAdj.Value = 100;
  6986. else
  6987. numericUpDown_SpeedAdj.Value += 10;
  6988. }
  6989. private void button_SpeedDec1_Click(object sender, EventArgs e)
  6990. {
  6991. if (numericUpDown_SpeedAdj.Value <= 1)
  6992. numericUpDown_SpeedAdj.Value = 0;
  6993. else
  6994. numericUpDown_SpeedAdj.Value -= 1;
  6995. }
  6996. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  6997. {
  6998. if(numericUpDown_SpeedAdj.Value >= 99)
  6999. numericUpDown_SpeedAdj.Value = 100;
  7000. else
  7001. numericUpDown_SpeedAdj.Value += 1;
  7002. }
  7003. bool WriteLockStatus = true;
  7004. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  7005. {
  7006. if (WriteLockStatus == true)
  7007. {
  7008. EnterForm1.ShowDialog();
  7009. try
  7010. {
  7011. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7012. {
  7013. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7014. {
  7015. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  7016. foreach (Control c in groupBox2.Controls)
  7017. {
  7018. if (c is CheckBox)
  7019. c.Enabled = true;
  7020. }
  7021. WriteLockStatus = !WriteLockStatus;
  7022. }
  7023. else
  7024. {
  7025. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7026. }
  7027. }
  7028. else
  7029. {
  7030. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7031. }
  7032. }
  7033. catch (Exception)
  7034. {
  7035. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7036. }
  7037. }
  7038. else
  7039. {
  7040. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7041. foreach (Control c in groupBox2.Controls)
  7042. {
  7043. if (c is CheckBox)
  7044. c.Enabled = false;
  7045. }
  7046. WriteLockStatus = !WriteLockStatus;
  7047. }
  7048. }
  7049. bool ReadLockStatus = true;
  7050. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  7051. {
  7052. if (ReadLockStatus == true)
  7053. {
  7054. EnterForm1.ShowDialog();
  7055. try
  7056. {
  7057. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  7058. {
  7059. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  7060. {
  7061. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  7062. foreach (Control c in groupBox29.Controls)
  7063. {
  7064. if (c is CheckBox)
  7065. c.Enabled = true;
  7066. }
  7067. ReadLockStatus = !ReadLockStatus;
  7068. }
  7069. else
  7070. {
  7071. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7072. }
  7073. }
  7074. else
  7075. {
  7076. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7077. }
  7078. }
  7079. catch (Exception)
  7080. {
  7081. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7082. }
  7083. }
  7084. else
  7085. {
  7086. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7087. foreach (Control c in groupBox29.Controls)
  7088. {
  7089. if (c is CheckBox)
  7090. c.Enabled = false;
  7091. }
  7092. ReadLockStatus = !ReadLockStatus;
  7093. }
  7094. }
  7095. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  7096. {
  7097. System.Diagnostics.Process.Start("osk.exe");
  7098. }
  7099. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  7100. {
  7101. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  7102. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  7103. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  7104. }
  7105. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  7106. {
  7107. comboBox_FacModeCfgDate.SelectedIndex = -1;
  7108. comboBox_FacModeCfgFile.SelectedIndex = -1;
  7109. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  7110. }
  7111. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  7112. {
  7113. VersionForm.ShowDialog();
  7114. }
  7115. private void button_MOS_Cal_Click(object sender, EventArgs e)
  7116. {
  7117. textBox_MOS_R1.Text = "";
  7118. textBox_MOS_R2.Text = "";
  7119. textBox_MOS_R3.Text = "";
  7120. try
  7121. {
  7122. var Code = new byte[16];
  7123. for (int i = 0; i < 16; i++)
  7124. Code[i] = 0;
  7125. ushort uwDataTemp = 0;
  7126. Code[0] = 0xAA;
  7127. Code[1] = 0xAA;
  7128. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  7129. Code[2] = (byte)(uwDataTemp & 0xFF);
  7130. Code[3] = (byte)(uwDataTemp >> 8);
  7131. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  7132. Code[4] = (byte)(uwDataTemp & 0xFF);
  7133. Code[5] = (byte)(uwDataTemp >> 8);
  7134. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  7135. Code[6] = (byte)(uwDataTemp & 0xFF);
  7136. Code[7] = (byte)(uwDataTemp >> 8);
  7137. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  7138. Code[8] = (byte)(uwDataTemp & 0xFF);
  7139. Code[9] = (byte)(uwDataTemp >> 8);
  7140. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  7141. Code[10] = (byte)(uwDataTemp & 0xFF);
  7142. Code[11] = (byte)(uwDataTemp >> 8);
  7143. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A10, Code);
  7144. }
  7145. catch (Exception)
  7146. {
  7147. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7148. }
  7149. }
  7150. private void button_MOS_Read_Click(object sender, EventArgs e)
  7151. {
  7152. foreach (Control c in groupBox21.Controls)
  7153. {
  7154. if (c is TextBox)
  7155. c.Text = "";
  7156. }
  7157. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7158. }
  7159. private void button_MOS_Write_Click(object sender, EventArgs e)
  7160. {
  7161. try
  7162. {
  7163. var Code = new byte[32];
  7164. for (int i = 0; i < 32; i++)
  7165. Code[i] = 0;
  7166. ushort uwDataTemp = 0;
  7167. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  7168. Code[0] = (byte)(uwDataTemp & 0xFF);
  7169. Code[1] = (byte)(uwDataTemp >> 8);
  7170. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  7171. Code[2] = (byte)(uwDataTemp & 0xFF);
  7172. Code[3] = (byte)(uwDataTemp >> 8);
  7173. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  7174. Code[4] = (byte)(uwDataTemp & 0xFF);
  7175. Code[5] = (byte)(uwDataTemp >> 8);
  7176. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  7177. Code[6] = (byte)(uwDataTemp & 0xFF);
  7178. Code[7] = (byte)(uwDataTemp >> 8);
  7179. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  7180. Code[8] = (byte)(uwDataTemp & 0xFF);
  7181. Code[9] = (byte)(uwDataTemp >> 8);
  7182. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  7183. Code[10] = (byte)(uwDataTemp & 0xFF);
  7184. Code[11] = (byte)(uwDataTemp >> 8);
  7185. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  7186. Code[12] = (byte)(uwDataTemp & 0xFF);
  7187. Code[13] = (byte)(uwDataTemp >> 8);
  7188. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  7189. Code[14] = (byte)(uwDataTemp & 0xFF);
  7190. Code[15] = (byte)(uwDataTemp >> 8);
  7191. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C20, Code);
  7192. }
  7193. catch (Exception)
  7194. {
  7195. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  7196. }
  7197. }
  7198. }
  7199. }