mainForm.cs 330 KB

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