mainForm.cs 454 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Diagnostics.Eventing.Reader;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Ports;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.InteropServices;
  12. using System.Runtime.InteropServices.ComTypes;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading;
  16. using System.Web;
  17. using System.Windows.Forms;
  18. using System.Xml.Linq;
  19. namespace Welling_Motor_Debug_Tool
  20. {
  21. public partial class mainForm : Form
  22. {
  23. #region 变量定义
  24. //版本号
  25. public static string Version = "2.2.2";
  26. //串口实例
  27. Serial_Process mySerialProcess = new Serial_Process();
  28. string PortNumSave = "";
  29. string PortBaudrateSave = "";
  30. //本地信息定义
  31. LocalInfo localInfo = new LocalInfo();
  32. //FTP实例
  33. ftp myFtp = new ftp();
  34. //MC运行信息超时计数
  35. bool MC_RunInfo_Refresh = false;
  36. ushort MC_RunInfo_Refresh_Cnt = 0;
  37. //MC调试信息超时计数
  38. bool MC_DebugInfo_Refresh = false;
  39. ushort MC_DebugInfo_Refresh_Cnt = 0;
  40. //MC故障码超时计数
  41. bool MC_ErrorCode_Refresh = false;
  42. ushort MC_ErrorCode_Refresh_Cnt = 0;
  43. //配置参数实例
  44. Params myParams = new Params();
  45. //记录文件名称
  46. string RunInfoSaveFilename = "";
  47. //BMS运行信息超时计数
  48. bool BMS_RunInfo_Refresh = false;
  49. ushort BMS_RunInfo_Refresh_Cnt = 0;
  50. //生产模式关机指令反馈状态
  51. bool PowerOffAckStatus = false;
  52. //登录窗口
  53. public static Login EnterForm1 = new Login();
  54. //生产配置文件信息
  55. ArrayList array_CfgInfo = new ArrayList();
  56. //写入参数返回标志和计数
  57. public bool WriteACK = false;
  58. public ushort WriteCnt = 0;
  59. public ushort ACK_WaitCnt = 0;
  60. //写入参数返回提示标志
  61. public bool ACK_DisFlag = true;
  62. //Boot版本信息
  63. public string BootInfo = "";
  64. //接收指令临时缓存,转string
  65. public string CmdRevStrTemp = "";
  66. //计时器,用于统计运行时间
  67. public Stopwatch stopwatch = new Stopwatch();
  68. //力矩传感器检验参数窗口
  69. public static TorqueParams TorqueParamsForm = new TorqueParams();
  70. //参数生成窗口
  71. public static GenerateParams GenerateParamsForm = new GenerateParams();
  72. //版本信息窗口
  73. public static Version VersionForm = new Version();
  74. //本机硬件信息
  75. public string Local_HdInformation = "";
  76. //指令窗口显示
  77. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  78. #endregion
  79. #region 故障日志结构体定义
  80. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  81. [StructLayout(LayoutKind.Sequential)]
  82. public struct MC_ErrorLogSaveInfo_Struct_t
  83. {
  84. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  85. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  86. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  87. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  88. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  89. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  90. //电机运行信息,占用空间32bytes
  91. [StructLayout(LayoutKind.Sequential)]
  92. public struct MC_RunInfo_Struct_t
  93. {
  94. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  95. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  96. public ushort Power; //电功率 1W,地址偏移4
  97. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  98. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  99. public byte Cadence; //踏频 1rpm,地址偏移10
  100. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  101. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  102. public byte GearSt; //助力档位,地址偏移13
  103. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  104. public byte SOC; //剩余电量 1%,地址偏移15
  105. public ushort RemainDistance; //续航里程 1km,地址偏移16
  106. public ushort Torque_AD; //力矩寄存器,地址偏移18
  107. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  108. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  109. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  110. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  111. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  112. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  113. public UInt32 RS; //预留 4bytes
  114. };
  115. [MarshalAs(UnmanagedType.Struct)]
  116. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  117. //控制变量
  118. public Int16 IqCurrent; //Pu, 地址偏移 48
  119. public Int16 IqVoltage; //Pu, 地址偏移 50
  120. public Int16 IdCurrent; //Pu, 地址偏移 52
  121. public Int16 IdVoltage; //Pu, 地址偏移 54
  122. //状态机
  123. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  124. //预留
  125. public UInt16 RS1;
  126. public UInt16 RS2;
  127. public UInt16 RS3;
  128. };
  129. #endregion
  130. #region 屏幕缩放比例获取
  131. public class PrimaryScreen
  132. {
  133. #region Win32 API
  134. [DllImport("user32.dll")]
  135. static extern IntPtr GetDC(IntPtr ptr);
  136. [DllImport("gdi32.dll")]
  137. static extern int GetDeviceCaps(
  138. IntPtr hdc, // handle to DC
  139. int nIndex // index of capability
  140. );
  141. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  142. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  143. #endregion
  144. #region DeviceCaps常量
  145. const int HORZRES = 8;
  146. const int VERTRES = 10;
  147. const int LOGPIXELSX = 88;
  148. const int LOGPIXELSY = 90;
  149. const int DESKTOPVERTRES = 117;
  150. const int DESKTOPHORZRES = 118;
  151. #endregion
  152. #region 属性
  153. /// <summary>
  154. /// 获取屏幕分辨率当前物理大小
  155. /// </summary>
  156. public static Size WorkingArea
  157. {
  158. get
  159. {
  160. IntPtr hdc = GetDC(IntPtr.Zero);
  161. Size size = new Size();
  162. size.Width = GetDeviceCaps(hdc, HORZRES);
  163. size.Height = GetDeviceCaps(hdc, VERTRES);
  164. ReleaseDC(IntPtr.Zero, hdc);
  165. return size;
  166. }
  167. }
  168. /// <summary>
  169. /// 当前系统DPI_X 大小 一般为96
  170. /// </summary>
  171. public static int DpiX
  172. {
  173. get
  174. {
  175. IntPtr hdc = GetDC(IntPtr.Zero);
  176. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  177. ReleaseDC(IntPtr.Zero, hdc);
  178. return DpiX;
  179. }
  180. }
  181. /// <summary>
  182. /// 当前系统DPI_Y 大小 一般为96
  183. /// </summary>
  184. public static int DpiY
  185. {
  186. get
  187. {
  188. IntPtr hdc = GetDC(IntPtr.Zero);
  189. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  190. ReleaseDC(IntPtr.Zero, hdc);
  191. return DpiX;
  192. }
  193. }
  194. /// <summary>
  195. /// 获取真实设置的桌面分辨率大小
  196. /// </summary>
  197. public static Size DESKTOP
  198. {
  199. get
  200. {
  201. IntPtr hdc = GetDC(IntPtr.Zero);
  202. Size size = new Size();
  203. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  204. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  205. ReleaseDC(IntPtr.Zero, hdc);
  206. return size;
  207. }
  208. }
  209. /// <summary>
  210. /// 获取宽度缩放百分比
  211. /// </summary>
  212. public static float ScaleX
  213. {
  214. get
  215. {
  216. IntPtr hdc = GetDC(IntPtr.Zero);
  217. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  218. int d = GetDeviceCaps(hdc, HORZRES);
  219. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  220. ReleaseDC(IntPtr.Zero, hdc);
  221. return ScaleX;
  222. }
  223. }
  224. /// <summary>
  225. /// 获取高度缩放百分比
  226. /// </summary>
  227. public static float ScaleY
  228. {
  229. get
  230. {
  231. IntPtr hdc = GetDC(IntPtr.Zero);
  232. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  233. ReleaseDC(IntPtr.Zero, hdc);
  234. return ScaleY;
  235. }
  236. }
  237. #endregion
  238. }
  239. #endregion
  240. public static mainForm mainform1 = null;
  241. public mainForm()
  242. {
  243. InitializeComponent();
  244. mainform1 = this;
  245. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  246. stopwatch.Start();
  247. //端口初始化
  248. mySerialProcess.Init();
  249. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  250. //检查备忘录文件
  251. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  252. {
  253. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  254. }
  255. //检验流水号记录文件
  256. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  257. {
  258. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  259. }
  260. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  261. {
  262. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  263. }
  264. //检查文件夹
  265. if (!Directory.Exists(localInfo.LocalPath))
  266. {
  267. Directory.CreateDirectory(localInfo.LocalPath);
  268. }
  269. if (!Directory.Exists(localInfo.LocalDataPath))
  270. {
  271. Directory.CreateDirectory(localInfo.LocalDataPath);
  272. }
  273. if (!Directory.Exists(localInfo.ToolsPath))
  274. {
  275. Directory.CreateDirectory(localInfo.ToolsPath);
  276. }
  277. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  278. {
  279. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  280. }
  281. //检查配置文件
  282. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  283. {
  284. //打开文件
  285. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  286. string sLine = "";
  287. ArrayList array_CfgInfo = new ArrayList();
  288. array_CfgInfo.Clear();
  289. while (sLine != null)
  290. {
  291. sLine = objReader.ReadLine();
  292. array_CfgInfo.Add(sLine);
  293. }
  294. objReader.Close();
  295. //解析配置文件
  296. try
  297. {
  298. //Port Set
  299. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  300. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  301. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  302. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  303. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  304. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  305. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  306. //Option
  307. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  308. 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
  309. 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
  310. if (array_CfgInfo[9].ToString().Split(':')[1] == "False")
  311. {
  312. checkBox_OffLineFacMode.Checked = false;
  313. checkBox_OffLineFacMode.Enabled = false;
  314. checkBox_OffLineCheckMode.Checked = false;
  315. checkBox_OffLineCheckMode.Enabled = false;
  316. }
  317. else
  318. {
  319. checkBox_OffLineFacMode.Checked = true;
  320. checkBox_OffLineFacMode.Enabled = true;
  321. checkBox_OffLineCheckMode.Checked = true;
  322. checkBox_OffLineCheckMode.Enabled = true;
  323. }
  324. //Server Set
  325. toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
  326. toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
  327. toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
  328. toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
  329. toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
  330. //MacInfo
  331. toolStripTextBox_MAC.Text = array_CfgInfo[19].ToString().Split(':')[1];
  332. toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
  333. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  334. toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
  335. //Log Address
  336. textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
  337. textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
  338. //电机类型
  339. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[29].ToString().Split(':')[1] == "True");
  340. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  341. //检测阈值
  342. toolStripTextBox_ThVol.Text = array_CfgInfo[33].ToString().Split(':')[1];
  343. toolStripTextBox_ThCur.Text = array_CfgInfo[34].ToString().Split(':')[1];
  344. toolStripTextBox_ThSpeed.Text = array_CfgInfo[35].ToString().Split(':')[1];
  345. toolStripTextBox_ThTor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  346. toolStripTextBox_ThCad.Text = array_CfgInfo[37].ToString().Split(':')[1];
  347. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[38].ToString().Split(':')[1];
  348. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[39].ToString().Split(':')[1];
  349. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[40].ToString().Split(':')[1];
  350. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[41].ToString().Split(':')[1];
  351. //MOS内阻校准系数
  352. toolStripTextBox_MosCalK.Text = array_CfgInfo[44].ToString().Split(':')[1];
  353. toolStripTextBox_MOS1.Text= array_CfgInfo[45].ToString().Split(':')[1];
  354. toolStripTextBox_MOS2.Text = array_CfgInfo[46].ToString().Split(':')[1];
  355. toolStripTextBox_MOS3.Text = array_CfgInfo[47].ToString().Split(':')[1];
  356. //通信协议类型
  357. cANToolStripMenuItem.Checked = (array_CfgInfo[50].ToString().Split(':')[1] == "True");
  358. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  359. //自动更新开关
  360. 打开ToolStripMenuItem.Checked = (array_CfgInfo[54].ToString().Split(':')[1] == "True");
  361. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  362. }
  363. catch (System.Exception)
  364. {
  365. timer_1s.Enabled = false;
  366. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  367. timer_1s.Enabled = true;
  368. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  369. }
  370. }
  371. else //不存在配置文件,生成文件写入默认值
  372. {
  373. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  374. }
  375. //解析本地流水号记录
  376. do
  377. {
  378. //测试模式
  379. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  380. //检验模式
  381. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  382. } while (false);
  383. //获取本机信息,读取时间较长,优先从本地文件获取
  384. do
  385. {
  386. try
  387. {
  388. //本地文件为空,读取信息保存
  389. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  390. {
  391. Local_HdInformation = "";
  392. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  393. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  394. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  395. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  396. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  397. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  398. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  399. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  400. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  401. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  402. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  403. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  404. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  405. }
  406. //从本地读取,计算机名和IP地址重新读
  407. else
  408. {
  409. Local_HdInformation = "";
  410. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  411. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  412. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  413. for (int i = 0; i < fileInfo.Length; i++)
  414. Local_HdInformation += fileInfo[i] + "\r\n";
  415. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  416. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  417. }
  418. }
  419. catch(Exception)
  420. {
  421. }
  422. } while (false);
  423. //系统登录
  424. do
  425. {
  426. EnterForm1.ShowDialog();
  427. try
  428. {
  429. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  430. {
  431. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  432. {
  433. //隐藏设置项
  434. 其它配置项ToolStripMenuItem.Visible = false;
  435. 写入存储ToolStripMenuItem.Visible = false;
  436. 离线使用ToolStripMenuItem.Visible = false;
  437. 服务器配置ToolStripMenuItem.Visible = false;
  438. 判断阈值ToolStripMenuItem.Visible = false;
  439. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  440. mOS内阻范围ToolStripMenuItem.Visible = false;
  441. 力矩传感器检验ToolStripMenuItem.Visible = false;
  442. //显示生产信息
  443. 生产信息ToolStripMenuItem.Visible = true;
  444. //显示电机类型,但不可编辑
  445. 电机类型ToolStripMenuItem.Visible = true;
  446. 中置电机ToolStripMenuItem.Enabled = false;
  447. 轮毂电机ToolStripMenuItem.Enabled = false;
  448. if (uARTToolStripMenuItem.Checked)
  449. UART协议ToolStripMenuItem.Visible = true;
  450. //隐藏研发调试界面
  451. tabPage_MotorParam.Parent = null;
  452. tabPage_BikeParam.Parent = null;
  453. tabPage_BikeParam2.Parent = null;
  454. tabPage_ControlParam.Parent = null;
  455. tabPage_SensorParam.Parent = null;
  456. tabPage_AssistParam.Parent = null;
  457. tabPage_UsrRideParam.Parent = null;
  458. tabPage_DebugParam.Parent = null;
  459. tabPage_RecordInfo.Parent = null;
  460. tabPage_OtherInfo.Parent = null;
  461. tabPage_OBC.Parent = null;
  462. tabPage_RAMorFLASH.Parent = null;
  463. tabPage_FactoryMode.Parent = null;
  464. tabPage_DebugInfo.Parent = null;
  465. //显示运行信息
  466. tabPage_RunInfo.Parent = tabControl2;
  467. //根据电机类型修改生产信息和电机类型
  468. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  469. {
  470. 中置电机ToolStripMenuItem.Checked = true;
  471. 轮毂电机ToolStripMenuItem.Checked = false;
  472. toolStripTextBox_MACPD.Text = "MM_MC1";
  473. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  474. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  475. }
  476. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  477. {
  478. 中置电机ToolStripMenuItem.Checked = false;
  479. 轮毂电机ToolStripMenuItem.Checked = true;
  480. toolStripTextBox_MACPD.Text = "GF_250_1";
  481. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  482. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  483. }
  484. //显示对应生产测试界面
  485. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  486. {
  487. tabPage_ProductMode_Write.Parent = tabControl1;
  488. tabPage_ProductMode_Write.Select();
  489. tabPage_ProductMode_Read.Parent = null;
  490. }
  491. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  492. {
  493. tabPage_ProductMode_Read.Parent = tabControl1;
  494. tabPage_ProductMode_Read.Select();
  495. tabPage_ProductMode_Write.Parent = null;
  496. }
  497. //应答指令不提示
  498. ACK_DisFlag = false;
  499. //退出登录
  500. break;
  501. }
  502. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  503. {
  504. //隐藏工作台内容,新建窗口完成配置
  505. groupBox1.Visible = false;
  506. groupBox3.Visible = false;
  507. tabControl2.Visible = false;
  508. //隐藏提示信息
  509. label_StarInfo.Visible = false;
  510. //打开参数配置框
  511. GenerateParamsForm.ShowDialog();
  512. System.Environment.Exit(0);
  513. //退出登录
  514. break;
  515. }
  516. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  517. {
  518. //隐藏量产界面
  519. tabPage_ProductMode_Read.Parent = null;
  520. tabPage_ProductMode_Write.Parent = null;
  521. //隐藏配置项
  522. 其它配置项ToolStripMenuItem.Visible = false;
  523. 离线使用ToolStripMenuItem.Visible = false;
  524. 服务器配置ToolStripMenuItem.Visible = false;
  525. 判断阈值ToolStripMenuItem.Visible = false;
  526. 力矩传感器检验ToolStripMenuItem.Visible = false;
  527. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  528. mOS内阻范围ToolStripMenuItem.Visible = false;
  529. //显示生产信息
  530. 生产信息ToolStripMenuItem.Visible = true;
  531. //显示电机类型,但不可编辑
  532. 电机类型ToolStripMenuItem.Visible = true;
  533. 中置电机ToolStripMenuItem.Enabled = true;
  534. 轮毂电机ToolStripMenuItem.Enabled = true;
  535. if (uARTToolStripMenuItem.Checked)
  536. UART协议ToolStripMenuItem.Visible = true;
  537. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  538. {
  539. 中置电机ToolStripMenuItem.Checked = true;
  540. 轮毂电机ToolStripMenuItem.Checked = false;
  541. toolStripTextBox_MACPD.Text = "MM_MC1";
  542. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  543. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  544. }
  545. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  546. {
  547. 中置电机ToolStripMenuItem.Checked = false;
  548. 轮毂电机ToolStripMenuItem.Checked = true;
  549. toolStripTextBox_MACPD.Text = "GF_250_1";
  550. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  551. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  552. }
  553. //退出登录
  554. break;
  555. }
  556. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  557. {
  558. //隐藏设置项
  559. 其它配置项ToolStripMenuItem.Visible = false;
  560. 写入存储ToolStripMenuItem.Visible = false;
  561. 离线使用ToolStripMenuItem.Visible = false;
  562. 服务器配置ToolStripMenuItem.Visible = false;
  563. 判断阈值ToolStripMenuItem.Visible = false;
  564. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  565. mOS内阻范围ToolStripMenuItem.Visible = false;
  566. 力矩传感器检验ToolStripMenuItem.Visible = false;
  567. //显示生产信息
  568. 生产信息ToolStripMenuItem.Visible = true;
  569. //显示电机类型,但不可编辑
  570. 电机类型ToolStripMenuItem.Visible = false;
  571. 中置电机ToolStripMenuItem.Enabled = false;
  572. 轮毂电机ToolStripMenuItem.Enabled = false;
  573. if (uARTToolStripMenuItem.Checked)
  574. UART协议ToolStripMenuItem.Visible = true;
  575. //隐藏研发调试界面
  576. tabPage_MotorParam.Parent = null;
  577. tabPage_BikeParam.Parent = null;
  578. tabPage_BikeParam2.Parent = null;
  579. tabPage_ControlParam.Parent = null;
  580. tabPage_SensorParam.Parent = null;
  581. tabPage_AssistParam.Parent = null;
  582. tabPage_UsrRideParam.Parent = null;
  583. tabPage_DebugParam.Parent = null;
  584. tabPage_RecordInfo.Parent = null;
  585. tabPage_OtherInfo.Parent = null;
  586. tabPage_OBC.Parent = null;
  587. tabPage_RAMorFLASH.Parent = null;
  588. tabPage_FactoryMode.Parent = null;
  589. tabPage_DebugInfo.Parent = null;
  590. //显示运行信息
  591. tabPage_RunInfo.Parent = tabControl2;
  592. //目前仅轮毂使用
  593. 中置电机ToolStripMenuItem.Checked = false;
  594. 轮毂电机ToolStripMenuItem.Checked = true;
  595. toolStripTextBox_MACPD.Text = "GF_250_1";
  596. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  597. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  598. //显示量产测试界面
  599. tabPage_ProductMode_Write.Parent = tabControl1;
  600. tabPage_ProductMode_Write.Select();
  601. tabPage_ProductMode_Read.Parent = null;
  602. //允许离线使用
  603. 允许ToolStripMenuItem.Checked = false;
  604. 不允许ToolStripMenuItem.Checked = true;
  605. checkBox_OffLineFacMode.Checked = false;
  606. checkBox_OffLineFacMode.Enabled = true;
  607. checkBox_OffLineCheckMode.Checked = false;
  608. checkBox_OffLineCheckMode.Enabled = true;
  609. //应答指令不提示
  610. ACK_DisFlag = false;
  611. //退出登录
  612. break;
  613. }
  614. else if (EnterForm1.comboBox_User.Text == "研发调试")
  615. {
  616. //隐藏量产界面
  617. tabPage_ProductMode_Read.Parent = null;
  618. tabPage_ProductMode_Write.Parent = null;
  619. 服务器配置ToolStripMenuItem.Visible = false;
  620. if (uARTToolStripMenuItem.Checked)
  621. UART协议ToolStripMenuItem.Visible = true;
  622. //退出登录
  623. break;
  624. }
  625. else if (EnterForm1.comboBox_User.Text == "管理员")
  626. {
  627. //不隐藏任何界面
  628. //...
  629. //退出登录
  630. break;
  631. }
  632. else
  633. {
  634. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  635. //重新登录
  636. continue;
  637. }
  638. }
  639. else
  640. {
  641. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  642. //重新登录
  643. continue;
  644. }
  645. }
  646. catch (Exception)
  647. {
  648. System.Environment.Exit(0);
  649. }
  650. } while (true);
  651. //配置网络FTP服务器
  652. myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text, "admin", "ttium_admin");
  653. //创建线程,定时检测网络连接状态
  654. Thread th = new Thread(NetworkCheck);
  655. th.IsBackground = true;
  656. th.Start();
  657. //允许跨线程访问
  658. Control.CheckForIllegalCrossThreadCalls = false;
  659. }
  660. /// <summary>
  661. /// 检查网络状态线程
  662. /// </summary>
  663. private void NetworkCheck()
  664. {
  665. //允许离线使用,直接退出
  666. if (允许ToolStripMenuItem.Checked == true) //允许离线使用
  667. {
  668. timer_1s.Enabled = false;
  669. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  670. timer_1s.Enabled = true;
  671. return;
  672. }
  673. //不允许离线使用,实时监测网络状态
  674. else
  675. {
  676. //初始化第一次连接FTP服务器
  677. bool Result = myFtp.CheckFtp();
  678. if (Result == true)//服务器连接成功
  679. {
  680. myFtp.IsNetConnected = true;
  681. //上传登录日志
  682. do
  683. {
  684. //日志文件名
  685. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  686. string fileName = date;
  687. //日志内容
  688. string fileInfo = Local_HdInformation;
  689. //保存本地
  690. if (!Directory.Exists(localInfo.LocalLogPath))
  691. Directory.CreateDirectory(localInfo.LocalLogPath);
  692. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  693. //上传服务器
  694. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  695. } while (false);
  696. }
  697. else//服务器连接失败
  698. {
  699. myFtp.IsNetConnected = false;
  700. if (EnterForm1.comboBox_User.Text != "管理员")
  701. {
  702. timer_1s.Enabled = false;
  703. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  704. timer_1s.Enabled = true;
  705. this.Close();
  706. }
  707. }
  708. //创建定时器,定时10s检查网络
  709. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  710. timer_CheckNet.Enabled = true;
  711. timer_CheckNet.Interval = 30000;
  712. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  713. timer_CheckNet.Start();
  714. while (true)
  715. {
  716. Thread.Sleep(1);
  717. if (myFtp.IsNetConnected == false)
  718. {
  719. label_Server_ComStatus.Text = "网络已断开";
  720. label_ServerStatus.BackColor = Color.Red;
  721. }
  722. else
  723. {
  724. label_Server_ComStatus.Text = "网络已连接";
  725. label_ServerStatus.BackColor = Color.Green;
  726. }
  727. }
  728. }
  729. }
  730. /// <summary>
  731. /// 线程中定时任务,检查网络状态
  732. /// </summary>
  733. /// <param name="sender"></param>
  734. /// <param name="e"></param>
  735. private void timer_CheckNet_Tick(object sender, EventArgs e)
  736. {
  737. //连接FTP服务器
  738. bool Result = myFtp.CheckFtp();
  739. if (Result == true)//服务器连接成功
  740. {
  741. myFtp.IsNetConnected = true;
  742. //允许使用
  743. groupBox1.Enabled = true;
  744. groupBox3.Enabled = true;
  745. tabControl2.Enabled = true;
  746. }
  747. else//服务器连接失败
  748. {
  749. myFtp.IsNetConnected = false;
  750. if (EnterForm1.comboBox_User.Text != "管理员")
  751. {
  752. timer_1s.Enabled = false;
  753. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  754. timer_1s.Enabled = true;
  755. //禁止使用
  756. groupBox1.Enabled = false;
  757. groupBox3.Enabled = false;
  758. tabControl2.Enabled = false;
  759. }
  760. }
  761. }
  762. #region 非独占性延时函数
  763. public static void Delay_ms(int milliSecond)
  764. {
  765. int start = Environment.TickCount;
  766. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  767. {
  768. Application.DoEvents();
  769. }
  770. }
  771. #endregion
  772. private void MainForm_Load(object sender, System.EventArgs e)
  773. {
  774. //页面初始化
  775. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  776. label_Computername.Text = System.Environment.UserName;
  777. label_UserName.Text = EnterForm1.comboBox_User.Text;
  778. this.Text += Version;
  779. //检查版本,自动更新
  780. do
  781. {
  782. if (打开ToolStripMenuItem.Checked == false)//关闭自动更新
  783. {
  784. break;
  785. }
  786. //检查网络状态
  787. if (myFtp.CheckFtp() == false)
  788. {
  789. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  790. break;
  791. }
  792. else
  793. {
  794. //检查本地文件删除
  795. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  796. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  797. //读取最新版本号
  798. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  799. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  800. string sLine = "";
  801. ArrayList arrText = new ArrayList();//创建一个动态数组
  802. while (sLine != null)
  803. {
  804. sLine = objReader.ReadLine();
  805. arrText.Add(sLine);
  806. }
  807. objReader.Close();
  808. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  809. //检查是否有最新版本
  810. string[] VerOld = mainForm.Version.Trim().Split('.');
  811. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  812. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  813. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  814. if (VerNew_int <= VerOld_int)
  815. {
  816. //版本已是最新,跳出
  817. break;
  818. }
  819. //确认下载最新版本
  820. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  821. {
  822. string SavePath = Directory.GetCurrentDirectory();
  823. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  824. foreach (string file in FileList)
  825. {
  826. if (file.Contains(".exe"))
  827. {
  828. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  829. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  830. System.Environment.Exit(0);
  831. }
  832. }
  833. }
  834. }
  835. } while (false);
  836. //下拉控件初始值设定
  837. comboBox_WorkMode.SelectedIndex = 0;
  838. comboBox_GearSt.SelectedIndex = 0;
  839. comboBox_LightSwitch.SelectedIndex = 1;
  840. comboBox_OBC_SetGearST.SelectedIndex = 0;
  841. comboBox_OBC_LightSw.SelectedIndex = 1;
  842. comboBox_AssistTorque.SelectedIndex = 0;
  843. comboBox_AssistCadence.SelectedIndex = 0;
  844. //combobox事件定义
  845. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  846. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  847. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  848. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  849. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  850. //端口自动连接
  851. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  852. {
  853. try
  854. {
  855. PortConnect();
  856. }
  857. catch (System.Exception)
  858. {
  859. timer_1s.Enabled = false;
  860. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  861. timer_1s.Enabled = true;
  862. }
  863. }
  864. //不识别联动装置盒自动打开界面
  865. #if true
  866. groupBox1.Visible = true;
  867. groupBox3.Visible = true;
  868. tabControl2.Visible = true;
  869. label_StarInfo.Visible = false;
  870. #endif
  871. //创建线程,定时解析数据
  872. Thread th = new Thread(Task_SerialProcess);
  873. th.IsBackground = true;
  874. th.Start();
  875. }
  876. #region 结构体与字节流相互转换
  877. public static class MyConverter
  878. {
  879. /// <summary>
  880. /// 由结构体转换为byte数组
  881. /// </summary>
  882. public static byte[] StructureToByte<T>(T structure)
  883. {
  884. int size = Marshal.SizeOf(typeof(T));
  885. byte[] buffer = new byte[size];
  886. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  887. try
  888. {
  889. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  890. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  891. }
  892. finally
  893. {
  894. Marshal.FreeHGlobal(bufferIntPtr);
  895. }
  896. return buffer;
  897. }
  898. /// <summary>
  899. /// 由byte数组转换为结构体
  900. /// </summary>
  901. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  902. {
  903. object structure = null;
  904. int size = Marshal.SizeOf(typeof(T));
  905. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  906. try
  907. {
  908. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  909. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  910. }
  911. finally
  912. {
  913. Marshal.FreeHGlobal(allocIntPtr);
  914. }
  915. return (T)structure;
  916. }
  917. }
  918. #endregion
  919. #region 故障日志解析显示
  920. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  921. {
  922. string SaveData = "";
  923. //Log1
  924. if (Log1.Error_Index != 0xFFFF)
  925. {
  926. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  927. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  928. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  929. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  930. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  931. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  932. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  933. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  934. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  935. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  936. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  937. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  938. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  939. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  940. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  941. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  942. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  943. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  944. {
  945. SaveData += "续航:" + "---km" + ", ";
  946. }
  947. else
  948. {
  949. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  950. }
  951. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  952. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  953. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  954. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  955. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  956. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  957. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  958. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  959. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  960. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  961. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  962. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  963. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  964. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  965. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  966. SaveData += "\r\n\r\n";
  967. richTextBox_Record.AppendText(SaveData);
  968. SaveData = "";
  969. }
  970. //Log2
  971. if (Log2.Error_Index != 0xFFFF)
  972. {
  973. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  974. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  975. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  976. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  977. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  978. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  979. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  980. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  981. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  982. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  983. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  984. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  985. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  986. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  987. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  988. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  989. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  990. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  991. {
  992. SaveData += "续航:" + "---km" + ", ";
  993. }
  994. else
  995. {
  996. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  997. }
  998. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  999. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1000. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1001. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1002. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1003. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1004. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1005. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1006. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1007. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1008. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1009. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1010. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1011. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1012. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1013. SaveData += "\r\n\r\n";
  1014. richTextBox_Record.AppendText(SaveData);
  1015. SaveData = "";
  1016. }
  1017. }
  1018. #endregion
  1019. #region 串口数据解析线程
  1020. /// <summary>
  1021. /// 串口数据解析线程
  1022. /// </summary>
  1023. private void Task_SerialProcess()
  1024. {
  1025. //创建定时器,定时读取串口数据
  1026. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1027. timer_ReadSerial.Enabled = true;
  1028. timer_ReadSerial.Interval = 20;
  1029. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1030. timer_ReadSerial.Start();
  1031. while (true)
  1032. {
  1033. Thread.Sleep(1);
  1034. };
  1035. }
  1036. /// <summary>
  1037. /// 串口解析定时器
  1038. /// </summary>
  1039. /// <param name="sender"></param>
  1040. /// <param name="e"></param>
  1041. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1042. {
  1043. //串口解析
  1044. Serial_process(mySerialProcess.buffer);
  1045. }
  1046. #endregion
  1047. #region 数据解析
  1048. public void Serial_process(List<byte> buffer)
  1049. {
  1050. byte DataNum = 0; //记录每条命令数据段的长度
  1051. ushort PackageID, Cmd;
  1052. byte[] Data = new byte[1024];
  1053. try
  1054. {
  1055. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1056. {
  1057. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1058. {
  1059. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1060. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1061. {
  1062. int CmdLen = buffer[5];
  1063. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1064. while (CmdLen > 0) //读取命令段
  1065. {
  1066. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1067. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1068. if (DataNum <= (CmdLen - 2))
  1069. {
  1070. for (int i = 0; i < DataNum; i++)
  1071. {
  1072. Data[i] = buffer[i + 8];
  1073. }
  1074. // 串口接收的数据 显示在子窗口
  1075. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1076. {
  1077. string strTemp = String.Empty;
  1078. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1079. for (int i = 0; i < CmdLen + 11; i++)
  1080. {
  1081. strTemp += (buffer[i].ToString("X2") + " ");
  1082. }
  1083. strTemp += "\n";
  1084. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1085. }
  1086. buffer.RemoveRange(0, CmdLen + 11);
  1087. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1088. DataRevToString(Cmd, Data);//指令数据转为字符串
  1089. }
  1090. }
  1091. }
  1092. else
  1093. {
  1094. buffer.RemoveAt(0);//ID不对
  1095. }
  1096. }
  1097. else
  1098. {
  1099. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1100. }
  1101. }
  1102. }
  1103. catch (Exception)
  1104. {
  1105. }
  1106. }
  1107. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1108. {
  1109. int DataTemp;
  1110. ushort uData16;
  1111. unchecked
  1112. {
  1113. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1114. }
  1115. #region 解析发送给CDL的指令
  1116. if (ID == 0x7FF)
  1117. {
  1118. switch (CmdTemp)
  1119. {
  1120. case 0x1100://
  1121. {
  1122. unchecked
  1123. {
  1124. this.Invoke((EventHandler)(delegate
  1125. {
  1126. //CDL连接成功
  1127. mySerialProcess.CDL_Online_Flag = true;
  1128. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1129. groupBox1.Visible = true;
  1130. groupBox3.Visible = true;
  1131. tabControl2.Visible = true;
  1132. label_StarInfo.Visible = false;
  1133. }));
  1134. }
  1135. break;
  1136. }
  1137. default: break;
  1138. }
  1139. }
  1140. #endregion
  1141. #region 解析电机的命令
  1142. else if ((ID == 0x715) || (ID == 0x710))
  1143. {
  1144. switch (CmdTemp)
  1145. {
  1146. case 0x1020://电机运行信息
  1147. {
  1148. unchecked
  1149. {
  1150. this.Invoke((EventHandler)(delegate
  1151. {
  1152. MC_RunInfo_Refresh = true;
  1153. //车速
  1154. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1155. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1156. //输出转速
  1157. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1158. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1159. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1160. Class_MotorSpeed.Data = DataTemp;
  1161. //电功率
  1162. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1163. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1164. //母线电压
  1165. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1166. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1167. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1168. //母线电流
  1169. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1170. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1171. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1172. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1173. Class_CurrentData.Data = DataTemp;
  1174. //踏频
  1175. DataTemp = (ushort)(Data[10]);
  1176. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1177. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1178. Class_CadenceData.Data = DataTemp;
  1179. //踩踏力矩
  1180. DataTemp = (ushort)(Data[11]);
  1181. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1182. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1183. Class_TorqueData.Data = DataTemp;
  1184. //踩踏方向
  1185. DataTemp = (ushort)(Data[12]);
  1186. if (DataTemp == 0)
  1187. {
  1188. textBox_RunInfo_Dir.Text = "正向";
  1189. }
  1190. else if (DataTemp == 1)
  1191. {
  1192. textBox_RunInfo_Dir.Text = "反向";
  1193. }
  1194. else if (DataTemp == 2)
  1195. {
  1196. textBox_RunInfo_Dir.Text = "停止";
  1197. }
  1198. //助力档位
  1199. DataTemp = (ushort)(Data[13]);
  1200. if (DataTemp == 0x33)
  1201. {
  1202. textBox_RunInfo_GearSt.Text = "SMART";
  1203. //comboBox_GearSt.SelectedIndex = 5;
  1204. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1205. }
  1206. else if (DataTemp == 0x22)
  1207. {
  1208. textBox_RunInfo_GearSt.Text = "WALK";
  1209. //comboBox_GearSt.SelectedIndex = 6;
  1210. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1211. }
  1212. else
  1213. {
  1214. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1215. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1216. //comboBox_GearSt.SelectedIndex = DataTemp;
  1217. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1218. }
  1219. //大灯状态
  1220. DataTemp = (ushort)(Data[14]);
  1221. if (DataTemp == 0xF0)
  1222. {
  1223. textBox_RunInfo_LightSwitch.Text = "OFF";
  1224. //comboBox_LightSwitch.SelectedIndex = 1;
  1225. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1226. }
  1227. else if (DataTemp == 0xF1)
  1228. {
  1229. textBox_RunInfo_LightSwitch.Text = "ON";
  1230. //comboBox_LightSwitch.SelectedIndex = 0;
  1231. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1232. }
  1233. //剩余电量
  1234. DataTemp = (ushort)(Data[15]);
  1235. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1236. //剩余续航里程
  1237. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1238. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1239. {
  1240. textBox_RunInfo_Range.Text = "---";
  1241. }
  1242. else
  1243. {
  1244. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1245. }
  1246. //预留(显示力矩Reg),空2bytes
  1247. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1248. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1249. //平均功耗
  1250. DataTemp = (ushort)(Data[20]);
  1251. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1252. //PCB温度
  1253. DataTemp = (ushort)(Data[21]);
  1254. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1255. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1256. Class_MotorTemp.Data = DataTemp - 40;
  1257. //绕组温度
  1258. DataTemp = (ushort)(Data[22]);
  1259. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1260. //MCU温度
  1261. DataTemp = (ushort)(Data[23]);
  1262. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1263. //单次里程
  1264. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1265. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1266. //单次时间
  1267. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1268. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1269. //数据保存
  1270. RunInfoAutoSave();
  1271. }));
  1272. }
  1273. break;
  1274. }
  1275. case 0x1104://故障码
  1276. {
  1277. unchecked
  1278. {
  1279. this.Invoke((EventHandler)(delegate
  1280. {
  1281. MC_ErrorCode_Refresh = true;
  1282. textBox_ErrorCode.Text =
  1283. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1284. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1285. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1286. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1287. "H";
  1288. }));
  1289. }
  1290. break;
  1291. }
  1292. case 0xA903://反馈指令
  1293. {
  1294. unchecked
  1295. {
  1296. this.Invoke((EventHandler)(delegate
  1297. {
  1298. if (ACK_DisFlag == true)
  1299. {
  1300. timer_1s.Enabled = false;
  1301. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1302. timer_1s.Enabled = true;
  1303. //关机反馈
  1304. PowerOffAckStatus = true;
  1305. }
  1306. //应答标志置位
  1307. WriteACK = true;
  1308. WriteCnt++;
  1309. }));
  1310. }
  1311. break;
  1312. }
  1313. case 0xB226://马达参数
  1314. {
  1315. unchecked
  1316. {
  1317. this.Invoke((EventHandler)(delegate
  1318. {
  1319. richTextBox_MotorParam.Clear();
  1320. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1321. {
  1322. if (i == 6)
  1323. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1324. else
  1325. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1326. }
  1327. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1328. }));
  1329. }
  1330. break;
  1331. }
  1332. case 0xB31A://整车信息
  1333. {
  1334. unchecked
  1335. {
  1336. this.Invoke((EventHandler)(delegate
  1337. {
  1338. richTextBox_BikeParam.Clear();
  1339. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1340. {
  1341. if (i == 9)
  1342. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1343. else
  1344. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1345. //更新前后灯参数
  1346. if (i == 8)
  1347. {
  1348. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1349. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1350. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1351. }
  1352. //更新开关机参数
  1353. else if (i == 11)
  1354. {
  1355. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1356. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1357. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1358. }
  1359. }
  1360. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1361. }));
  1362. }
  1363. break;
  1364. }
  1365. case 0xB420://控制器参数
  1366. {
  1367. unchecked
  1368. {
  1369. this.Invoke((EventHandler)(delegate
  1370. {
  1371. richTextBox_ControlParam.Clear();
  1372. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1373. {
  1374. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1375. //转把定速巡航
  1376. if (i == 13)
  1377. {
  1378. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1379. }
  1380. }
  1381. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1382. }));
  1383. }
  1384. break;
  1385. }
  1386. case 0xB528://传感器参数
  1387. {
  1388. unchecked
  1389. {
  1390. this.Invoke((EventHandler)(delegate
  1391. {
  1392. richTextBox_SensorParam.Clear();
  1393. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1394. {
  1395. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1396. }
  1397. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1398. //更新生产模式页面传感器零点和标定值
  1399. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1400. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1401. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1402. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1403. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1404. }));
  1405. }
  1406. break;
  1407. }
  1408. case 0xB64C://助力参数
  1409. {
  1410. unchecked
  1411. {
  1412. this.Invoke((EventHandler)(delegate
  1413. {
  1414. richTextBox_AssistParam.Clear();
  1415. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1416. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1417. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1418. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1419. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1420. {
  1421. if (i < index_1) //数据占用2bytes
  1422. {
  1423. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1424. }
  1425. else if (i <= index_2) //数据占用4bytes
  1426. {
  1427. 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])) + ", ");
  1428. }
  1429. else if (i < index_3) //数据占用2bytes,无符号
  1430. {
  1431. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1432. }
  1433. else if (i <= index_4) //数据占用2bytes,有符号
  1434. {
  1435. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1436. }
  1437. else //数据占用2bytes,无符号
  1438. {
  1439. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1440. }
  1441. }
  1442. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1443. }));
  1444. }
  1445. break;
  1446. }
  1447. case 0xB74C://历史记录
  1448. {
  1449. unchecked
  1450. {
  1451. this.Invoke((EventHandler)(delegate
  1452. {
  1453. richTextBox_Record.Clear();
  1454. for (int i = 0; i < myParams.Record.Count; i++)
  1455. {
  1456. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1457. }
  1458. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1459. }));
  1460. }
  1461. break;
  1462. }
  1463. case 0xB83A://调试参数
  1464. {
  1465. unchecked
  1466. {
  1467. this.Invoke((EventHandler)(delegate
  1468. {
  1469. richTextBox_DebugParam.Clear();
  1470. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1471. {
  1472. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1473. }
  1474. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1475. }));
  1476. }
  1477. break;
  1478. }
  1479. case 0xB904://存储标志
  1480. {
  1481. unchecked
  1482. {
  1483. this.Invoke((EventHandler)(delegate
  1484. {
  1485. ushort Flag = 0;
  1486. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1487. if (Flag == 0)
  1488. {
  1489. radioButton_EE_SaveNo.Checked = true;
  1490. radioButton_EE_SaveYes.Checked = false;
  1491. }
  1492. else
  1493. {
  1494. radioButton_EE_SaveNo.Checked = false;
  1495. radioButton_EE_SaveYes.Checked = true;
  1496. }
  1497. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1498. if (Flag == 0)
  1499. {
  1500. radioButton_SIP_SaveNo.Checked = true;
  1501. radioButton_SIP_SaveYes.Checked = false;
  1502. }
  1503. else
  1504. {
  1505. radioButton_SIP_SaveNo.Checked = false;
  1506. radioButton_SIP_SaveYes.Checked = true;
  1507. }
  1508. }));
  1509. }
  1510. break;
  1511. }
  1512. case 0x1240://电机版本信息
  1513. {
  1514. unchecked
  1515. {
  1516. this.Invoke((EventHandler)(delegate
  1517. {
  1518. //电机型号
  1519. textBox_Model.Text = "";
  1520. textBox_OBC_ReadModel.Text = "";
  1521. textBox_FacModeName.Text = "";
  1522. for (ushort i = 0; i < 16; i++)
  1523. {
  1524. if (Data[i] == 0x2E)
  1525. {
  1526. break;
  1527. }
  1528. textBox_Model.Text += ((char)Data[i]).ToString();
  1529. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1530. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1531. }
  1532. Class_Motor_Ver.Mode = textBox_Model.Text;
  1533. //电机SN
  1534. textBox_SN.Text = "";
  1535. textBox_OBC_ReadSN.Text = "";
  1536. textBox_FacModeNum.Text = "";
  1537. for (ushort i = 0; i < 16; i++)
  1538. {
  1539. if (Data[16 + i] == 0x2E)
  1540. {
  1541. break;
  1542. }
  1543. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1544. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1545. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1546. }
  1547. Class_Motor_Ver.SN = textBox_SN.Text;
  1548. //电机HW
  1549. textBox_HW.Text = "";
  1550. textBox_OBC_ReadHW.Text = "";
  1551. textBox_FacModeHW.Text = "";
  1552. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1553. {
  1554. if (Data[32 + i] == 0x2E)
  1555. {
  1556. break;
  1557. }
  1558. else if (Data[32 + i] == 'r')
  1559. {
  1560. Data[32 + i] = (byte)'.';
  1561. break;
  1562. }
  1563. string strTemp = "";
  1564. strTemp = ((char)Data[32 + i]).ToString();
  1565. textBox_HW.Text += strTemp;
  1566. textBox_OBC_ReadHW.Text += strTemp;
  1567. textBox_FacModeHW.Text += strTemp;
  1568. }
  1569. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1570. {
  1571. if (Data[40 + i] == 0x2E)
  1572. {
  1573. break;
  1574. }
  1575. else if (Data[40 + i] == 'r')
  1576. {
  1577. Data[40 + i] = (byte)'.';
  1578. break;
  1579. }
  1580. string strTemp = "";
  1581. strTemp = ((char)Data[40 + i]).ToString();
  1582. textBox_HW.Text += strTemp;
  1583. textBox_OBC_ReadHW.Text += strTemp;
  1584. textBox_FacModeHW.Text += strTemp;
  1585. }
  1586. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1587. {
  1588. string strTemp = "";
  1589. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1590. textBox_HW.Text += strTemp;
  1591. textBox_OBC_ReadHW.Text += strTemp;
  1592. textBox_FacModeHW.Text += strTemp;
  1593. }
  1594. Class_Motor_Ver.HW = textBox_HW.Text;
  1595. //电机FW
  1596. textBox_FW.Text = "";
  1597. textBox_OBC_ReadFW.Text = "";
  1598. textBox_FacModeFW.Text = "";
  1599. for (ushort i = 0; i < 16; i++)
  1600. {
  1601. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1602. {
  1603. break;
  1604. }
  1605. if (Data[48 + i] == 'r')
  1606. {
  1607. Data[48 + i] = (byte)'.';
  1608. }
  1609. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1610. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1611. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1612. }
  1613. Class_Motor_Ver.FW = textBox_FW.Text;
  1614. }));
  1615. }
  1616. break;
  1617. }
  1618. case 0xA610://自定义1
  1619. {
  1620. unchecked
  1621. {
  1622. this.Invoke((EventHandler)(delegate
  1623. {
  1624. textBox_User1.Text = "";
  1625. for (ushort i = 0; i < 16; i++)
  1626. {
  1627. if (Data[i] == 0x2E)
  1628. {
  1629. break;
  1630. }
  1631. textBox_User1.Text += ((char)Data[i]).ToString();
  1632. }
  1633. }));
  1634. }
  1635. break;
  1636. }
  1637. case 0xA710://自定义2
  1638. {
  1639. unchecked
  1640. {
  1641. this.Invoke((EventHandler)(delegate
  1642. {
  1643. textBox_User2.Text = "";
  1644. for (ushort i = 0; i < 16; i++)
  1645. {
  1646. if (Data[i] == 0x2E)
  1647. {
  1648. break;
  1649. }
  1650. textBox_User2.Text += ((char)Data[i]).ToString();
  1651. }
  1652. }));
  1653. }
  1654. break;
  1655. }
  1656. case 0xA810://自定义1
  1657. {
  1658. unchecked
  1659. {
  1660. this.Invoke((EventHandler)(delegate
  1661. {
  1662. textBox_User3.Text = "";
  1663. for (ushort i = 0; i < 16; i++)
  1664. {
  1665. if (Data[i] == 0x2E)
  1666. {
  1667. break;
  1668. }
  1669. textBox_User3.Text += ((char)Data[i]).ToString();
  1670. }
  1671. }));
  1672. }
  1673. break;
  1674. }
  1675. case 0xA520://生产信息
  1676. {
  1677. unchecked
  1678. {
  1679. this.Invoke((EventHandler)(delegate
  1680. {
  1681. //生产商
  1682. textBox_MAC.Text = "";
  1683. for (ushort i = 0; i < 8; i++)
  1684. {
  1685. if (Data[i] == 0x2E)
  1686. {
  1687. break;
  1688. }
  1689. textBox_MAC.Text += ((char)Data[i]).ToString();
  1690. }
  1691. //生产地
  1692. textBox_MACAdd.Text = "";
  1693. for (ushort i = 0; i < 8; i++)
  1694. {
  1695. if (Data[8 + i] == 0x2E)
  1696. {
  1697. break;
  1698. }
  1699. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1700. }
  1701. //生产日期
  1702. textBox_MACDate.Text = "";
  1703. for (ushort i = 0; i < 8; i++)
  1704. {
  1705. if (Data[16 + i] == 0x2E)
  1706. {
  1707. break;
  1708. }
  1709. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1710. }
  1711. //品牌信息
  1712. textBox_PP.Text = "";
  1713. for (ushort i = 0; i < 8; i++)
  1714. {
  1715. if (Data[24 + i] == 0x2E)
  1716. {
  1717. break;
  1718. }
  1719. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1720. }
  1721. }));
  1722. }
  1723. break;
  1724. }
  1725. case 0xA408://密钥
  1726. {
  1727. unchecked
  1728. {
  1729. this.Invoke((EventHandler)(delegate
  1730. {
  1731. textBox_Key.Text = "";
  1732. for (ushort i = 0; i < 8; i++)
  1733. {
  1734. textBox_Key.Text += ((char)Data[i]).ToString();
  1735. }
  1736. }));
  1737. }
  1738. break;
  1739. }
  1740. case 0xAB09://存储器数据
  1741. case 0xAB0A:
  1742. case 0xAB0B:
  1743. case 0xAB0C:
  1744. {
  1745. unchecked
  1746. {
  1747. this.Invoke((EventHandler)(delegate
  1748. {
  1749. long ByteNum = 0;
  1750. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1751. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1752. {
  1753. for (int i = 0; i < ByteNum; i++)
  1754. {
  1755. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1756. }
  1757. }
  1758. else //根据设置自动转换10进制显示
  1759. {
  1760. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1761. {
  1762. switch (ByteNum)
  1763. {
  1764. case 1:
  1765. {
  1766. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1767. break;
  1768. }
  1769. case 2:
  1770. {
  1771. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1772. break;
  1773. }
  1774. case 3:
  1775. {
  1776. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1777. break;
  1778. }
  1779. case 4:
  1780. {
  1781. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1782. break;
  1783. }
  1784. default:
  1785. {
  1786. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1787. break;
  1788. }
  1789. }
  1790. }
  1791. else //16进制显示
  1792. {
  1793. switch (ByteNum)
  1794. {
  1795. case 1:
  1796. {
  1797. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1798. break;
  1799. }
  1800. case 2:
  1801. {
  1802. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1803. break;
  1804. }
  1805. case 3:
  1806. {
  1807. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1808. break;
  1809. }
  1810. case 4:
  1811. {
  1812. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1813. break;
  1814. }
  1815. default:
  1816. {
  1817. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1818. break;
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }));
  1824. }
  1825. break;
  1826. }
  1827. case 0xAB88://故障日志
  1828. {
  1829. unchecked
  1830. {
  1831. this.Invoke((EventHandler)(delegate
  1832. {
  1833. //电机存储的故障日志,一包128字节包含2条故障日志
  1834. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1835. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1836. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1837. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1838. //数据显示
  1839. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1840. }));
  1841. }
  1842. break;
  1843. }
  1844. case 0x1401://在线检测结果
  1845. {
  1846. unchecked
  1847. {
  1848. this.Invoke((EventHandler)(delegate
  1849. {
  1850. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1851. }));
  1852. }
  1853. break;
  1854. }
  1855. case 0x1510://骑行历史信息
  1856. {
  1857. unchecked
  1858. {
  1859. this.Invoke((EventHandler)(delegate
  1860. {
  1861. long DataTemp32;
  1862. //ODO里程
  1863. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1864. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1865. textBox_ODO_KM.Text = DataTemp32.ToString();
  1866. //ODO时间
  1867. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1868. if (DataTemp32 >= 60 * 100000)
  1869. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1870. else
  1871. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1872. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1873. //TRIP里程
  1874. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1875. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1876. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1877. //TRIP时间
  1878. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1879. if (DataTemp32 >= 60 * 100000)
  1880. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1881. else
  1882. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1883. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1884. }));
  1885. }
  1886. break;
  1887. }
  1888. case 0x1720://客户信息
  1889. {
  1890. unchecked
  1891. {
  1892. this.Invoke((EventHandler)(delegate
  1893. {
  1894. //软件标识
  1895. textBox_SP.Text = "";
  1896. textBox_OBC_ReadSP.Text = "";
  1897. textBox_FacModeSP.Text = "";
  1898. for (ushort i = 0; i < 23; i++)
  1899. {
  1900. if (Data[i] == 'r')
  1901. {
  1902. Data[i] = (byte)'.';
  1903. }
  1904. textBox_SP.Text += ((char)Data[i]).ToString();
  1905. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1906. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  1907. }
  1908. //Git提交版本信息
  1909. textBox_FacModeGit.Text = "";
  1910. for (ushort i = 0; i < 9; i++)
  1911. {
  1912. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  1913. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  1914. }
  1915. Class_Motor_Ver.Special = textBox_SP.Text;
  1916. }));
  1917. }
  1918. break;
  1919. }
  1920. case 0xBA20: //调试信息
  1921. {
  1922. unchecked
  1923. {
  1924. this.Invoke((EventHandler)(delegate
  1925. {
  1926. MC_DebugInfo_Refresh = true;
  1927. //系统状态机
  1928. DataTemp = (short)(Data[0]);
  1929. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  1930. //二层状态机
  1931. DataTemp = (short)(Data[1]);
  1932. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  1933. //电机状态机
  1934. DataTemp = (short)(Data[2]);
  1935. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  1936. //助力状态机
  1937. DataTemp = (short)(Data[3]);
  1938. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  1939. //IdRef
  1940. DataTemp = (short)(Data[5] * 256 + Data[4]);
  1941. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  1942. //IqRef
  1943. DataTemp = (short)(Data[7] * 256 + Data[6]);
  1944. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  1945. //UdRef
  1946. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1947. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  1948. //UqRef
  1949. DataTemp = (short)(Data[11] * 256 + Data[10]);
  1950. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  1951. //瞬时力矩
  1952. DataTemp = (short)(Data[13] * 256 + Data[12]);
  1953. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  1954. //时间滤波力矩
  1955. DataTemp = (short)(Data[15] * 256 + Data[14]);
  1956. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  1957. //踏频滤波力矩
  1958. DataTemp = (short)(Data[17] * 256 + Data[16]);
  1959. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  1960. //IdFdb
  1961. DataTemp = (short)(Data[19] * 256 + Data[18]);
  1962. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  1963. //IqFdb
  1964. DataTemp = (short)(Data[21] * 256 + Data[20]);
  1965. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  1966. //助力输出
  1967. DataTemp = (short)(Data[23] * 256 + Data[22]);
  1968. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  1969. //数据保存
  1970. RunInfoAutoSave();
  1971. }));
  1972. }
  1973. break;
  1974. }
  1975. case 0xBB20: //产品标签信息
  1976. {
  1977. unchecked
  1978. {
  1979. this.Invoke((EventHandler)(delegate
  1980. {
  1981. //产品标签
  1982. textBox_TagInfo.Text = "";
  1983. for (ushort i = 0; i < 32; i++)
  1984. {
  1985. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  1986. }
  1987. }));
  1988. }
  1989. break;
  1990. }
  1991. case 0xBC20: //内阻校正信息
  1992. {
  1993. unchecked
  1994. {
  1995. this.Invoke((EventHandler)(delegate
  1996. {
  1997. //内阻1
  1998. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1999. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2000. //内阻2
  2001. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2002. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2003. //内阻3
  2004. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2005. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2006. //K1
  2007. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2008. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2009. //K2
  2010. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2011. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2012. //K3
  2013. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2014. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2015. //K4
  2016. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2017. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2018. //K5
  2019. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2020. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2021. }));
  2022. }
  2023. break;
  2024. }
  2025. case 0xBD20: //整车信息2
  2026. {
  2027. unchecked
  2028. {
  2029. this.Invoke((EventHandler)(delegate
  2030. {
  2031. richTextBox_BikeParam2.Clear();
  2032. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2033. {
  2034. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2035. }
  2036. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2037. }));
  2038. }
  2039. break;
  2040. }
  2041. case 0xBE20: //用户骑行参数
  2042. {
  2043. unchecked
  2044. {
  2045. this.Invoke((EventHandler)(delegate
  2046. {
  2047. richTextBox_UsrRidesParam.Clear();
  2048. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2049. {
  2050. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2051. }
  2052. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2053. }));
  2054. }
  2055. break;
  2056. }
  2057. case 0xC109: //Boot版本信息
  2058. {
  2059. BootInfo = "";
  2060. for (ushort i = 0; i < 9; i++)
  2061. {
  2062. BootInfo += ((char)Data[i]).ToString();
  2063. }
  2064. break;
  2065. }
  2066. default:
  2067. {
  2068. break;
  2069. }
  2070. }
  2071. //存储器导出数据显示
  2072. if ((CmdTemp & 0xFF00) == 0xAB00)
  2073. {
  2074. unchecked
  2075. {
  2076. this.Invoke((EventHandler)(delegate
  2077. {
  2078. long ByteNum = 0;
  2079. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2080. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2081. {
  2082. for (int i = 0; i < ByteNum; i++)
  2083. {
  2084. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2085. }
  2086. }
  2087. }));
  2088. }
  2089. }
  2090. }
  2091. #endregion
  2092. #region 解析BMS广播的命令
  2093. else if (ID == 0x720)
  2094. {
  2095. switch (CmdTemp)
  2096. {
  2097. case 0x1010://BMS运行信息
  2098. {
  2099. unchecked
  2100. {
  2101. this.Invoke((EventHandler)(delegate
  2102. {
  2103. BMS_RunInfo_Refresh = true;
  2104. richTextBox_OBC_BMS_RunInfo.Clear();
  2105. //电压
  2106. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2107. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2108. //电流
  2109. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2110. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2111. //剩余容量
  2112. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2113. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2114. //满充容量
  2115. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2116. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2117. //电芯温度
  2118. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2119. //剩余电量
  2120. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2121. //电池状态
  2122. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2123. //SOH
  2124. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2125. //循环次数
  2126. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2127. }));
  2128. }
  2129. break;
  2130. }
  2131. default: break;
  2132. }
  2133. }
  2134. #endregion
  2135. #region 解析电机发送OBC的命令
  2136. else if (ID == 0x713)
  2137. {
  2138. switch (CmdTemp)
  2139. {
  2140. case 0x5408://电机用户参数
  2141. {
  2142. unchecked
  2143. {
  2144. this.Invoke((EventHandler)(delegate
  2145. {
  2146. richTextBox_OBC_ReadUserInfo.Clear();
  2147. //默认周长
  2148. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2149. //启动模式
  2150. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2151. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2152. //限速
  2153. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2154. //周长微调
  2155. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2156. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2157. //助力方案
  2158. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2159. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2160. //关机时间
  2161. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2162. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2163. //限速微调
  2164. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2165. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2166. //定速巡航
  2167. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2168. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2169. }));
  2170. }
  2171. break;
  2172. }
  2173. case 0x5303://电机应答反馈
  2174. {
  2175. unchecked
  2176. {
  2177. this.Invoke((EventHandler)(delegate
  2178. {
  2179. timer_1s.Enabled = false;
  2180. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2181. timer_1s.Enabled = true;
  2182. }));
  2183. }
  2184. break;
  2185. }
  2186. case 0x5620: //用户骑行参数
  2187. {
  2188. unchecked
  2189. {
  2190. this.Invoke((EventHandler)(delegate
  2191. {
  2192. richTextBox_UsrRidesParam.Clear();
  2193. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2194. {
  2195. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2196. }
  2197. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2198. }));
  2199. }
  2200. break;
  2201. }
  2202. default: break;
  2203. }
  2204. }
  2205. #endregion
  2206. }
  2207. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2208. {
  2209. CmdRevStrTemp = "";
  2210. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2211. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2212. ushort len = (ushort)(CmdTemp & 0x00FF);
  2213. for (int i = 0; i < len ; i++)
  2214. {
  2215. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2216. }
  2217. }
  2218. #endregion
  2219. /// <summary>
  2220. /// 端口连接或断开
  2221. /// </summary>
  2222. private void PortConnect()
  2223. {
  2224. bool result = false;
  2225. if (连接ToolStripMenuItem.Text == "连接")
  2226. {
  2227. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2228. if (result)
  2229. {
  2230. toolStripComboBox_ComNum.Enabled = false;
  2231. toolStripComboBox_Baudrate.Enabled = false;
  2232. 刷新ToolStripMenuItem.Enabled = false;
  2233. 连接ToolStripMenuItem.Text = "断开";
  2234. 连接ToolStripMenuItem.Checked = true;
  2235. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2236. label_PortStatus.BackColor = Color.Green;
  2237. }
  2238. }
  2239. else if (连接ToolStripMenuItem.Text == "断开")
  2240. {
  2241. checkBox_OBC_StartSetGearSt.Checked = false;
  2242. checkBox_OBC_StartReadBMS.Checked = false;
  2243. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2244. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2245. toolStripComboBox_ComNum.Enabled = true;
  2246. toolStripComboBox_Baudrate.Enabled = true;
  2247. 刷新ToolStripMenuItem.Enabled = true;
  2248. 连接ToolStripMenuItem.Text = "连接";
  2249. 连接ToolStripMenuItem.Checked = false;
  2250. label_COM_Sta.Text = "连接状态:未连接";
  2251. label_PortStatus.BackColor = Color.Red;
  2252. }
  2253. }
  2254. /// <summary>
  2255. /// 端口连接事件
  2256. /// </summary>
  2257. /// <param name="sender"></param>
  2258. /// <param name="e"></param>
  2259. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2260. {
  2261. PortConnect();
  2262. }
  2263. /// <summary>
  2264. /// 端口号刷新事件
  2265. /// </summary>
  2266. /// <param name="sender"></param>
  2267. /// <param name="e"></param>
  2268. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2269. {
  2270. toolStripComboBox_ComNum.Items.Clear();
  2271. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2272. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2273. }
  2274. /// <summary>
  2275. /// 存储标志修改事件
  2276. /// </summary>
  2277. /// <param name="sender"></param>
  2278. /// <param name="e"></param>
  2279. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2280. {
  2281. if (写入存储ToolStripMenuItem.Checked)
  2282. {
  2283. EnterForm1.ShowDialog();
  2284. try
  2285. {
  2286. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2287. {
  2288. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2289. {
  2290. 写入存储ToolStripMenuItem.Checked = false;
  2291. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2292. }
  2293. else
  2294. {
  2295. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2296. }
  2297. }
  2298. else
  2299. {
  2300. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2301. }
  2302. }
  2303. catch (Exception)
  2304. {
  2305. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2306. }
  2307. }
  2308. else
  2309. {
  2310. 写入存储ToolStripMenuItem.Checked = true;
  2311. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2312. }
  2313. }
  2314. /// <summary>
  2315. /// 1s定时器
  2316. /// </summary>
  2317. /// <param name="sender"></param>
  2318. /// <param name="e"></param>
  2319. private void timer_1s_Tick(object sender, EventArgs e)
  2320. {
  2321. //时间更新
  2322. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2323. //MC_Runinfo超时清除
  2324. if (MC_RunInfo_Refresh == false)
  2325. {
  2326. MC_RunInfo_Refresh_Cnt++;
  2327. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2328. {
  2329. MC_RunInfo_Clear();
  2330. MC_RunInfo_Refresh_Cnt = 0;
  2331. }
  2332. }
  2333. else
  2334. {
  2335. MC_RunInfo_Refresh_Cnt = 0;
  2336. }
  2337. MC_RunInfo_Refresh = false;
  2338. //MC_Debuginfo超时清除
  2339. if (MC_DebugInfo_Refresh == false)
  2340. {
  2341. MC_DebugInfo_Refresh_Cnt++;
  2342. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2343. {
  2344. MC_DebugInfo_Clear();
  2345. MC_DebugInfo_Refresh_Cnt = 0;
  2346. }
  2347. }
  2348. else
  2349. {
  2350. MC_DebugInfo_Refresh_Cnt = 0;
  2351. }
  2352. MC_DebugInfo_Refresh = false;
  2353. //BMS_RunInfo超时清除
  2354. if (BMS_RunInfo_Refresh == false)
  2355. {
  2356. BMS_RunInfo_Refresh_Cnt++;
  2357. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2358. {
  2359. richTextBox_OBC_BMS_RunInfo.Clear();
  2360. BMS_RunInfo_Refresh_Cnt = 0;
  2361. }
  2362. }
  2363. else
  2364. {
  2365. BMS_RunInfo_Refresh_Cnt = 0;
  2366. }
  2367. BMS_RunInfo_Refresh = false;
  2368. //故障码超时清除
  2369. if (MC_ErrorCode_Refresh == false)
  2370. {
  2371. MC_ErrorCode_Refresh_Cnt++;
  2372. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2373. {
  2374. textBox_ErrorCode.Text = "---";
  2375. MC_ErrorCode_Refresh_Cnt = 0;
  2376. }
  2377. }
  2378. else
  2379. {
  2380. MC_ErrorCode_Refresh_Cnt = 0;
  2381. }
  2382. MC_ErrorCode_Refresh = false;
  2383. //CDL连接超时
  2384. if (识别通讯盒ToolStripMenuItem.Checked)
  2385. {
  2386. if (mySerialProcess.CDL_Online_Flag == false)
  2387. {
  2388. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2389. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2390. {
  2391. timer_1s.Enabled = false;
  2392. MessageBox.Show("连接失败!", "提示");
  2393. timer_1s.Enabled = true;
  2394. //关闭串口
  2395. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2396. toolStripComboBox_ComNum.Enabled = true;
  2397. toolStripComboBox_Baudrate.Enabled = true;
  2398. 刷新ToolStripMenuItem.Enabled = true;
  2399. 连接ToolStripMenuItem.Text = "连接";
  2400. 连接ToolStripMenuItem.Checked = false;
  2401. label_COM_Sta.Text = "连接状态:未连接";
  2402. label_PortStatus.BackColor = Color.Red;
  2403. }
  2404. }
  2405. }
  2406. //OBC定时发送设置档位
  2407. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2408. {
  2409. var CtrlCode = new byte[2];
  2410. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2411. CtrlCode[0] = 0x33;
  2412. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2413. CtrlCode[0] = 0x22;
  2414. else
  2415. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2416. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2417. CtrlCode[1] = 0xF1;
  2418. else
  2419. CtrlCode[1] = 0xF0;
  2420. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2421. {
  2422. checkBox_OBC_StartSetGearSt.Checked = false;
  2423. }
  2424. }
  2425. //OBC定时发送查询电池
  2426. if (checkBox_OBC_StartReadBMS.Checked == true)
  2427. {
  2428. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2429. {
  2430. checkBox_OBC_StartReadBMS.Checked = false;
  2431. }
  2432. }
  2433. //定时读取存储器
  2434. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2435. {
  2436. var Address = new byte[4];
  2437. UInt32 Address_Begin;
  2438. UInt32 Addres_End;
  2439. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2440. richTextBox_RamFlasgData.Clear();
  2441. do
  2442. {
  2443. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2444. {
  2445. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2446. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2447. continue;
  2448. }
  2449. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2450. {
  2451. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2452. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2453. continue;
  2454. }
  2455. else
  2456. {
  2457. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2458. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2459. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2460. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2461. if (Addres_End < Address_Begin)
  2462. {
  2463. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2464. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2465. continue;
  2466. }
  2467. else
  2468. {
  2469. var SendByte = new byte[8];
  2470. SendByte[0] = (byte)(Address_Begin >> 24);
  2471. SendByte[1] = (byte)(Address_Begin >> 16);
  2472. SendByte[2] = (byte)(Address_Begin >> 8);
  2473. SendByte[3] = (byte)(Address_Begin);
  2474. SendByte[4] = (byte)(Addres_End >> 24);
  2475. SendByte[5] = (byte)(Addres_End >> 16);
  2476. SendByte[6] = (byte)(Addres_End >> 8);
  2477. SendByte[7] = (byte)(Addres_End);
  2478. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2479. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2480. }
  2481. }
  2482. } while (false);
  2483. }
  2484. //写入参数等待计时
  2485. ACK_WaitCnt++;
  2486. }
  2487. /// <summary>
  2488. /// 运行信息清除
  2489. /// </summary>
  2490. private void MC_RunInfo_Clear()
  2491. {
  2492. foreach (Control c in tabPage_RunInfo.Controls)
  2493. {
  2494. if ((c is TextBox))
  2495. {
  2496. if (c.Name != textBox_ErrorCode.ToString())
  2497. c.Text = "---";
  2498. }
  2499. }
  2500. }
  2501. /// <summary>
  2502. /// 调试信息清除
  2503. /// </summary>
  2504. private void MC_DebugInfo_Clear()
  2505. {
  2506. foreach (Control c in tabPage_DebugInfo.Controls)
  2507. {
  2508. if ((c is TextBox))
  2509. {
  2510. if (c.Name != textBox_ErrorCode.ToString())
  2511. c.Text = "---";
  2512. }
  2513. }
  2514. }
  2515. /// <summary>
  2516. /// 读取马达参数
  2517. /// </summary>
  2518. /// <param name="sender"></param>
  2519. /// <param name="e"></param>
  2520. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2521. {
  2522. richTextBox_MotorParam.Clear();
  2523. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2524. }
  2525. /// <summary>
  2526. /// 写入马达参数
  2527. /// </summary>
  2528. /// <param name="sender"></param>
  2529. /// <param name="e"></param>
  2530. private void button_Write_Click(object sender, EventArgs e)
  2531. {
  2532. var ConfigParam = new byte[40];
  2533. for (int i = 0; i < 40; i++)
  2534. ConfigParam[i] = 0;
  2535. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2536. short wDataTemp = 0;
  2537. ushort DataTemp = 0;
  2538. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2539. try
  2540. {
  2541. for (int i = 0; i < strDataTemp.Length; i++)
  2542. {
  2543. if (i == 6)
  2544. {
  2545. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2546. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2547. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2548. }
  2549. else
  2550. {
  2551. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2552. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2553. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2554. }
  2555. }
  2556. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2557. }
  2558. catch (Exception)
  2559. {
  2560. timer_1s.Enabled = false;
  2561. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2562. timer_1s.Enabled = true;
  2563. }
  2564. }
  2565. /// <summary>
  2566. /// 读取整车信息
  2567. /// </summary>
  2568. /// <param name="sender"></param>
  2569. /// <param name="e"></param>
  2570. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2571. {
  2572. richTextBox_BikeParam.Clear();
  2573. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2574. }
  2575. /// <summary>
  2576. /// 写入整车信息
  2577. /// </summary>
  2578. /// <param name="sender"></param>
  2579. /// <param name="e"></param>
  2580. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2581. {
  2582. var ConfigParam = new byte[28];
  2583. for (int i = 0; i < 28; i++)
  2584. ConfigParam[i] = 0;
  2585. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2586. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2587. try
  2588. {
  2589. for (int i = 0; i < strDataTemp.Length; i++)
  2590. {
  2591. short wDataTemp = 0;
  2592. //前后灯参数修改
  2593. if (i == 8)
  2594. {
  2595. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2596. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2597. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2598. }
  2599. //开关机参数
  2600. else if (i == 11)
  2601. {
  2602. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2603. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2604. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2605. }
  2606. else
  2607. {
  2608. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2609. }
  2610. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2611. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2612. }
  2613. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2614. }
  2615. catch (Exception)
  2616. {
  2617. timer_1s.Enabled = false;
  2618. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2619. timer_1s.Enabled = true;
  2620. }
  2621. }
  2622. /// <summary>
  2623. /// 读取控制器参数
  2624. /// </summary>
  2625. /// <param name="sender"></param>
  2626. /// <param name="e"></param>
  2627. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2628. {
  2629. richTextBox_ControlParam.Clear();
  2630. comboBox_Bike_CCS.SelectedIndex = 0;
  2631. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2632. }
  2633. /// <summary>
  2634. /// 写入控制器参数
  2635. /// </summary>
  2636. /// <param name="sender"></param>
  2637. /// <param name="e"></param>
  2638. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2639. {
  2640. var ConfigParam = new byte[34];
  2641. for (int i = 0; i < 34; i++)
  2642. ConfigParam[i] = 0;
  2643. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2644. ushort uwDataTemp = 0;
  2645. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2646. try
  2647. {
  2648. for (int i = 0; i < strDataTemp.Length; i++)
  2649. {
  2650. if (i == 13)
  2651. {
  2652. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2653. }
  2654. else
  2655. {
  2656. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2657. }
  2658. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2659. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2660. }
  2661. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2662. }
  2663. catch (Exception)
  2664. {
  2665. timer_1s.Enabled = false;
  2666. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2667. timer_1s.Enabled = true;
  2668. }
  2669. }
  2670. /// <summary>
  2671. /// 读取助力参数
  2672. /// </summary>
  2673. /// <param name="sender"></param>
  2674. /// <param name="e"></param>
  2675. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2676. {
  2677. var ConfigParam = new byte[4];
  2678. int AssistNum = 0;
  2679. try
  2680. {
  2681. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2682. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2683. ConfigParam[1] = (byte)(AssistNum >> 8);
  2684. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2685. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2686. ConfigParam[3] = (byte)(AssistNum >> 8);
  2687. richTextBox_AssistParam.Clear();
  2688. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2689. }
  2690. catch (Exception)
  2691. {
  2692. timer_1s.Enabled = false;
  2693. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2694. timer_1s.Enabled = true;
  2695. }
  2696. }
  2697. /// <summary>
  2698. /// 写入助力参数
  2699. /// </summary>
  2700. /// <param name="sender"></param>
  2701. /// <param name="e"></param>
  2702. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2703. {
  2704. var ConfigParam = new byte[80];
  2705. for (int i = 0; i < 80; i++)
  2706. ConfigParam[i] = 0;
  2707. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2708. long lDataTemp = 0;
  2709. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2710. int index_1 = 0, index_2 = 0;
  2711. try
  2712. {
  2713. for (int i = 0; i < strDataTemp.Length; i++)
  2714. {
  2715. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2716. {
  2717. index_1 = i;
  2718. break;
  2719. }
  2720. }
  2721. for (int i = 0; i < strDataTemp.Length; i++)
  2722. {
  2723. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2724. {
  2725. index_2 = i;
  2726. break;
  2727. }
  2728. }
  2729. for (int i = 0; i < strDataTemp.Length; i++)
  2730. {
  2731. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2732. if (i < index_1)
  2733. {
  2734. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2735. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2736. }
  2737. else if (i <= index_2)
  2738. {
  2739. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2740. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2741. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2742. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2743. }
  2744. else
  2745. {
  2746. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2747. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2748. }
  2749. }
  2750. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2751. }
  2752. catch (Exception)
  2753. {
  2754. timer_1s.Enabled = false;
  2755. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2756. timer_1s.Enabled = true;
  2757. }
  2758. }
  2759. /// <summary>
  2760. /// 读取调试参数
  2761. /// </summary>
  2762. /// <param name="sender"></param>
  2763. /// <param name="e"></param>
  2764. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2765. {
  2766. richTextBox_DebugParam.Clear();
  2767. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2768. }
  2769. /// <summary>
  2770. /// 写入调试参数
  2771. /// </summary>
  2772. /// <param name="sender"></param>
  2773. /// <param name="e"></param>
  2774. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2775. {
  2776. var ConfigParam = new byte[60];
  2777. for (int i = 0; i < 60; i++)
  2778. ConfigParam[i] = 0;
  2779. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2780. ushort uwDataTemp = 0;
  2781. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2782. try
  2783. {
  2784. for (int i = 0; i < strDataTemp.Length; i++)
  2785. {
  2786. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2787. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2788. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2789. }
  2790. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2791. }
  2792. catch (Exception)
  2793. {
  2794. timer_1s.Enabled = false;
  2795. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2796. timer_1s.Enabled = true;
  2797. }
  2798. }
  2799. /// <summary>
  2800. /// 读取历史
  2801. /// </summary>
  2802. /// <param name="sender"></param>
  2803. /// <param name="e"></param>
  2804. private void button_ReadRecord_Click(object sender, EventArgs e)
  2805. {
  2806. richTextBox_Record.Clear();
  2807. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2808. }
  2809. /// <summary>
  2810. /// 读取传感器参数
  2811. /// </summary>
  2812. /// <param name="sender"></param>
  2813. /// <param name="e"></param>
  2814. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2815. {
  2816. richTextBox_SensorParam.Clear();
  2817. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2818. }
  2819. /// <summary>
  2820. /// 写入力矩传感器标定值
  2821. /// </summary>
  2822. /// <param name="sender"></param>
  2823. /// <param name="e"></param>
  2824. private void button_Write_Cal_Click(object sender, EventArgs e)
  2825. {
  2826. var ConfigParam = new byte[4];
  2827. for (int i = 0; i < 4; i++)
  2828. ConfigParam[i] = 0;
  2829. ushort uwDataTemp = 0;
  2830. try
  2831. {
  2832. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2833. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2834. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2835. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2836. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2837. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2838. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2839. }
  2840. catch (Exception)
  2841. {
  2842. timer_1s.Enabled = false;
  2843. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2844. timer_1s.Enabled = true;
  2845. }
  2846. }
  2847. /// <summary>
  2848. /// 写入传感器参数
  2849. /// </summary>
  2850. /// <param name="sender"></param>
  2851. /// <param name="e"></param>
  2852. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2853. {
  2854. var ConfigParam = new byte[14];
  2855. for (int i = 0; i < 14; i++)
  2856. ConfigParam[i] = 0;
  2857. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2858. ushort uwDataTemp = 0;
  2859. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2860. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2861. int index = 0;
  2862. try
  2863. {
  2864. for (int i = 0; i < strDataTemp.Length; i++)
  2865. {
  2866. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  2867. {
  2868. index = i;
  2869. break;
  2870. }
  2871. }
  2872. for (int i = 0; i < (strDataTemp.Length - index); i++)
  2873. {
  2874. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  2875. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2876. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2877. }
  2878. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  2879. }
  2880. catch (Exception)
  2881. {
  2882. timer_1s.Enabled = false;
  2883. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2884. timer_1s.Enabled = true;
  2885. }
  2886. }
  2887. /// <summary>
  2888. /// 写入型号
  2889. /// </summary>
  2890. /// <param name="sender"></param>
  2891. /// <param name="e"></param>
  2892. private void button_WriteModel_Click(object sender, EventArgs e)
  2893. {
  2894. string Mode = textBox_Model.Text;
  2895. var ModeArray = new byte[16];
  2896. for (ushort i = 0; i < Mode.Length; i++)
  2897. {
  2898. ModeArray[i] = (byte)Mode[i];
  2899. }
  2900. if (Mode.Length < 16)
  2901. {
  2902. ModeArray[Mode.Length] = (byte)'.';
  2903. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2904. {
  2905. ModeArray[Mode.Length + 1 + i] = 0x20;
  2906. }
  2907. }
  2908. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2909. }
  2910. /// <summary>
  2911. /// 写入SN
  2912. /// </summary>
  2913. /// <param name="sender"></param>
  2914. /// <param name="e"></param>
  2915. private void button_WriteSN_Click(object sender, EventArgs e)
  2916. {
  2917. string SN = textBox_SN.Text;
  2918. var SNArray = new byte[16];
  2919. for (ushort i = 0; i < SN.Length; i++)
  2920. {
  2921. SNArray[i] = (byte)SN[i];
  2922. }
  2923. if (SN.Length < 16)
  2924. {
  2925. SNArray[SN.Length] = (byte)'.';
  2926. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2927. {
  2928. SNArray[SN.Length + 1 + i] = 0x20;
  2929. }
  2930. }
  2931. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2932. }
  2933. /// <summary>
  2934. /// 查询版本信息
  2935. /// </summary>
  2936. /// <param name="sender"></param>
  2937. /// <param name="e"></param>
  2938. private void button_ReadVersion_Click(object sender, EventArgs e)
  2939. {
  2940. textBox_Model.Text = "---";
  2941. textBox_SN.Text = "---";
  2942. textBox_HW.Text = "---";
  2943. textBox_FW.Text = "---";
  2944. textBox_SP.Text = "---";
  2945. textBox_OBC_ReadModel.Text = "---";
  2946. textBox_OBC_ReadSN.Text = "---";
  2947. textBox_OBC_ReadHW.Text = "---";
  2948. textBox_OBC_ReadFW.Text = "---";
  2949. textBox_OBC_ReadSP.Text = "---";
  2950. textBox_FacModeName.Text = "---";
  2951. textBox_FacModeNum.Text = "---";
  2952. textBox_FacModeHW.Text = "---";
  2953. textBox_FacModeFW.Text = "---";
  2954. textBox_FacModeSP.Text = "---";
  2955. Class_Motor_Ver.Mode = "---";
  2956. Class_Motor_Ver.SN = "---";
  2957. Class_Motor_Ver.HW = "---";
  2958. Class_Motor_Ver.FW = "---";
  2959. Class_Motor_Ver.Special = "---";
  2960. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2961. }
  2962. /// <summary>
  2963. /// 查询自定义1
  2964. /// </summary>
  2965. /// <param name="sender"></param>
  2966. /// <param name="e"></param>
  2967. private void button_ReadUser1_Click(object sender, EventArgs e)
  2968. {
  2969. textBox_User1.Text = "---";
  2970. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  2971. }
  2972. /// <summary>
  2973. /// 查询自定义2
  2974. /// </summary>
  2975. /// <param name="sender"></param>
  2976. /// <param name="e"></param>
  2977. private void button_ReadUser2_Click(object sender, EventArgs e)
  2978. {
  2979. textBox_User2.Text = "---";
  2980. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  2981. }
  2982. /// <summary>
  2983. /// 查询自定义3
  2984. /// </summary>
  2985. /// <param name="sender"></param>
  2986. /// <param name="e"></param>
  2987. private void button_ReadUser3_Click(object sender, EventArgs e)
  2988. {
  2989. textBox_User3.Text = "---";
  2990. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  2991. }
  2992. /// <summary>
  2993. /// 写入自定义字符串1
  2994. /// </summary>
  2995. /// <param name="sender"></param>
  2996. /// <param name="e"></param>
  2997. private void button_WriteUser1_Click(object sender, EventArgs e)
  2998. {
  2999. string User = textBox_User1.Text;
  3000. var UserArray = new byte[16];
  3001. for (ushort i = 0; i < User.Length; i++)
  3002. {
  3003. UserArray[i] = (byte)User[i];
  3004. }
  3005. if (User.Length < 16)
  3006. {
  3007. UserArray[User.Length] = (byte)'.';
  3008. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3009. {
  3010. UserArray[User.Length + 1 + i] = 0x20;
  3011. }
  3012. }
  3013. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3014. }
  3015. /// <summary>
  3016. /// 写入自定义字符串2
  3017. /// </summary>
  3018. /// <param name="sender"></param>
  3019. /// <param name="e"></param>
  3020. private void button_WriteUser2_Click(object sender, EventArgs e)
  3021. {
  3022. string User = textBox_User2.Text;
  3023. var UserArray = new byte[16];
  3024. for (ushort i = 0; i < User.Length; i++)
  3025. {
  3026. UserArray[i] = (byte)User[i];
  3027. }
  3028. if (User.Length < 16)
  3029. {
  3030. UserArray[User.Length] = (byte)'.';
  3031. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3032. {
  3033. UserArray[User.Length + 1 + i] = 0x20;
  3034. }
  3035. }
  3036. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3037. }
  3038. /// <summary>
  3039. /// 写入自定义字符串3
  3040. /// </summary>
  3041. /// <param name="sender"></param>
  3042. /// <param name="e"></param>
  3043. private void button_WriteUser3_Click(object sender, EventArgs e)
  3044. {
  3045. string User = textBox_User3.Text;
  3046. var UserArray = new byte[16];
  3047. for (ushort i = 0; i < User.Length; i++)
  3048. {
  3049. UserArray[i] = (byte)User[i];
  3050. }
  3051. if (User.Length < 16)
  3052. {
  3053. UserArray[User.Length] = (byte)'.';
  3054. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3055. {
  3056. UserArray[User.Length + 1 + i] = 0x20;
  3057. }
  3058. }
  3059. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3060. }
  3061. /// <summary>
  3062. /// 查询生产信息
  3063. /// </summary>
  3064. /// <param name="sender"></param>
  3065. /// <param name="e"></param>
  3066. private void button_ReadMAC_Click(object sender, EventArgs e)
  3067. {
  3068. textBox_MAC.Text = "---";
  3069. textBox_MACAdd.Text = "---";
  3070. textBox_MACDate.Text = "---";
  3071. textBox_PP.Text = "---";
  3072. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3073. }
  3074. /// <summary>
  3075. /// 写入生产信息
  3076. /// </summary>
  3077. /// <param name="sender"></param>
  3078. /// <param name="e"></param>
  3079. private void button_WriteMac_Click(object sender, EventArgs e)
  3080. {
  3081. var MACArray = new byte[32];
  3082. //填入生产商
  3083. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3084. {
  3085. MACArray[i] = (byte)textBox_MAC.Text[i];
  3086. }
  3087. if (textBox_MAC.Text.Length < 8)
  3088. {
  3089. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3090. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3091. {
  3092. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3093. }
  3094. }
  3095. //填入生产地
  3096. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3097. {
  3098. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3099. }
  3100. if (textBox_MACAdd.Text.Length < 8)
  3101. {
  3102. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3103. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3104. {
  3105. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3106. }
  3107. }
  3108. //填入生产日期
  3109. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3110. {
  3111. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3112. }
  3113. if (textBox_MACDate.Text.Length < 8)
  3114. {
  3115. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3116. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3117. {
  3118. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3119. }
  3120. }
  3121. //填入品牌
  3122. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3123. {
  3124. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3125. }
  3126. if (textBox_PP.Text.Length < 8)
  3127. {
  3128. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3129. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3130. {
  3131. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3132. }
  3133. }
  3134. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3135. }
  3136. /// <summary>
  3137. /// 查询密钥
  3138. /// </summary>
  3139. /// <param name="sender"></param>
  3140. /// <param name="e"></param>
  3141. private void button_ReadKey_Click(object sender, EventArgs e)
  3142. {
  3143. textBox_Key.Text = "---";
  3144. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3145. }
  3146. /// <summary>
  3147. /// 写入校验密钥
  3148. /// </summary>
  3149. /// <param name="sender"></param>
  3150. /// <param name="e"></param>
  3151. private void button_WriteKey_Click(object sender, EventArgs e)
  3152. {
  3153. string Key = textBox_Key.Text;
  3154. var KeyArray = new byte[8];
  3155. if (Key.Length != 8)
  3156. {
  3157. timer_1s.Enabled = false;
  3158. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3159. timer_1s.Enabled = true;
  3160. return;
  3161. }
  3162. for (ushort i = 0; i < Key.Length; i++)
  3163. {
  3164. KeyArray[i] = (byte)Key[i];
  3165. }
  3166. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3167. }
  3168. /// <summary>
  3169. /// 查询在线检测结果
  3170. /// </summary>
  3171. /// <param name="sender"></param>
  3172. /// <param name="e"></param>
  3173. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3174. {
  3175. textBox_Online.Text = "---";
  3176. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3177. }
  3178. /// <summary>
  3179. /// 系统清除
  3180. /// </summary>
  3181. /// <param name="sender"></param>
  3182. /// <param name="e"></param>
  3183. private void button_SystemClear_Click(object sender, EventArgs e)
  3184. {
  3185. var Code = new byte[5];
  3186. Code[0] = (byte)'C';
  3187. Code[1] = (byte)'L';
  3188. Code[2] = (byte)'E';
  3189. Code[3] = (byte)'A';
  3190. Code[4] = (byte)'R';
  3191. timer_1s.Enabled = false;
  3192. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3193. {
  3194. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3195. {
  3196. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3197. {
  3198. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3199. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3200. }
  3201. }
  3202. }
  3203. timer_1s.Enabled = true;
  3204. }
  3205. /// <summary>
  3206. /// 参数还原
  3207. /// </summary>
  3208. /// <param name="sender"></param>
  3209. /// <param name="e"></param>
  3210. private void button_Recovery_Click(object sender, EventArgs e)
  3211. {
  3212. var Code = new byte[8];
  3213. Code[0] = (byte)'R';
  3214. Code[1] = (byte)'E';
  3215. Code[2] = (byte)'C';
  3216. Code[3] = (byte)'O';
  3217. Code[4] = (byte)'V';
  3218. Code[5] = (byte)'E';
  3219. Code[6] = (byte)'R';
  3220. Code[7] = (byte)'Y';
  3221. timer_1s.Enabled = false;
  3222. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3223. {
  3224. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3225. {
  3226. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3227. {
  3228. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3229. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3230. }
  3231. }
  3232. }
  3233. timer_1s.Enabled = true;
  3234. }
  3235. /// <summary>
  3236. /// 系统复位
  3237. /// </summary>
  3238. /// <param name="sender"></param>
  3239. /// <param name="e"></param>
  3240. private void button_Reset_Click(object sender, EventArgs e)
  3241. {
  3242. var Code_Off = new byte[5];
  3243. var Code_Reset = new byte[5];
  3244. Code_Off[0] = (byte)'O';
  3245. Code_Off[1] = (byte)'F';
  3246. Code_Off[2] = (byte)'F';
  3247. Code_Off[3] = (byte)'.';
  3248. Code_Off[4] = (byte)'.';
  3249. Code_Reset[0] = (byte)'R';
  3250. Code_Reset[1] = (byte)'E';
  3251. Code_Reset[2] = (byte)'S';
  3252. Code_Reset[3] = (byte)'E';
  3253. Code_Reset[4] = (byte)'T';
  3254. timer_1s.Enabled = false;
  3255. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3256. {
  3257. timer_1s.Enabled = true;
  3258. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3259. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3260. PowerOffAckStatus = false;
  3261. Delay_ms(250);
  3262. int TryCnt = 3;
  3263. while ((TryCnt--) >= 0)
  3264. {
  3265. if (!PowerOffAckStatus)
  3266. {
  3267. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3268. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3269. PowerOffAckStatus = false;
  3270. Delay_ms(250);
  3271. }
  3272. else break;
  3273. }
  3274. if (PowerOffAckStatus)
  3275. {
  3276. timer_1s.Enabled = false;
  3277. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3278. timer_1s.Enabled = true;
  3279. }
  3280. else
  3281. {
  3282. timer_1s.Enabled = false;
  3283. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3284. timer_1s.Enabled = true;
  3285. }
  3286. }
  3287. timer_1s.Enabled = true;
  3288. }
  3289. /// <summary>
  3290. /// 记录清除
  3291. /// </summary>
  3292. /// <param name="sender"></param>
  3293. /// <param name="e"></param>
  3294. private void button_ClearLog_Click(object sender, EventArgs e)
  3295. {
  3296. var Code = new byte[9];
  3297. Code[0] = (byte)'L';
  3298. Code[1] = (byte)'O';
  3299. Code[2] = (byte)'G';
  3300. Code[3] = (byte)' ';
  3301. Code[4] = (byte)'C';
  3302. Code[5] = (byte)'L';
  3303. Code[6] = (byte)'E';
  3304. Code[7] = (byte)'A';
  3305. Code[8] = (byte)'R';
  3306. timer_1s.Enabled = false;
  3307. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3308. {
  3309. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3310. {
  3311. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3312. {
  3313. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3314. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3315. }
  3316. }
  3317. }
  3318. timer_1s.Enabled = true;
  3319. }
  3320. /// <summary>
  3321. /// 打开系统计算器
  3322. /// </summary>
  3323. /// <param name="sender"></param>
  3324. /// <param name="e"></param>
  3325. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3326. {
  3327. System.Diagnostics.Process.Start("calc.exe");
  3328. }
  3329. /// <summary>
  3330. ///故障转换和显示
  3331. /// </summary>
  3332. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3333. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3334. "",""};
  3335. private string ErrorInfoDisplay(UInt32 Code)
  3336. {
  3337. string Result = "";
  3338. if (Code == 0)
  3339. {
  3340. Result = "无故障";
  3341. }
  3342. else
  3343. {
  3344. for (int i = 0; i < 32; i++)
  3345. {
  3346. if ((Code & 0x01) == 0x01)
  3347. {
  3348. Result += ErrorInfo[i] + " ";
  3349. }
  3350. Code >>= 1;
  3351. }
  3352. }
  3353. return Result;
  3354. }
  3355. /// <summary>
  3356. /// 鼠标滑过故障码显示具体内容
  3357. /// </summary>
  3358. /// <param name="sender"></param>
  3359. /// <param name="e"></param>
  3360. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3361. {
  3362. // 创建the ToolTip
  3363. ToolTip toolTip1 = new ToolTip();
  3364. // 设置显示样式
  3365. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3366. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3367. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3368. toolTip1.ShowAlways = true;//是否显示提示框
  3369. // 设置伴随的对象.
  3370. string ErrorCode = this.textBox_ErrorCode.Text;
  3371. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3372. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3373. }
  3374. /// <summary>
  3375. /// 数据记录
  3376. /// </summary>
  3377. private void RunInfoAutoSave()
  3378. {
  3379. if (运行信息记录ToolStripMenuItem.Checked == true)
  3380. {
  3381. if (RunInfoSaveFilename == string.Empty)
  3382. {
  3383. return;
  3384. }
  3385. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3386. foreach (Control c in tabPage_RunInfo.Controls)
  3387. {
  3388. if (c is TextBox)
  3389. {
  3390. SaveData += c.Text + " , ";
  3391. }
  3392. }
  3393. foreach (Control c in tabPage_DebugInfo.Controls)
  3394. {
  3395. if (c is TextBox)
  3396. {
  3397. SaveData += c.Text + " , ";
  3398. }
  3399. }
  3400. SaveData += "\r\n";
  3401. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3402. }
  3403. }
  3404. /// <summary>
  3405. /// 打开或关闭数据记录
  3406. /// </summary>
  3407. /// <param name="sender"></param>
  3408. /// <param name="e"></param>
  3409. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3410. {
  3411. if (运行信息记录ToolStripMenuItem.Checked == false)
  3412. {
  3413. if (mySerialProcess.mySerial.IsOpen == true)
  3414. {
  3415. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3416. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3417. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3418. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3419. timer_1s.Enabled = false;
  3420. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3421. timer_1s.Enabled = true;
  3422. 运行信息记录ToolStripMenuItem.Checked = true;
  3423. }
  3424. else
  3425. {
  3426. timer_1s.Enabled = false;
  3427. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3428. timer_1s.Enabled = true;
  3429. }
  3430. }
  3431. else
  3432. {
  3433. 运行信息记录ToolStripMenuItem.Checked = false;
  3434. timer_1s.Enabled = false;
  3435. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3436. timer_1s.Enabled = true;
  3437. }
  3438. }
  3439. /// <summary>
  3440. /// 仪表启动控制档位开关事件
  3441. /// </summary>
  3442. /// <param name="sender"></param>
  3443. /// <param name="e"></param>
  3444. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3445. {
  3446. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3447. {
  3448. //检查串口是否打开
  3449. if (!mySerialProcess.mySerial.IsOpen)
  3450. {
  3451. timer_1s.Enabled = false;
  3452. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3453. timer_1s.Enabled = true;
  3454. checkBox_OBC_StartSetGearSt.Checked = false;
  3455. return;
  3456. }
  3457. //检查是否选择档位和打开车灯
  3458. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3459. {
  3460. timer_1s.Enabled = false;
  3461. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3462. timer_1s.Enabled = true;
  3463. checkBox_OBC_StartSetGearSt.Checked = false;
  3464. return;
  3465. }
  3466. }
  3467. }
  3468. /// <summary>
  3469. /// OBC查询电机用户参数
  3470. /// </summary>
  3471. /// <param name="sender"></param>
  3472. /// <param name="e"></param>
  3473. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3474. {
  3475. richTextBox_OBC_ReadUserInfo.Clear();
  3476. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3477. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3478. }
  3479. /// <summary>
  3480. /// OBC设置电机用户参数
  3481. /// </summary>
  3482. /// <param name="sender"></param>
  3483. /// <param name="e"></param>
  3484. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3485. {
  3486. var UserInfoCode = new byte[8];
  3487. for (int i = 0; i < UserInfoCode.Length; i++)
  3488. UserInfoCode[i] = 0;
  3489. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3490. {
  3491. timer_1s.Enabled = false;
  3492. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3493. timer_1s.Enabled = true;
  3494. return;
  3495. }
  3496. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3497. {
  3498. timer_1s.Enabled = false;
  3499. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3500. timer_1s.Enabled = true;
  3501. return;
  3502. }
  3503. //周长微调
  3504. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3505. //启动模式
  3506. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3507. //助力方案
  3508. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3509. //自动关机时间
  3510. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3511. //限速微调
  3512. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3513. //定速巡航开关
  3514. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3515. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3516. }
  3517. /// <summary>
  3518. /// OBC查询电机版本信息
  3519. /// </summary>
  3520. /// <param name="sender"></param>
  3521. /// <param name="e"></param>
  3522. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3523. {
  3524. textBox_Model.Text = "---";
  3525. textBox_SN.Text = "---";
  3526. textBox_HW.Text = "---";
  3527. textBox_FW.Text = "---";
  3528. textBox_SP.Text = "---";
  3529. textBox_OBC_ReadModel.Text = "---";
  3530. textBox_OBC_ReadSN.Text = "---";
  3531. textBox_OBC_ReadHW.Text = "---";
  3532. textBox_OBC_ReadFW.Text = "---";
  3533. textBox_OBC_ReadSP.Text = "---";
  3534. textBox_FacModeName.Text = "---";
  3535. textBox_FacModeNum.Text = "---";
  3536. textBox_FacModeHW.Text = "---";
  3537. textBox_FacModeFW.Text = "---";
  3538. textBox_FacModeSP.Text = "---";
  3539. Class_Motor_Ver.Mode = "---";
  3540. Class_Motor_Ver.SN = "---";
  3541. Class_Motor_Ver.HW = "---";
  3542. Class_Motor_Ver.FW = "---";
  3543. Class_Motor_Ver.Special = "---";
  3544. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3545. }
  3546. /// <summary>
  3547. /// OBC读取骑行历史
  3548. /// </summary>
  3549. /// <param name="sender"></param>
  3550. /// <param name="e"></param>
  3551. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3552. {
  3553. textBox_OBC_TRIP_KM.Text = "";
  3554. textBox_OBC_TRIP_TIME.Text = "";
  3555. textBox_OBC_ODO_KM.Text = "";
  3556. textBox_OBC_ODO_TIME.Text = "";
  3557. textBox_ODO_KM.Text = "---";
  3558. textBox_ODO_TIME.Text = "---";
  3559. textBox_TRIP_KM.Text = "---";
  3560. textBox_TRIP_TIME.Text = "---";
  3561. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3562. }
  3563. /// <summary>
  3564. /// OBC清除TRIP里程
  3565. /// </summary>
  3566. /// <param name="sender"></param>
  3567. /// <param name="e"></param>
  3568. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3569. {
  3570. var Code = new byte[5];
  3571. Code[0] = (byte)'C';
  3572. Code[1] = (byte)'L';
  3573. Code[2] = (byte)'E';
  3574. Code[3] = (byte)'A';
  3575. Code[4] = (byte)'R';
  3576. timer_1s.Enabled = false;
  3577. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3578. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3579. timer_1s.Enabled = true;
  3580. }
  3581. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3582. {
  3583. if (checkBox_OBC_StartReadBMS.Checked == true)
  3584. {
  3585. //检查串口是否打开
  3586. if (!mySerialProcess.mySerial.IsOpen)
  3587. {
  3588. timer_1s.Enabled = false;
  3589. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3590. timer_1s.Enabled = true;
  3591. checkBox_OBC_StartReadBMS.Checked = false;
  3592. return;
  3593. }
  3594. }
  3595. }
  3596. /// <summary>
  3597. /// 写入力矩传感器参数
  3598. /// </summary>
  3599. /// <param name="sender"></param>
  3600. /// <param name="e"></param>
  3601. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3602. {
  3603. var ConfigParam = new byte[46];
  3604. for (int i = 0; i < 14; i++)
  3605. ConfigParam[i] = 0;
  3606. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3607. ushort uwDataTemp = 0;
  3608. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3609. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3610. int index = 0;
  3611. try
  3612. {
  3613. for (int i = 0; i < strDataTemp.Length; i++)
  3614. {
  3615. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3616. {
  3617. index = i;
  3618. break;
  3619. }
  3620. }
  3621. for (int i = 0; i < (index + 1); i++)
  3622. {
  3623. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3624. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3625. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3626. }
  3627. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3628. }
  3629. catch (Exception)
  3630. {
  3631. timer_1s.Enabled = false;
  3632. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3633. timer_1s.Enabled = true;
  3634. }
  3635. }
  3636. /// <summary>
  3637. /// 查询存储标志
  3638. /// </summary>
  3639. /// <param name="sender"></param>
  3640. /// <param name="e"></param>
  3641. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3642. {
  3643. radioButton_EE_SaveYes.Checked = false;
  3644. radioButton_EE_SaveNo.Checked = false;
  3645. radioButton_SIP_SaveYes.Checked = false;
  3646. radioButton_SIP_SaveNo.Checked = false;
  3647. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3648. }
  3649. /// <summary>
  3650. /// 写入存储标志
  3651. /// </summary>
  3652. /// <param name="sender"></param>
  3653. /// <param name="e"></param>
  3654. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3655. {
  3656. var SaveFlag = new byte[6];
  3657. for (int i = 0; i < 6; i++)
  3658. SaveFlag[i] = 0;
  3659. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3660. {
  3661. timer_1s.Enabled = false;
  3662. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3663. timer_1s.Enabled = true;
  3664. return;
  3665. }
  3666. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3667. {
  3668. timer_1s.Enabled = false;
  3669. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3670. timer_1s.Enabled = true;
  3671. return;
  3672. }
  3673. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3674. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3675. SaveFlag[3] = 0;
  3676. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3677. SaveFlag[5] = 0;
  3678. timer_1s.Enabled = false;
  3679. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3680. {
  3681. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3682. }
  3683. timer_1s.Enabled = true;
  3684. }
  3685. /// <summary>
  3686. /// 读取指定地址数据
  3687. /// </summary>
  3688. /// <param name="sender"></param>
  3689. /// <param name="e"></param>
  3690. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3691. {
  3692. var Address = new byte[4];
  3693. UInt32 Address_Begin;
  3694. UInt32 Addres_End;
  3695. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3696. richTextBox_RamFlasgData.Clear();
  3697. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3698. {
  3699. timer_1s.Enabled = false;
  3700. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3701. timer_1s.Enabled = true;
  3702. return;
  3703. }
  3704. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3705. {
  3706. timer_1s.Enabled = false;
  3707. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3708. timer_1s.Enabled = true;
  3709. return;
  3710. }
  3711. else
  3712. {
  3713. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3714. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3715. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3716. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3717. if (Addres_End < Address_Begin)
  3718. {
  3719. timer_1s.Enabled = false;
  3720. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3721. timer_1s.Enabled = true;
  3722. return;
  3723. }
  3724. else
  3725. {
  3726. var SendByte = new byte[8];
  3727. SendByte[0] = (byte)(Address_Begin >> 24);
  3728. SendByte[1] = (byte)(Address_Begin >> 16);
  3729. SendByte[2] = (byte)(Address_Begin >> 8);
  3730. SendByte[3] = (byte)(Address_Begin);
  3731. SendByte[4] = (byte)(Addres_End >> 24);
  3732. SendByte[5] = (byte)(Addres_End >> 16);
  3733. SendByte[6] = (byte)(Addres_End >> 8);
  3734. SendByte[7] = (byte)(Addres_End);
  3735. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3736. }
  3737. }
  3738. }
  3739. /// <summary>
  3740. /// 工作模式选择
  3741. /// </summary>
  3742. /// <param name="sender"></param>
  3743. /// <param name="e"></param>
  3744. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3745. {
  3746. var RunMode = new byte[1];
  3747. if (comboBox_WorkMode.Text == "配置模式")
  3748. RunMode[0] = 0x01;
  3749. else if (comboBox_WorkMode.Text == "调试模式")
  3750. RunMode[0] = 0x02;
  3751. else
  3752. RunMode[0] = 0x00;
  3753. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3754. }
  3755. /// <summary>
  3756. /// 助力档位选择
  3757. /// </summary>
  3758. /// <param name="sender"></param>
  3759. /// <param name="e"></param>
  3760. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3761. {
  3762. var CtrlCode = new byte[2];
  3763. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3764. CtrlCode[0] = 0x33;
  3765. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3766. CtrlCode[0] = 0x22;
  3767. else
  3768. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3769. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3770. CtrlCode[1] = 0xF1;
  3771. else
  3772. CtrlCode[1] = 0xF0;
  3773. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3774. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3775. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3776. }
  3777. /// <summary>
  3778. /// 仪表档位选择
  3779. /// </summary>
  3780. /// <param name="sender"></param>
  3781. /// <param name="e"></param>
  3782. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3783. {
  3784. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3785. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3786. }
  3787. /// <summary>
  3788. /// 生产模式初始化
  3789. /// </summary>
  3790. /// <param name="sender"></param>
  3791. /// <param name="e"></param>
  3792. private void button_FacModeInit_Click(object sender, EventArgs e)
  3793. {
  3794. var Code = new byte[5];
  3795. Code[0] = (byte)'C';
  3796. Code[1] = (byte)'L';
  3797. Code[2] = (byte)'E';
  3798. Code[3] = (byte)'A';
  3799. Code[4] = (byte)'R';
  3800. timer_1s.Enabled = false;
  3801. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3802. {
  3803. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3804. {
  3805. timer_1s.Enabled = true;
  3806. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3807. PowerOffAckStatus = false;
  3808. Delay_ms(250);
  3809. int TryCnt = 3;
  3810. while ((TryCnt--) >= 0)
  3811. {
  3812. if (!PowerOffAckStatus)
  3813. {
  3814. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3815. PowerOffAckStatus = false;
  3816. Delay_ms(250);
  3817. }
  3818. else break;
  3819. }
  3820. if (PowerOffAckStatus)
  3821. {
  3822. timer_1s.Enabled = false;
  3823. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3824. timer_1s.Enabled = true;
  3825. }
  3826. else
  3827. {
  3828. timer_1s.Enabled = false;
  3829. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3830. timer_1s.Enabled = true;
  3831. }
  3832. timer_1s.Enabled = true;
  3833. }
  3834. }
  3835. timer_1s.Enabled = true;
  3836. //清除历史测试记录
  3837. textBox_FacModeSensorADC0.Text = "";
  3838. textBox_FacModeSensorADC1.Text = "";
  3839. textBox_FacModeSensorADC2.Text = "";
  3840. textBox_FacModeSensorADC3.Text = "";
  3841. textBox_FacModeSensorADC4.Text = "";
  3842. LightSwitchStatus = false;
  3843. MotorRunStatus = false;
  3844. textBox_MotorSpeedPercent.Text = "5";
  3845. textBox_FacModeName.Text = "";
  3846. textBox_FacModeNum.Text = "";
  3847. textBox_FacModeHW.Text = "";
  3848. textBox_FacModeFW.Text = "";
  3849. }
  3850. /// <summary>
  3851. /// 生产模式读取传感器参数
  3852. /// </summary>
  3853. /// <param name="sender"></param>
  3854. /// <param name="e"></param>
  3855. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3856. {
  3857. richTextBox_SensorParam.Clear();
  3858. textBox_FacModeSensorADC0.Text = "";
  3859. textBox_FacModeSensorADC1.Text = "";
  3860. textBox_FacModeSensorADC2.Text = "";
  3861. textBox_FacModeSensorADC3.Text = "";
  3862. textBox_FacModeSensorADC4.Text = "";
  3863. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3864. }
  3865. /// <summary>
  3866. /// 生产模式传感器标定1
  3867. /// </summary>
  3868. /// <param name="sender"></param>
  3869. /// <param name="e"></param>
  3870. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  3871. {
  3872. var ConfigParam = new byte[4];
  3873. for (int i = 0; i < 4; i++)
  3874. ConfigParam[i] = 0;
  3875. ushort uwDataTemp = 0;
  3876. try
  3877. {
  3878. uwDataTemp = 1;//负载序号
  3879. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3880. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3881. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  3882. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3883. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3884. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3885. Delay_ms(200);
  3886. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3887. }
  3888. catch (Exception)
  3889. {
  3890. timer_1s.Enabled = false;
  3891. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3892. timer_1s.Enabled = true;
  3893. }
  3894. }
  3895. /// <summary>
  3896. /// 生产模式传感器标定2
  3897. /// </summary>
  3898. /// <param name="sender"></param>
  3899. /// <param name="e"></param>
  3900. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  3901. {
  3902. var ConfigParam = new byte[4];
  3903. for (int i = 0; i < 4; i++)
  3904. ConfigParam[i] = 0;
  3905. ushort uwDataTemp = 0;
  3906. try
  3907. {
  3908. uwDataTemp = 2;//负载序号
  3909. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3910. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3911. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  3912. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3913. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3914. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3915. Delay_ms(200);
  3916. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3917. }
  3918. catch (Exception)
  3919. {
  3920. timer_1s.Enabled = false;
  3921. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3922. timer_1s.Enabled = true;
  3923. }
  3924. }
  3925. /// <summary>
  3926. /// 生产模式传感器标定3
  3927. /// </summary>
  3928. /// <param name="sender"></param>
  3929. /// <param name="e"></param>
  3930. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  3931. {
  3932. var ConfigParam = new byte[4];
  3933. for (int i = 0; i < 4; i++)
  3934. ConfigParam[i] = 0;
  3935. ushort uwDataTemp = 0;
  3936. try
  3937. {
  3938. uwDataTemp = 3;//负载序号
  3939. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3940. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3941. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  3942. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3943. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3945. Delay_ms(200);
  3946. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3947. }
  3948. catch (Exception)
  3949. {
  3950. timer_1s.Enabled = false;
  3951. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3952. timer_1s.Enabled = true;
  3953. }
  3954. }
  3955. /// <summary>
  3956. /// 生产模式传感器标定3
  3957. /// </summary>
  3958. /// <param name="sender"></param>
  3959. /// <param name="e"></param>
  3960. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  3961. {
  3962. var ConfigParam = new byte[4];
  3963. for (int i = 0; i < 4; i++)
  3964. ConfigParam[i] = 0;
  3965. ushort uwDataTemp = 0;
  3966. try
  3967. {
  3968. uwDataTemp = 4;//负载序号
  3969. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3970. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3971. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  3972. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3973. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3974. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3975. Delay_ms(200);
  3976. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3977. }
  3978. catch (Exception)
  3979. {
  3980. timer_1s.Enabled = false;
  3981. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3982. timer_1s.Enabled = true;
  3983. }
  3984. }
  3985. /// <summary>
  3986. /// 生产模式开关灯
  3987. /// </summary>
  3988. /// <param name="sender"></param>
  3989. /// <param name="e"></param>
  3990. bool LightSwitchStatus = false;
  3991. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  3992. {
  3993. var CtrlCode = new byte[2];
  3994. CtrlCode[0] = 0x00;
  3995. if (LightSwitchStatus)
  3996. {
  3997. CtrlCode[1] = 0xF0;
  3998. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  3999. }
  4000. else
  4001. {
  4002. CtrlCode[1] = 0xF1;
  4003. button_FacModeLightSW.BackColor = Color.Yellow;
  4004. }
  4005. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4006. {
  4007. LightSwitchStatus = !LightSwitchStatus;
  4008. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4009. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4010. }
  4011. }
  4012. /// <summary>
  4013. /// 生产模式电机控制
  4014. /// </summary>
  4015. /// <param name="sender"></param>
  4016. /// <param name="e"></param>
  4017. bool MotorRunStatus = false;
  4018. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4019. {
  4020. string DebugDefaultInfo = "";
  4021. //获取调试信息
  4022. if (richTextBox_DebugParam.Text == string.Empty)
  4023. {
  4024. richTextBox_DebugParam.Clear();
  4025. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4026. }
  4027. Delay_ms(200);
  4028. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4029. //获取参数
  4030. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4031. if (strDataTemp.Length != 29)
  4032. {
  4033. timer_1s.Enabled = false;
  4034. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4035. timer_1s.Enabled = true;
  4036. return;
  4037. }
  4038. //设置参数
  4039. var ConfigParam = new byte[60];
  4040. for (int i = 0; i < 60; i++)
  4041. ConfigParam[i] = 0;
  4042. ConfigParam[0] = 0x00;
  4043. ushort uwDataTemp = 0;
  4044. if (!MotorRunStatus) //停止状态
  4045. {
  4046. //设置速度环
  4047. strDataTemp[0] = "整体运行模式=3";
  4048. //发送数据
  4049. try
  4050. {
  4051. for (int i = 0; i < strDataTemp.Length; i++)
  4052. {
  4053. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4054. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4055. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4056. }
  4057. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4058. return;
  4059. }
  4060. catch (Exception)
  4061. {
  4062. timer_1s.Enabled = false;
  4063. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4064. timer_1s.Enabled = true;
  4065. }
  4066. Delay_ms(200);
  4067. //设置转速百分比100%
  4068. textBox_MotorSpeedPercent.Text = "100";
  4069. ConfigParam[0] = (byte)100;
  4070. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4071. MotorRunStatus = !MotorRunStatus;
  4072. button_FacModeMotorRun.BackColor = Color.Yellow;
  4073. Delay_ms(200);
  4074. //电机进入配置模式
  4075. var RunMode = new byte[1];
  4076. RunMode[0] = 0x01;
  4077. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4078. }
  4079. else //运转状态
  4080. {
  4081. //设置转速百分比0%
  4082. textBox_MotorSpeedPercent.Text = "0";
  4083. ConfigParam[0] = (byte)0;
  4084. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4085. MotorRunStatus = !MotorRunStatus;
  4086. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4087. Delay_ms(200);
  4088. //还原为原始值
  4089. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4090. try
  4091. {
  4092. for (int i = 0; i < strDataTemp.Length; i++)
  4093. {
  4094. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4095. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4096. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4097. }
  4098. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4099. return;
  4100. }
  4101. catch (Exception)
  4102. {
  4103. timer_1s.Enabled = false;
  4104. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4105. timer_1s.Enabled = true;
  4106. }
  4107. Delay_ms(200);
  4108. //电机退出配置模式
  4109. var RunMode = new byte[1];
  4110. RunMode[0] = 0x00;
  4111. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4112. }
  4113. }
  4114. /// <summary>
  4115. /// 生产模式写入型号
  4116. /// </summary>
  4117. /// <param name="sender"></param>
  4118. /// <param name="e"></param>
  4119. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4120. {
  4121. string Mode = textBox_FacModeName.Text;
  4122. var ModeArray = new byte[16];
  4123. for (ushort i = 0; i < Mode.Length; i++)
  4124. {
  4125. ModeArray[i] = (byte)Mode[i];
  4126. }
  4127. if (Mode.Length < 16)
  4128. {
  4129. ModeArray[Mode.Length] = (byte)'.';
  4130. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4131. {
  4132. ModeArray[Mode.Length + 1 + i] = 0x20;
  4133. }
  4134. }
  4135. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4136. }
  4137. /// <summary>
  4138. /// 生产模式写入SN
  4139. /// </summary>
  4140. /// <param name="sender"></param>
  4141. /// <param name="e"></param>
  4142. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4143. {
  4144. string SN = textBox_FacModeNum.Text;
  4145. var SNArray = new byte[16];
  4146. for (ushort i = 0; i < SN.Length; i++)
  4147. {
  4148. SNArray[i] = (byte)SN[i];
  4149. }
  4150. if (SN.Length < 16)
  4151. {
  4152. SNArray[SN.Length] = (byte)'.';
  4153. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4154. {
  4155. SNArray[SN.Length + 1 + i] = 0x20;
  4156. }
  4157. }
  4158. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4159. }
  4160. /// <summary>
  4161. /// 生产模式读取版本信息
  4162. /// </summary>
  4163. /// <param name="sender"></param>
  4164. /// <param name="e"></param>
  4165. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4166. {
  4167. textBox_Model.Text = "---";
  4168. textBox_SN.Text = "---";
  4169. textBox_HW.Text = "---";
  4170. textBox_FW.Text = "---";
  4171. textBox_SP.Text = "---";
  4172. textBox_OBC_ReadModel.Text = "---";
  4173. textBox_OBC_ReadSN.Text = "---";
  4174. textBox_OBC_ReadHW.Text = "---";
  4175. textBox_OBC_ReadFW.Text = "---";
  4176. textBox_OBC_ReadSP.Text = "---";
  4177. textBox_FacModeName.Text = "---";
  4178. textBox_FacModeNum.Text = "---";
  4179. textBox_FacModeHW.Text = "---";
  4180. textBox_FacModeFW.Text = "---";
  4181. textBox_FacModeSP.Text = "---";
  4182. textBox_FacModeGit.Text = "---";
  4183. Class_Motor_Ver.Mode = "---";
  4184. Class_Motor_Ver.SN = "---";
  4185. Class_Motor_Ver.HW = "---";
  4186. Class_Motor_Ver.FW = "---";
  4187. Class_Motor_Ver.Special = "---";
  4188. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4189. }
  4190. /// <summary>
  4191. /// 生产模式写入生产信息
  4192. /// </summary>
  4193. /// <param name="sender"></param>
  4194. /// <param name="e"></param>
  4195. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4196. {
  4197. var MACArray = new byte[32];
  4198. string MacDefaultInfo = "";
  4199. string MacAddDefaultInfo = "";
  4200. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4201. string MacPPDefaultInfo = "";
  4202. do
  4203. {
  4204. //填入生产商
  4205. if (toolStripTextBox_MAC.Text == string.Empty)
  4206. {
  4207. break;
  4208. }
  4209. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4210. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4211. {
  4212. MACArray[i] = (byte)MacDefaultInfo[i];
  4213. }
  4214. if (MacDefaultInfo.Length < 8)
  4215. {
  4216. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4217. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4218. {
  4219. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4220. }
  4221. }
  4222. //填入生产地
  4223. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4224. {
  4225. break;
  4226. }
  4227. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4228. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4229. {
  4230. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4231. }
  4232. if (MacAddDefaultInfo.Length < 8)
  4233. {
  4234. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4235. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4236. {
  4237. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4238. }
  4239. }
  4240. //填入生产日期
  4241. if (toolStripTextBox_MACDate.Text == string.Empty)
  4242. {
  4243. break;
  4244. }
  4245. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4246. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4247. {
  4248. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4249. }
  4250. if (MacDateDefaultInfo.Length < 8)
  4251. {
  4252. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4253. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4254. {
  4255. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4256. }
  4257. }
  4258. //填入产品标识
  4259. if (toolStripTextBox_MACPD.Text == string.Empty)
  4260. {
  4261. break;
  4262. }
  4263. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4264. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4265. {
  4266. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4267. }
  4268. if (MacPPDefaultInfo.Length < 8)
  4269. {
  4270. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4271. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4272. {
  4273. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4274. }
  4275. }
  4276. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4277. return;
  4278. } while (false);
  4279. timer_1s.Enabled = false;
  4280. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4281. timer_1s.Enabled = true;
  4282. }
  4283. /// <summary>
  4284. /// 生产模式保存测试页面
  4285. /// </summary>
  4286. /// <param name="sender"></param>
  4287. /// <param name="e"></param>
  4288. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4289. {
  4290. Button_FacModeSaveResult.Text = "存储中…";
  4291. string[] AssistParams = new string[15];
  4292. do
  4293. {
  4294. //读取一次马达参数
  4295. richTextBox_MotorParam.Clear();
  4296. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4297. Delay_ms(100);
  4298. //读取一次整车参数
  4299. richTextBox_BikeParam.Clear();
  4300. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4301. Delay_ms(100);
  4302. //读取一次控制参数
  4303. richTextBox_ControlParam.Clear();
  4304. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4305. Delay_ms(100);
  4306. //查询传感器
  4307. richTextBox_SensorParam.Clear();
  4308. textBox_FacModeSensorADC0.Text = "";
  4309. textBox_FacModeSensorADC1.Text = "";
  4310. textBox_FacModeSensorADC2.Text = "";
  4311. textBox_FacModeSensorADC3.Text = "";
  4312. textBox_FacModeSensorADC4.Text = "";
  4313. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4314. Delay_ms(100);
  4315. //读取15次助力参数
  4316. for (int i = 1; i <= 15; i++)
  4317. {
  4318. var ConfigParam = new byte[4];
  4319. richTextBox_AssistParam.Clear();
  4320. ConfigParam[0] = (byte)(i & 0xFF);
  4321. ConfigParam[1] = (byte)(i >> 8);
  4322. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4323. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4324. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4325. Delay_ms(200);
  4326. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4327. }
  4328. //读取一次调试信息
  4329. richTextBox_DebugParam.Clear();
  4330. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4331. Delay_ms(100);
  4332. //读取一次历史信息
  4333. richTextBox_Record.Clear();
  4334. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4335. Delay_ms(100);
  4336. //读取一次电机运行信息
  4337. var CtrlCode = new byte[2];
  4338. CtrlCode[0] = 0x00;
  4339. CtrlCode[1] = 0xF0;
  4340. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4341. Delay_ms(100);
  4342. //读取一次版本信息
  4343. textBox_Model.Text = "---";
  4344. textBox_SN.Text = "---";
  4345. textBox_HW.Text = "---";
  4346. textBox_FW.Text = "---";
  4347. textBox_OBC_ReadModel.Text = "---";
  4348. textBox_OBC_ReadSN.Text = "---";
  4349. textBox_OBC_ReadHW.Text = "---";
  4350. textBox_OBC_ReadFW.Text = "---";
  4351. textBox_FacModeName.Text = "---";
  4352. textBox_FacModeNum.Text = "---";
  4353. textBox_FacModeHW.Text = "---";
  4354. textBox_FacModeFW.Text = "---";
  4355. Class_Motor_Ver.Mode = "---";
  4356. Class_Motor_Ver.SN = "---";
  4357. Class_Motor_Ver.HW = "---";
  4358. Class_Motor_Ver.FW = "---";
  4359. Class_Motor_Ver.Special = "---";
  4360. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4361. Delay_ms(100);
  4362. //读取一次生产信息
  4363. textBox_MAC.Text = "";
  4364. textBox_MACAdd.Text = "";
  4365. textBox_MACDate.Text = "";
  4366. textBox_PP.Text = "";
  4367. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4368. Delay_ms(100);
  4369. //读取一次自定义信息
  4370. textBox_User1.Text = "---";
  4371. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4372. Delay_ms(100);
  4373. textBox_User2.Text = "---";
  4374. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4375. Delay_ms(100);
  4376. textBox_User3.Text = "---";
  4377. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4378. Delay_ms(100);
  4379. //读取一次密钥
  4380. textBox_Key.Text = "---";
  4381. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4382. Delay_ms(100);
  4383. //读取一次存储标志
  4384. radioButton_EE_SaveYes.Checked = false;
  4385. radioButton_EE_SaveNo.Checked = false;
  4386. radioButton_SIP_SaveYes.Checked = false;
  4387. radioButton_SIP_SaveNo.Checked = false;
  4388. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4389. Delay_ms(100);
  4390. //读取一次MOS内阻校准参数
  4391. foreach (Control c in groupBox21.Controls)
  4392. {
  4393. if (c is TextBox)
  4394. c.Text = "";
  4395. }
  4396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4397. Delay_ms(100);
  4398. //提示检查
  4399. #if false
  4400. timer_1s.Enabled = false;
  4401. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4402. {
  4403. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4404. timer_1s.Enabled = true;
  4405. return;
  4406. }
  4407. timer_1s.Enabled = true;
  4408. Delay_ms(200);
  4409. #endif
  4410. //判断数据是否有效
  4411. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4412. {
  4413. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4414. break;
  4415. }
  4416. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4417. {
  4418. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4419. break;
  4420. }
  4421. //设置文件存储路径
  4422. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4423. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4424. Save_Path += PD_PathName;
  4425. if (!Directory.Exists(Save_Path))
  4426. Directory.CreateDirectory(Save_Path);
  4427. //保存页面
  4428. string PIC_SaveFileName = "";
  4429. Double scaleX = PrimaryScreen.ScaleX;
  4430. Double scaleY = PrimaryScreen.ScaleY;
  4431. //保存页面
  4432. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4433. Graphics g = Graphics.FromImage(bit);
  4434. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4435. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4436. bit.Save(PIC_SaveFileName);
  4437. //保存数据
  4438. string DataFileName = "";
  4439. string FileInfo = "";
  4440. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4441. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4442. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4443. FileInfo += "\r\n";
  4444. FileInfo += "[电机信息]\r\n";
  4445. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4446. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4447. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4448. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4449. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4450. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4451. FileInfo += "\r\n";
  4452. FileInfo += "[马达参数]\r\n";
  4453. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4454. FileInfo += "\r\n";
  4455. FileInfo += "[整车参数]\r\n";
  4456. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4457. FileInfo += "\r\n";
  4458. FileInfo += "[控制参数]\r\n";
  4459. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4460. FileInfo += "\r\n";
  4461. FileInfo += "[传感器参数]\r\n";
  4462. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4463. FileInfo += "\r\n";
  4464. FileInfo += "[助力参数]\r\n";
  4465. for(int i=0;i<15;i++)
  4466. {
  4467. FileInfo += AssistParams[i] + "\r\n";
  4468. }
  4469. FileInfo += "[调试参数]\r\n";
  4470. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4471. FileInfo += "\r\n";
  4472. FileInfo += "[历史信息]\r\n";
  4473. FileInfo += richTextBox_Record.Text + "\r\n";
  4474. FileInfo += "\r\n";
  4475. FileInfo += "[MOS内阻校准参数]\r\n";
  4476. FileInfo += textBox_MOS_K1.Text + ", ";
  4477. FileInfo += textBox_MOS_K2.Text + ", ";
  4478. FileInfo += textBox_MOS_K3.Text + ", ";
  4479. FileInfo += textBox_MOS_K4.Text + ", ";
  4480. FileInfo += textBox_MOS_K5.Text + ", ";
  4481. FileInfo += textBox_MOS_R1.Text + ", ";
  4482. FileInfo += textBox_MOS_R2.Text + ", ";
  4483. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4484. FileInfo += "\r\n";
  4485. FileInfo += "[生产信息]\r\n";
  4486. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4487. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4488. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4489. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4490. FileInfo += "\r\n";
  4491. FileInfo += "[自定义信息]\r\n";
  4492. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4493. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4494. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4495. FileInfo += "\r\n";
  4496. FileInfo += "[校验密钥]\r\n";
  4497. FileInfo += textBox_Key.Text + "\r\n";
  4498. FileInfo += "\r\n";
  4499. FileInfo += "[存储标志]\r\n";
  4500. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4501. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4502. FileInfo += "\r\n";
  4503. FileInfo += Local_HdInformation;
  4504. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4505. Delay_ms(1000);
  4506. timer_1s.Enabled = false;
  4507. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4508. timer_1s.Enabled = true;
  4509. //数据上传
  4510. if (myFtp.IsNetConnected == true)
  4511. {
  4512. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4513. //检查路径
  4514. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4515. {
  4516. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4517. }
  4518. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4519. {
  4520. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4521. }
  4522. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4523. {
  4524. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4525. }
  4526. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4527. {
  4528. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4529. }
  4530. //上传文件
  4531. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4532. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4533. if ((result1 & result2) == true)
  4534. {
  4535. timer_1s.Enabled = false;
  4536. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4537. timer_1s.Enabled = true;
  4538. }
  4539. else
  4540. {
  4541. timer_1s.Enabled = false;
  4542. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4543. timer_1s.Enabled = true;
  4544. }
  4545. }
  4546. else
  4547. {
  4548. timer_1s.Enabled = false;
  4549. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4550. timer_1s.Enabled = true;
  4551. }
  4552. Button_FacModeSaveResult.Text = "保存数据";
  4553. return;
  4554. } while (false);
  4555. timer_1s.Enabled = false;
  4556. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4557. timer_1s.Enabled = true;
  4558. Button_FacModeSaveResult.Text = "保存数据";
  4559. }
  4560. /// <summary>
  4561. /// 工具箱页面保存
  4562. /// </summary>
  4563. /// <param name="sender"></param>
  4564. /// <param name="e"></param>
  4565. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4566. {
  4567. Double scaleX = PrimaryScreen.ScaleX;
  4568. Double scaleY = PrimaryScreen.ScaleY;
  4569. //保存页面
  4570. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4571. Graphics g = Graphics.FromImage(bit);
  4572. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4573. SaveFileDialog sf = new SaveFileDialog();
  4574. sf.Title = "页面保存";
  4575. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4576. sf.Filter = "图片|*.png";
  4577. timer_1s.Enabled = false;
  4578. if (sf.ShowDialog() == DialogResult.OK)
  4579. {
  4580. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4581. }
  4582. timer_1s.Enabled = true;
  4583. }
  4584. /// <summary>
  4585. /// 生产模式关机
  4586. /// </summary>
  4587. /// <param name="sender"></param>
  4588. /// <param name="e"></param>
  4589. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4590. {
  4591. var Code_Off = new byte[5];
  4592. var Code_Reset = new byte[5];
  4593. Code_Off[0] = (byte)'O';
  4594. Code_Off[1] = (byte)'F';
  4595. Code_Off[2] = (byte)'F';
  4596. Code_Off[3] = (byte)'.';
  4597. Code_Off[4] = (byte)'.';
  4598. Code_Reset[0] = (byte)'R';
  4599. Code_Reset[1] = (byte)'E';
  4600. Code_Reset[2] = (byte)'S';
  4601. Code_Reset[3] = (byte)'E';
  4602. Code_Reset[4] = (byte)'T';
  4603. timer_1s.Enabled = false;
  4604. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4605. {
  4606. timer_1s.Enabled = true;
  4607. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4608. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4609. PowerOffAckStatus = false;
  4610. Delay_ms(250);
  4611. int TryCnt = 3;
  4612. while ((TryCnt--) >= 0)
  4613. {
  4614. if (!PowerOffAckStatus)
  4615. {
  4616. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4617. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4618. PowerOffAckStatus = false;
  4619. Delay_ms(250);
  4620. }
  4621. else break;
  4622. }
  4623. if (PowerOffAckStatus)
  4624. {
  4625. timer_1s.Enabled = false;
  4626. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4627. timer_1s.Enabled = true;
  4628. }
  4629. else
  4630. {
  4631. timer_1s.Enabled = false;
  4632. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4633. timer_1s.Enabled = true;
  4634. }
  4635. }
  4636. timer_1s.Enabled = true;
  4637. }
  4638. //仪表电源键按下
  4639. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4640. {
  4641. var Code = new byte[2];
  4642. Code[0] = 0;
  4643. Code[1] = 0b00100000;
  4644. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4645. }
  4646. /// <summary>
  4647. /// 仪表加键按下
  4648. /// </summary>
  4649. /// <param name="sender"></param>
  4650. /// <param name="e"></param>
  4651. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4652. {
  4653. var Code = new byte[2];
  4654. Code[0] = 0;
  4655. Code[1] = 0b00010000;
  4656. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4657. }
  4658. /// <summary>
  4659. /// 仪表减键按下
  4660. /// </summary>
  4661. /// <param name="sender"></param>
  4662. /// <param name="e"></param>
  4663. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4664. {
  4665. var Code = new byte[2];
  4666. Code[0] = 0;
  4667. Code[1] = 0b00001000;
  4668. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4669. }
  4670. /// <summary>
  4671. /// 仪表Walk键按下
  4672. /// </summary>
  4673. /// <param name="sender"></param>
  4674. /// <param name="e"></param>
  4675. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4676. {
  4677. var Code = new byte[2];
  4678. Code[0] = 0;
  4679. Code[1] = 0b00000100;
  4680. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4681. }
  4682. /// <summary>
  4683. /// 仪表Light键按下
  4684. /// </summary>
  4685. /// <param name="sender"></param>
  4686. /// <param name="e"></param>
  4687. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4688. {
  4689. var Code = new byte[2];
  4690. Code[0] = 0;
  4691. Code[1] = 0b00000010;
  4692. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4693. }
  4694. /// <summary>
  4695. /// 仪表Set键按下
  4696. /// </summary>
  4697. /// <param name="sender"></param>
  4698. /// <param name="e"></param>
  4699. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4700. {
  4701. var Code = new byte[2];
  4702. Code[0] = 0;
  4703. Code[1] = 0b00000001;
  4704. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4705. }
  4706. /// <summary>
  4707. /// 导出电机故障日志
  4708. /// </summary>
  4709. /// <param name="sender"></param>
  4710. /// <param name="e"></param>
  4711. private void button_ExportLog_Click(object sender, EventArgs e)
  4712. {
  4713. var Address = new byte[4];
  4714. UInt32 Address_Begin;
  4715. UInt32 Addres_End;
  4716. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4717. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4718. richTextBox_Record.Clear();
  4719. textBox_LogAddrBegin.ReadOnly = true;
  4720. textBox_LogAddrEnd.ReadOnly = true;
  4721. if (!mySerialProcess.mySerial.IsOpen)
  4722. {
  4723. timer_1s.Enabled = false;
  4724. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4725. timer_1s.Enabled = true;
  4726. return;
  4727. }
  4728. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4729. {
  4730. timer_1s.Enabled = false;
  4731. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4732. timer_1s.Enabled = true;
  4733. return;
  4734. }
  4735. else
  4736. {
  4737. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4738. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4739. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4740. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4741. if (Addres_End <= Address_Begin)
  4742. {
  4743. timer_1s.Enabled = false;
  4744. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4745. timer_1s.Enabled = true;
  4746. return;
  4747. }
  4748. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4749. {
  4750. timer_1s.Enabled = false;
  4751. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4752. timer_1s.Enabled = true;
  4753. return;
  4754. }
  4755. else
  4756. {
  4757. UInt32 ReadCount = 0;
  4758. button_ExportLog.Text = "导出中...";
  4759. button_ExportLog.Enabled = false;
  4760. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4761. for (ushort i = 0; i < ReadCount; i++)
  4762. {
  4763. var SendByte = new byte[8];
  4764. UInt32 Address_Temp_Begin;
  4765. UInt32 Address_Temp_End;
  4766. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4767. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4768. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4769. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4770. SendByte[3] = (byte)(Address_Temp_Begin);
  4771. Address_Temp_End = Address_Temp_Begin + 127;
  4772. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4773. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4774. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4775. SendByte[7] = (byte)(Address_Temp_End);
  4776. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4777. Delay_ms(200);//Thread.Sleep(200);
  4778. }
  4779. button_ExportLog.Text = "导出日志";
  4780. button_ExportLog.Enabled = true;
  4781. }
  4782. }
  4783. }
  4784. /// <summary>
  4785. /// 保存日志信息
  4786. /// </summary>
  4787. /// <param name="sender"></param>
  4788. /// <param name="e"></param>
  4789. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4790. {
  4791. string SaveInfo = "";
  4792. if (richTextBox_Record.Text == string.Empty)
  4793. {
  4794. timer_1s.Enabled = false;
  4795. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4796. timer_1s.Enabled = true;
  4797. return;
  4798. }
  4799. //获取保存信息
  4800. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4801. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4802. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4803. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4804. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4805. SaveInfo += "\r\n";
  4806. SaveInfo += richTextBox_Record.Text;
  4807. //设置保存路径和文件名
  4808. SaveFileDialog sf = new SaveFileDialog();
  4809. sf.Title = "数据保存";
  4810. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4811. sf.FileName.Replace(" ", "");
  4812. sf.Filter = "日志|*.ttlog";
  4813. if (sf.ShowDialog() == DialogResult.OK)
  4814. {
  4815. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4816. }
  4817. }
  4818. /// <summary>
  4819. /// 双击修改日志起始地址
  4820. /// </summary>
  4821. /// <param name="sender"></param>
  4822. /// <param name="e"></param>
  4823. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4824. {
  4825. textBox_LogAddrBegin.ReadOnly = false;
  4826. }
  4827. /// <summary>
  4828. /// 双击修改日志结束地址
  4829. /// </summary>
  4830. /// <param name="sender"></param>
  4831. /// <param name="e"></param>
  4832. private void label88_DoubleClick(object sender, EventArgs e)
  4833. {
  4834. textBox_LogAddrEnd.ReadOnly = false;
  4835. }
  4836. /// <summary>
  4837. /// 存储器自动读取选择
  4838. /// </summary>
  4839. /// <param name="sender"></param>
  4840. /// <param name="e"></param>
  4841. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4842. {
  4843. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4844. {
  4845. //检查串口是否打开
  4846. if (!mySerialProcess.mySerial.IsOpen)
  4847. {
  4848. timer_1s.Enabled = false;
  4849. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4850. timer_1s.Enabled = true;
  4851. checkBox_ReadRanFlash_AutoSW.Checked = false;
  4852. return;
  4853. }
  4854. }
  4855. }
  4856. /// <summary>
  4857. /// 系统开机按钮
  4858. /// </summary>
  4859. /// <param name="sender"></param>
  4860. /// <param name="e"></param>
  4861. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4862. {
  4863. byte[] Data = new byte[1];
  4864. Data[0] = 0xF1;
  4865. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4866. }
  4867. /// <summary>
  4868. /// 系统关机按钮
  4869. /// </summary>
  4870. /// <param name="sender"></param>
  4871. /// <param name="e"></param>
  4872. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4873. {
  4874. byte[] Data = new byte[1];
  4875. Data[0] = 0xF0;
  4876. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  4877. }
  4878. /// <summary>
  4879. /// 连接开机选择
  4880. /// </summary>
  4881. /// <param name="sender"></param>
  4882. /// <param name="e"></param>
  4883. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4884. {
  4885. //输入用户名
  4886. EnterForm1.ShowDialog();
  4887. try
  4888. {
  4889. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4890. {
  4891. if (EnterForm1.comboBox_User.Text == "管理员")
  4892. {
  4893. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  4894. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4895. }
  4896. else
  4897. {
  4898. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4899. }
  4900. }
  4901. else
  4902. {
  4903. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4904. }
  4905. }
  4906. catch (Exception)
  4907. {
  4908. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4909. }
  4910. }
  4911. /// <summary>
  4912. /// 断开关机选择
  4913. /// </summary>
  4914. /// <param name="sender"></param>
  4915. /// <param name="e"></param>
  4916. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4917. {
  4918. //输入用户名
  4919. EnterForm1.ShowDialog();
  4920. try
  4921. {
  4922. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4923. {
  4924. if (EnterForm1.comboBox_User.Text == "管理员")
  4925. {
  4926. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  4927. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4928. }
  4929. else
  4930. {
  4931. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4932. }
  4933. }
  4934. else
  4935. {
  4936. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4937. }
  4938. }
  4939. catch (Exception)
  4940. {
  4941. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4942. }
  4943. }
  4944. /// <summary>
  4945. /// 识别通讯盒选择
  4946. /// </summary>
  4947. /// <param name="sender"></param>
  4948. /// <param name="e"></param>
  4949. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  4950. {
  4951. //输入用户名
  4952. EnterForm1.ShowDialog();
  4953. try
  4954. {
  4955. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  4956. {
  4957. if (EnterForm1.comboBox_User.Text == "管理员")
  4958. {
  4959. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  4960. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  4961. }
  4962. else
  4963. {
  4964. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4965. }
  4966. }
  4967. else
  4968. {
  4969. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4970. }
  4971. }
  4972. catch (Exception)
  4973. {
  4974. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4975. }
  4976. }
  4977. /// <summary>
  4978. /// 将配置信息导出为cfg文件
  4979. /// </summary>
  4980. private void ConfigFileSave(bool DeleteFlag, string FileName)
  4981. {
  4982. if (DeleteFlag)
  4983. {
  4984. if (File.Exists(FileName))
  4985. File.Delete(FileName);
  4986. }
  4987. string CfgFileInfo = "";
  4988. CfgFileInfo += "[PortSet]" + "\r\n";
  4989. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  4990. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  4991. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4992. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4993. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  4994. CfgFileInfo += "\r\n";
  4995. CfgFileInfo += "[Option]" + "\r\n";
  4996. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  4997. CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
  4998. CfgFileInfo += "\r\n";
  4999. CfgFileInfo += "[ServerSet]" + "\r\n";
  5000. CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
  5001. CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
  5002. CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
  5003. CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
  5004. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5005. CfgFileInfo += "\r\n";
  5006. CfgFileInfo += "[MacInfo]" + "\r\n";
  5007. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5008. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5009. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5010. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5011. CfgFileInfo += "\r\n";
  5012. CfgFileInfo += "[LogAddress]" + "\r\n";
  5013. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5014. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5015. CfgFileInfo += "\r\n";
  5016. CfgFileInfo += "[MotorType]" + "\r\n";
  5017. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5018. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5019. CfgFileInfo += "\r\n";
  5020. CfgFileInfo += "[CheckValue]" + "\r\n";
  5021. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5022. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5023. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5024. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5025. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5026. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5027. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5028. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5029. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5030. CfgFileInfo += "\r\n";
  5031. CfgFileInfo += "[MosCalK]" + "\r\n";
  5032. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5033. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5034. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5035. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5036. CfgFileInfo += "\r\n";
  5037. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5038. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5039. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5040. CfgFileInfo += "\r\n";
  5041. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5042. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5043. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5044. }
  5045. /// <summary>
  5046. /// 配置状态更新,点击时保存
  5047. /// </summary>
  5048. private void ConfigFileSave_Click(object sender, EventArgs e)
  5049. {
  5050. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5051. }
  5052. /// <summary>
  5053. /// 文本框修改结束,回车保存
  5054. /// </summary>
  5055. /// <param name="sender"></param>
  5056. /// <param name="e"></param>
  5057. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5058. {
  5059. if (e.KeyCode == Keys.Enter)
  5060. {
  5061. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5062. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5063. }
  5064. }
  5065. /// <summary>
  5066. /// 允许离线使用
  5067. /// </summary>
  5068. /// <param name="sender"></param>
  5069. /// <param name="e"></param>
  5070. private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
  5071. {
  5072. //输入用户名
  5073. EnterForm1.ShowDialog();
  5074. try
  5075. {
  5076. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5077. {
  5078. if (EnterForm1.comboBox_User.Text == "管理员")
  5079. {
  5080. 允许ToolStripMenuItem.Checked = true;
  5081. 不允许ToolStripMenuItem.Checked = false;
  5082. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5083. }
  5084. else
  5085. {
  5086. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5087. 允许ToolStripMenuItem.Checked = false;
  5088. 不允许ToolStripMenuItem.Checked = true;
  5089. }
  5090. }
  5091. else
  5092. {
  5093. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5094. 允许ToolStripMenuItem.Checked = false;
  5095. 不允许ToolStripMenuItem.Checked = true;
  5096. }
  5097. }
  5098. catch (Exception)
  5099. {
  5100. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5101. 允许ToolStripMenuItem.Checked = false;
  5102. 不允许ToolStripMenuItem.Checked = true;
  5103. }
  5104. }
  5105. /// <summary>
  5106. /// 不允许离线使用
  5107. /// </summary>
  5108. /// <param name="sender"></param>
  5109. /// <param name="e"></param>
  5110. private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
  5111. {
  5112. 允许ToolStripMenuItem.Checked = false;
  5113. 不允许ToolStripMenuItem.Checked = true;
  5114. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5115. }
  5116. /// <summary>
  5117. /// 弹出扫码按钮
  5118. /// </summary>
  5119. /// <param name="sender"></param>
  5120. /// <param name="e"></param>
  5121. private void button_ScanCode_Click(object sender, EventArgs e)
  5122. {
  5123. Scan scan_form = new Scan();
  5124. scan_form.ShowDialog();
  5125. do
  5126. {
  5127. if (scan_form.textBox_Scan.Text == string.Empty)
  5128. {
  5129. timer_1s.Enabled = false;
  5130. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5131. timer_1s.Enabled = true;
  5132. break;
  5133. }
  5134. string ScanInfo = scan_form.textBox_Scan.Text;
  5135. string regexInfo = "";
  5136. string[] InfoList = { "" };
  5137. try
  5138. {
  5139. if (中置电机ToolStripMenuItem.Checked == true)
  5140. {
  5141. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5142. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5143. }
  5144. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5145. {
  5146. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5147. string Model = InfoList[0];
  5148. string Spec = InfoList[1];
  5149. string Sn = InfoList[2];
  5150. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5151. InfoList[1] = Sn;
  5152. }
  5153. }
  5154. catch (Exception)
  5155. {
  5156. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5157. return;
  5158. }
  5159. if (InfoList.Length >= 2)
  5160. {
  5161. //写入型号
  5162. textBox_FacModeName.Text = InfoList[0];
  5163. string Mode = textBox_FacModeName.Text;
  5164. var ModeArray = new byte[16];
  5165. for (ushort i = 0; i < Mode.Length; i++)
  5166. {
  5167. ModeArray[i] = (byte)Mode[i];
  5168. }
  5169. if (Mode.Length < 16)
  5170. {
  5171. ModeArray[Mode.Length] = (byte)'.';
  5172. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5173. {
  5174. ModeArray[Mode.Length + 1 + i] = 0x20;
  5175. }
  5176. }
  5177. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5178. //写入SN
  5179. textBox_FacModeNum.Text = InfoList[1];
  5180. string SN = textBox_FacModeNum.Text;
  5181. var SNArray = new byte[16];
  5182. for (ushort i = 0; i < SN.Length; i++)
  5183. {
  5184. SNArray[i] = (byte)SN[i];
  5185. }
  5186. if (SN.Length < 16)
  5187. {
  5188. SNArray[SN.Length] = (byte)'.';
  5189. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5190. {
  5191. SNArray[SN.Length + 1 + i] = 0x20;
  5192. }
  5193. }
  5194. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5195. }
  5196. else
  5197. {
  5198. timer_1s.Enabled = false;
  5199. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5200. timer_1s.Enabled = true;
  5201. break;
  5202. }
  5203. } while (false);
  5204. scan_form.Dispose();
  5205. }
  5206. private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
  5207. {
  5208. //输入用户名
  5209. EnterForm1.ShowDialog();
  5210. try
  5211. {
  5212. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5213. {
  5214. if (EnterForm1.comboBox_User.Text == "管理员")
  5215. {
  5216. IP地址ToolStripMenuItem.Visible = true;
  5217. 端口ToolStripMenuItem.Visible = true;
  5218. 用户名ToolStripMenuItem.Visible = true;
  5219. 密码ToolStripMenuItem.Visible = true;
  5220. 存储路径ToolStripMenuItem.Visible = true;
  5221. }
  5222. else
  5223. {
  5224. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5225. IP地址ToolStripMenuItem.Visible = false;
  5226. 端口ToolStripMenuItem.Visible = false;
  5227. 用户名ToolStripMenuItem.Visible = false;
  5228. 密码ToolStripMenuItem.Visible = false;
  5229. 存储路径ToolStripMenuItem.Visible = false;
  5230. }
  5231. }
  5232. else
  5233. {
  5234. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5235. IP地址ToolStripMenuItem.Visible = false;
  5236. 端口ToolStripMenuItem.Visible = false;
  5237. 用户名ToolStripMenuItem.Visible = false;
  5238. 密码ToolStripMenuItem.Visible = false;
  5239. 存储路径ToolStripMenuItem.Visible = false;
  5240. }
  5241. }
  5242. catch (Exception)
  5243. {
  5244. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5245. IP地址ToolStripMenuItem.Visible = false;
  5246. 端口ToolStripMenuItem.Visible = false;
  5247. 用户名ToolStripMenuItem.Visible = false;
  5248. 密码ToolStripMenuItem.Visible = false;
  5249. 存储路径ToolStripMenuItem.Visible = false;
  5250. }
  5251. }
  5252. private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
  5253. {
  5254. //输入用户名
  5255. EnterForm1.ShowDialog();
  5256. try
  5257. {
  5258. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5259. {
  5260. if (EnterForm1.comboBox_User.Text == "管理员")
  5261. {
  5262. 生产商ToolStripMenuItem.Visible = true;
  5263. 生产地ToolStripMenuItem.Visible = true;
  5264. 生产日期ToolStripMenuItem.Visible = true;
  5265. 产品标识ToolStripMenuItem.Visible = true;
  5266. }
  5267. else
  5268. {
  5269. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5270. 生产商ToolStripMenuItem.Visible = false;
  5271. 生产地ToolStripMenuItem.Visible = false;
  5272. 生产日期ToolStripMenuItem.Visible = false;
  5273. 产品标识ToolStripMenuItem.Visible = false;
  5274. }
  5275. }
  5276. else
  5277. {
  5278. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5279. 生产商ToolStripMenuItem.Visible = false;
  5280. 生产地ToolStripMenuItem.Visible = false;
  5281. 生产日期ToolStripMenuItem.Visible = false;
  5282. 产品标识ToolStripMenuItem.Visible = false;
  5283. }
  5284. }
  5285. catch (Exception)
  5286. {
  5287. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5288. 生产商ToolStripMenuItem.Visible = false;
  5289. 生产地ToolStripMenuItem.Visible = false;
  5290. 生产日期ToolStripMenuItem.Visible = false;
  5291. 产品标识ToolStripMenuItem.Visible = false;
  5292. }
  5293. }
  5294. /// <summary>
  5295. /// 切换电机类型
  5296. /// </summary>
  5297. /// <param name="sender"></param>
  5298. /// <param name="e"></param>
  5299. private void 中置电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5300. {
  5301. 中置电机ToolStripMenuItem.Checked = true;
  5302. 轮毂电机ToolStripMenuItem.Checked = false;
  5303. toolStripTextBox_MACPD.Text = "MM_MC1";
  5304. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5305. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5306. }
  5307. /// <summary>
  5308. /// 切换电机类型
  5309. /// </summary>
  5310. /// <param name="sender"></param>
  5311. /// <param name="e"></param>
  5312. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5313. {
  5314. 中置电机ToolStripMenuItem.Checked = false;
  5315. 轮毂电机ToolStripMenuItem.Checked = true;
  5316. toolStripTextBox_MACPD.Text = "GF_250_1";
  5317. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5318. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5319. }
  5320. /// <summary>
  5321. /// 获取配置文件日期
  5322. /// </summary>
  5323. /// <param name="DisAll"></param>
  5324. private void GetDateList(bool DisAll)
  5325. {
  5326. string[] DateList = { "" };
  5327. //从服务器更新日期列表
  5328. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5329. {
  5330. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5331. }
  5332. //从本地更新日期列表
  5333. else
  5334. {
  5335. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5336. }
  5337. comboBox_FacModeCfgDate.Items.Clear();
  5338. comboBox_CheckModeCfgDate.Items.Clear();
  5339. //日期列表加载
  5340. if (DisAll == true)
  5341. {
  5342. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5343. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5344. comboBox_FacModeCfgDate.Items.Add("---");
  5345. comboBox_CheckModeCfgDate.Items.Add("---");
  5346. foreach (var file in DateList)
  5347. {
  5348. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5349. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5350. }
  5351. }
  5352. else
  5353. {
  5354. if (DateList.Length > 10)
  5355. {
  5356. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5357. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5358. comboBox_FacModeCfgDate.Items.Add("---");
  5359. comboBox_CheckModeCfgDate.Items.Add("---");
  5360. }
  5361. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5362. {
  5363. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5364. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5365. }
  5366. }
  5367. }
  5368. /// <summary>
  5369. /// 获取配置文件列表
  5370. /// </summary>
  5371. /// <param name="date"></param>
  5372. private void GetFileListFrom(string date)
  5373. {
  5374. string[] FileList = { "" };
  5375. //从服务器更新文件列表
  5376. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5377. {
  5378. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5379. }
  5380. else
  5381. {
  5382. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5383. }
  5384. comboBox_CheckModeCfgFile.Items.Clear();
  5385. comboBox_FacModeCfgFile.Items.Clear();
  5386. foreach (var file in FileList)
  5387. {
  5388. if (file.Contains(".ttcfg"))
  5389. {
  5390. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5391. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5392. }
  5393. }
  5394. }
  5395. /// <summary>
  5396. /// 检验模式选择文件日期
  5397. /// </summary>
  5398. /// <param name="sender"></param>
  5399. /// <param name="e"></param>
  5400. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5401. {
  5402. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5403. {
  5404. GetDateList(true);
  5405. }
  5406. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5407. {
  5408. GetDateList(false);
  5409. }
  5410. else
  5411. {
  5412. comboBox_CheckModeCfgFile.Text = "";
  5413. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5414. }
  5415. }
  5416. /// <summary>
  5417. /// 配置模式选择文件日期
  5418. /// </summary>
  5419. /// <param name="sender"></param>
  5420. /// <param name="e"></param>
  5421. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5422. {
  5423. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5424. {
  5425. GetDateList(true);
  5426. }
  5427. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5428. {
  5429. GetDateList(false);
  5430. }
  5431. else
  5432. {
  5433. comboBox_FacModeCfgFile.Text = "";
  5434. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5435. }
  5436. }
  5437. /// <summary>
  5438. /// 选中量产模式
  5439. /// </summary>
  5440. /// <param name="sender"></param>
  5441. /// <param name="e"></param>
  5442. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5443. {
  5444. //更新生产配置文件目录
  5445. GetDateList(false);
  5446. }
  5447. /// <summary>
  5448. /// 量产测试结束
  5449. /// </summary>
  5450. /// <param name=""></param>
  5451. private void FacMode_Stop(bool OK_Flag)
  5452. {
  5453. //打开开始按钮
  5454. button__FacMode_Start.Enabled = true;
  5455. //系统关机
  5456. var Code = new byte[32];//发送的指令数据
  5457. Code[0] = 0xF0;
  5458. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5459. //关闭串口
  5460. //mySerialProcess.SerialClose(false);
  5461. //路径设置
  5462. string LocalSavePath = "";
  5463. string ServerSavePath = "";
  5464. if (OK_Flag)
  5465. {
  5466. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5467. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5468. }
  5469. else
  5470. {
  5471. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5472. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5473. }
  5474. if (Directory.Exists(LocalSavePath) == false)
  5475. {
  5476. Directory.CreateDirectory(LocalSavePath);
  5477. }
  5478. //保存和上传
  5479. string LogSavePath = "";
  5480. string LogSaveFileName = "";
  5481. string ProductInfo = textBox_FacModeScan.Text;
  5482. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5483. if (Directory.Exists(LogSavePath) == false)
  5484. {
  5485. Directory.CreateDirectory(LogSavePath);
  5486. }
  5487. //测试页面
  5488. Double scaleX = PrimaryScreen.ScaleX;
  5489. Double scaleY = PrimaryScreen.ScaleY;
  5490. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5491. Graphics g = Graphics.FromImage(bit);
  5492. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5493. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5494. bit.Save(LogSaveFileName);
  5495. //上传测试页面到服务器
  5496. if (myFtp.IsNetConnected == true)
  5497. {
  5498. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5499. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5500. {
  5501. myFtp.MakeDir(ServerSavePath + DateNow);
  5502. }
  5503. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5504. {
  5505. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5506. }
  5507. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5508. if (result == true)
  5509. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5510. }
  5511. else
  5512. {
  5513. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5514. }
  5515. //测试记录
  5516. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5517. string file_str = "";
  5518. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5519. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5520. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5521. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5522. file_str += Local_HdInformation;
  5523. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5524. //上传测试记录到服务器
  5525. if (myFtp.IsNetConnected == true)
  5526. {
  5527. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5528. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5529. {
  5530. myFtp.MakeDir(ServerSavePath + DateNow);
  5531. }
  5532. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5533. {
  5534. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5535. }
  5536. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5537. if (result == true)
  5538. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5539. }
  5540. else
  5541. {
  5542. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5543. }
  5544. //扫码框清空
  5545. textBox_FacModeScan.Text = "";
  5546. }
  5547. /// <summary>
  5548. /// 量产测试开始
  5549. /// </summary>
  5550. /// <param name="sender"></param>
  5551. /// <param name="e"></param>
  5552. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5553. {
  5554. //关闭测试项目编辑
  5555. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5556. foreach (Control c in groupBox2.Controls)
  5557. {
  5558. if (c is CheckBox)
  5559. c.Enabled = false;
  5560. }
  5561. WriteLockStatus = true;
  5562. //检查配置文件
  5563. if (comboBox_FacModeCfgFile.Text == "")
  5564. {
  5565. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5566. return;
  5567. }
  5568. //开始测试
  5569. TestStart();
  5570. }
  5571. /// <summary>
  5572. /// 测试子函数
  5573. /// </summary>
  5574. private void TestStart()
  5575. {
  5576. //初始化标签
  5577. FacModelLabelInit();
  5578. richTextBox_FacModeLog.Clear();
  5579. //按钮禁止操作
  5580. button__FacMode_Start.Enabled = false;
  5581. //记录配置文件
  5582. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5583. //检查打标信息格式
  5584. label_FacModeStatus.Text = "检查扫码信息";
  5585. Delay_ms(500);
  5586. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5587. if (textBox_FacModeScan.Text == string.Empty)
  5588. {
  5589. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5590. button__FacMode_Start.Enabled = true;
  5591. return;
  5592. }
  5593. try
  5594. {
  5595. if (中置电机ToolStripMenuItem.Checked == true)
  5596. {
  5597. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5598. {
  5599. label_FacModeStatus.Text = "存在故障!";
  5600. label_FacModeResult.BackColor = Color.Red;
  5601. label_FacModeResult.Text = "标签格式错误";
  5602. button__FacMode_Start.Enabled = true;
  5603. return;
  5604. }
  5605. }
  5606. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5607. {
  5608. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5609. {
  5610. label_FacModeStatus.Text = "存在故障!";
  5611. label_FacModeResult.BackColor = Color.Red;
  5612. label_FacModeResult.Text = "标签格式错误";
  5613. button__FacMode_Start.Enabled = true;
  5614. return;
  5615. }
  5616. }
  5617. }
  5618. catch (System.Exception)
  5619. {
  5620. label_FacModeStatus.Text = "存在故障!";
  5621. label_FacModeResult.BackColor = Color.Red;
  5622. label_FacModeResult.Text = "标签格式错误";
  5623. button__FacMode_Start.Enabled = true;
  5624. return;
  5625. }
  5626. //打开串口
  5627. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5628. if (!mySerialProcess.mySerial.IsOpen)
  5629. {
  5630. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5631. //按钮禁止操作
  5632. button__FacMode_Start.Enabled = true;
  5633. return;
  5634. }
  5635. //流水号计数
  5636. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5637. serial += 1;
  5638. label_FacModeSerial.Text = serial.ToString();
  5639. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5640. //创建线程,执行测试任务
  5641. Thread th = new Thread(FacModeTest_Task);
  5642. th.Start();
  5643. }
  5644. /// <summary>
  5645. /// 执行一次测试任务
  5646. /// </summary>
  5647. private void FacModeTest_Task()
  5648. {
  5649. //开始测试
  5650. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5651. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5652. //变量定义
  5653. var Code = new byte[255];//发送的指令数据
  5654. label_FacModeStatus.Text = "开始测试";
  5655. BootInfo = "";
  5656. Delay_ms(500);
  5657. label_FacModeStatus.Text = "系统开机";
  5658. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5659. if (uARTToolStripMenuItem.Checked)
  5660. {
  5661. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5662. Code[0] = (byte)'R';
  5663. Code[1] = (byte)'E';
  5664. Code[2] = (byte)'S';
  5665. Code[3] = (byte)'E';
  5666. Code[4] = (byte)'T';
  5667. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5668. Delay_ms(500);
  5669. }
  5670. //发送开机指令
  5671. //确保测试前先关机,发送关机指令再发送开机指令
  5672. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5673. Code[0] = 0xF0;
  5674. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5675. Delay_ms(1500);
  5676. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5677. Code[0] = 0xF1;
  5678. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5679. ACK_WaitCnt = 0;
  5680. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5681. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5682. //检查BOOT版本
  5683. if (BootInfo != string.Empty)
  5684. {
  5685. label_FacModeBootVer.BackColor = Color.Green;
  5686. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5687. Delay_ms(500);
  5688. }
  5689. else
  5690. {
  5691. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5692. label_FacModeStatus.Text = "存在故障!";
  5693. label_FacModeResult.BackColor = Color.Red;
  5694. label_FacModeResult.Text = "测试异常";
  5695. Delay_ms(500);
  5696. //存储异常并上传
  5697. FacMode_Stop(false);
  5698. return;
  5699. }
  5700. //系统清除
  5701. if (checkBox_FacModeSysClear.Checked)
  5702. {
  5703. do
  5704. {
  5705. #if false
  5706. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5707. {
  5708. Code[0] = 0x00;//5S协议
  5709. Code[1] = 0x00;
  5710. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5711. Delay_ms(500);
  5712. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5713. Delay_ms(500);
  5714. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5715. }
  5716. #endif
  5717. //发送系统清除指令
  5718. label_FacModeStatus.Text = "系统清除";
  5719. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5720. Code[0] = (byte)'C';
  5721. Code[1] = (byte)'L';
  5722. Code[2] = (byte)'E';
  5723. Code[3] = (byte)'A';
  5724. Code[4] = (byte)'R';
  5725. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5726. WriteACK = false;
  5727. WriteCnt = 0;
  5728. ACK_WaitCnt = 0;
  5729. while (ACK_WaitCnt <= 6); //3s
  5730. //等待系统清除完成指令
  5731. if (WriteACK == true)
  5732. {
  5733. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5734. label_FacModeSysClear.BackColor = Color.Green;
  5735. }
  5736. else
  5737. {
  5738. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5739. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5740. ACK_WaitCnt = 0;
  5741. while (ACK_WaitCnt <= 6) ; //3s
  5742. //等待系统清除完成指令
  5743. if (WriteACK == true)
  5744. {
  5745. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5746. label_FacModeSysClear.BackColor = Color.Green;
  5747. }
  5748. else
  5749. {
  5750. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5751. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5752. ACK_WaitCnt = 0;
  5753. while (ACK_WaitCnt <= 6) ; //3s
  5754. //等待系统清除完成指令
  5755. if (WriteACK == true)
  5756. {
  5757. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5758. label_FacModeSysClear.BackColor = Color.Green;
  5759. }
  5760. else
  5761. {
  5762. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5763. label_FacModeStatus.Text = "存在故障!";
  5764. label_FacModeResult.BackColor = Color.Red;
  5765. label_FacModeResult.Text = "测试异常";
  5766. Delay_ms(500);
  5767. //存储异常并上传
  5768. FacMode_Stop(false);
  5769. return;
  5770. }
  5771. }
  5772. }
  5773. BootInfo = "";
  5774. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5775. if (uARTToolStripMenuItem.Checked)
  5776. {
  5777. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5778. Code[0] = (byte)'R';
  5779. Code[1] = (byte)'E';
  5780. Code[2] = (byte)'S';
  5781. Code[3] = (byte)'E';
  5782. Code[4] = (byte)'T';
  5783. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5784. Delay_ms(500);
  5785. }
  5786. //系统重新开机
  5787. label_FacModeStatus.Text = "重新开机";
  5788. //确保测试前先关机,发送关机指令再发送开机指令
  5789. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  5790. Code[0] = 0xF0;
  5791. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5792. Delay_ms(1500);
  5793. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  5794. Code[0] = 0xF1;
  5795. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5796. ACK_WaitCnt = 0;
  5797. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5798. while (ACK_WaitCnt <= 20); //10s
  5799. //获取Boot版本信息
  5800. if (BootInfo != string.Empty)
  5801. {
  5802. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5803. Delay_ms(500);
  5804. }
  5805. else
  5806. {
  5807. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\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. } while (false);
  5817. }
  5818. else
  5819. {
  5820. label_FacModeSysClear.BackColor = Color.Yellow;
  5821. label_FacModeStatus.Text = "跳过系统清除!";
  5822. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5823. Delay_ms(500);
  5824. }
  5825. #if false
  5826. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5827. {
  5828. Code[0] = 0x00;//5S协议
  5829. Code[1] = 0x00;
  5830. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5831. Delay_ms(500);
  5832. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5833. Delay_ms(500);
  5834. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5835. }
  5836. #endif
  5837. //检查是否有故障
  5838. if (textBox_ErrorCode.Text.Contains("H"))
  5839. {
  5840. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5841. label_FacModeStatus.Text = "电机存在故障!";
  5842. label_FacModeResult.BackColor = Color.Red;
  5843. label_FacModeResult.Text = "测试异常";
  5844. Delay_ms(500);
  5845. //存储异常并上传
  5846. FacMode_Stop(false);
  5847. return;
  5848. }
  5849. //MOS内阻校准
  5850. if (checkBox_FacMode_MosCal.Checked)
  5851. {
  5852. label_FacModeStatus.Text = "MOS内阻校准";
  5853. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  5854. Delay_ms(500);
  5855. //提示进行负载切换
  5856. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  5857. {
  5858. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  5859. label_FacModeStatus.Text = "存在故障!";
  5860. label_FacModeResult.BackColor = Color.Red;
  5861. label_FacModeResult.Text = "测试异常";
  5862. Delay_ms(500);
  5863. //存储异常并上传
  5864. FacMode_Stop(false);
  5865. return;
  5866. }
  5867. //确认后发送校准指令
  5868. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  5869. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  5870. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  5871. ushort uwDataTemp = 0;
  5872. uwDataTemp = Convert.ToUInt16(K[0]);
  5873. Code[2] = (byte)(uwDataTemp & 0xFF);
  5874. Code[3] = (byte)(uwDataTemp >> 8);
  5875. uwDataTemp = Convert.ToUInt16(K[1]);
  5876. Code[4] = (byte)(uwDataTemp & 0xFF);
  5877. Code[5] = (byte)(uwDataTemp >> 8);
  5878. uwDataTemp = Convert.ToUInt16(K[2]);
  5879. Code[6] = (byte)(uwDataTemp & 0xFF);
  5880. Code[7] = (byte)(uwDataTemp >> 8);
  5881. uwDataTemp = Convert.ToUInt16(K[3]);
  5882. Code[8] = (byte)(uwDataTemp & 0xFF);
  5883. Code[9] = (byte)(uwDataTemp >> 8);
  5884. uwDataTemp = Convert.ToUInt16(K[4]);
  5885. Code[10] = (byte)(uwDataTemp & 0xFF);
  5886. Code[11] = (byte)(uwDataTemp >> 8);
  5887. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5888. WriteACK = false;
  5889. WriteCnt = 0;
  5890. ACK_WaitCnt = 0;
  5891. while (ACK_WaitCnt <= 6) ; //3s
  5892. if (WriteACK == true)
  5893. {
  5894. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5895. }
  5896. else
  5897. {
  5898. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  5899. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5900. ACK_WaitCnt = 0;
  5901. while (ACK_WaitCnt <= 6) ; //3s
  5902. if (WriteACK == true)
  5903. {
  5904. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5905. }
  5906. else
  5907. {
  5908. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  5909. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5910. ACK_WaitCnt = 0;
  5911. while (ACK_WaitCnt <= 6) ; //3s
  5912. if (WriteACK == true)
  5913. {
  5914. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5915. }
  5916. else
  5917. {
  5918. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  5919. label_FacModeStatus.Text = "存在故障!";
  5920. label_FacModeResult.BackColor = Color.Red;
  5921. label_FacModeResult.Text = "测试异常";
  5922. Delay_ms(500);
  5923. //存储异常并上传
  5924. FacMode_Stop(false);
  5925. return;
  5926. }
  5927. }
  5928. }
  5929. #if false
  5930. //因控制器复位需发送指令重新进入5S协议
  5931. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5932. {
  5933. Code[0] = 0x00;//5S协议
  5934. Code[1] = 0x00;
  5935. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5936. Delay_ms(500);
  5937. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5938. Delay_ms(500);
  5939. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5940. }
  5941. #endif
  5942. //读取显示校准返回数据
  5943. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  5944. foreach (Control c in groupBox21.Controls)
  5945. {
  5946. if (c is TextBox)
  5947. c.Text = "";
  5948. }
  5949. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5950. ACK_WaitCnt = 0;
  5951. while (ACK_WaitCnt <= 2) ; //1s
  5952. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5953. {
  5954. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  5955. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5956. ACK_WaitCnt = 0;
  5957. while (ACK_WaitCnt <= 2) ; //1s
  5958. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5959. {
  5960. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  5961. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5962. ACK_WaitCnt = 0;
  5963. while (ACK_WaitCnt <= 2) ; //1s
  5964. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5965. {
  5966. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  5967. label_FacModeStatus.Text = "存在故障!";
  5968. label_FacModeResult.BackColor = Color.Red;
  5969. label_FacModeResult.Text = "测试异常";
  5970. Delay_ms(500);
  5971. //存储异常并上传
  5972. FacMode_Stop(false);
  5973. return;
  5974. }
  5975. }
  5976. }
  5977. else
  5978. {
  5979. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  5980. }
  5981. //与校准返回数据对比
  5982. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  5983. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  5984. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  5985. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  5986. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  5987. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  5988. )
  5989. {
  5990. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  5991. label_FacModeMosCal.BackColor = Color.Green;
  5992. //提示切换负载
  5993. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  5994. }
  5995. else
  5996. {
  5997. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  5998. label_FacModeStatus.Text = "存在故障!";
  5999. label_FacModeResult.BackColor = Color.Red;
  6000. label_FacModeResult.Text = "测试异常";
  6001. Delay_ms(500);
  6002. //存储异常并上传
  6003. FacMode_Stop(false);
  6004. //提示切换负载
  6005. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6006. return;
  6007. }
  6008. }
  6009. else
  6010. {
  6011. label_FacModeMosCal.BackColor = Color.Yellow;
  6012. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6013. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6014. Delay_ms(500);
  6015. }
  6016. //参数写入
  6017. if (checkBox_FacModeCfgWrite.Checked)
  6018. {
  6019. label_FacModeStatus.Text = "参数写入";
  6020. //写入产品型号和SN
  6021. do
  6022. {
  6023. //根据扫码信息获取型号和SN
  6024. string ScanInfo = textBox_FacModeScan.Text;
  6025. string regexInfo = "";
  6026. string[] InfoList = { "" };
  6027. try
  6028. {
  6029. if (中置电机ToolStripMenuItem.Checked == true)
  6030. {
  6031. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6032. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6033. }
  6034. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6035. {
  6036. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6037. string Model = InfoList[0];
  6038. string Spec = InfoList[1];
  6039. string Sn = InfoList[2];
  6040. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6041. InfoList[1] = Sn;
  6042. }
  6043. }
  6044. catch
  6045. {
  6046. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6047. label_FacModeStatus.Text = "存在故障!";
  6048. label_FacModeResult.BackColor = Color.Red;
  6049. label_FacModeResult.Text = "标签格式错误";
  6050. Delay_ms(500);
  6051. //存储异常并上传
  6052. FacMode_Stop(false);
  6053. return;
  6054. }
  6055. if (InfoList.Length >= 2)
  6056. {
  6057. //检查配置文件是否与打标信息一致
  6058. //...
  6059. //写入型号
  6060. label_FacModeStatus.Text = "写入型号";
  6061. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6062. textBox_FacModeName.Text = InfoList[0];
  6063. string Mode = textBox_FacModeName.Text;
  6064. var ModeArray = new byte[16];
  6065. for (ushort i = 0; i < Mode.Length; i++)
  6066. {
  6067. ModeArray[i] = (byte)Mode[i];
  6068. }
  6069. if (Mode.Length < 16)
  6070. {
  6071. ModeArray[Mode.Length] = (byte)'.';
  6072. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6073. {
  6074. ModeArray[Mode.Length + 1 + i] = 0x20;
  6075. }
  6076. }
  6077. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6078. WriteACK = false;
  6079. WriteCnt = 0;
  6080. ACK_WaitCnt = 0;
  6081. while (ACK_WaitCnt <= 2); //1s
  6082. if (WriteACK == true)
  6083. {
  6084. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6085. }
  6086. else
  6087. {
  6088. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6089. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6090. ACK_WaitCnt = 0;
  6091. while (ACK_WaitCnt <= 2) ; //1s
  6092. if (WriteACK == true)
  6093. {
  6094. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6095. }
  6096. else
  6097. {
  6098. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6099. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6100. ACK_WaitCnt = 0;
  6101. while (ACK_WaitCnt <= 2) ; //1s
  6102. if (WriteACK == true)
  6103. {
  6104. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6105. }
  6106. else
  6107. {
  6108. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6109. label_FacModeStatus.Text = "存在故障!";
  6110. label_FacModeResult.BackColor = Color.Red;
  6111. label_FacModeResult.Text = "测试异常";
  6112. Delay_ms(500);
  6113. //存储异常并上传
  6114. FacMode_Stop(false);
  6115. return;
  6116. }
  6117. }
  6118. }
  6119. //写入SN
  6120. label_FacModeStatus.Text = "写入SN";
  6121. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6122. textBox_FacModeNum.Text = InfoList[1];
  6123. string SN = textBox_FacModeNum.Text;
  6124. var SNArray = new byte[16];
  6125. for (ushort i = 0; i < SN.Length; i++)
  6126. {
  6127. SNArray[i] = (byte)SN[i];
  6128. }
  6129. if (SN.Length < 16)
  6130. {
  6131. SNArray[SN.Length] = (byte)'.';
  6132. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6133. {
  6134. SNArray[SN.Length + 1 + i] = 0x20;
  6135. }
  6136. }
  6137. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6138. WriteACK = false;
  6139. WriteCnt = 0;
  6140. ACK_WaitCnt = 0;
  6141. while (ACK_WaitCnt <= 2); //1s
  6142. if (WriteACK == true)
  6143. {
  6144. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6145. }
  6146. else
  6147. {
  6148. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6149. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6150. ACK_WaitCnt = 0;
  6151. while (ACK_WaitCnt <= 2) ; //1s
  6152. if (WriteACK == true)
  6153. {
  6154. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6155. }
  6156. else
  6157. {
  6158. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6159. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6160. ACK_WaitCnt = 0;
  6161. while (ACK_WaitCnt <= 2) ; //1s
  6162. if (WriteACK == true)
  6163. {
  6164. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6165. }
  6166. else
  6167. {
  6168. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6169. label_FacModeStatus.Text = "存在故障!";
  6170. label_FacModeResult.BackColor = Color.Red;
  6171. label_FacModeResult.Text = "测试异常";
  6172. Delay_ms(500);
  6173. //存储异常并上传
  6174. FacMode_Stop(false);
  6175. return;
  6176. }
  6177. }
  6178. }
  6179. }
  6180. else
  6181. {
  6182. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6183. return;
  6184. }
  6185. } while (false);
  6186. //写入配置文件
  6187. do
  6188. {
  6189. label_FacModeStatus.Text = "写入配置文件";
  6190. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6191. //配置文件
  6192. List<byte[]> CmdList = new List<byte[]>();
  6193. //从服务器下载文件
  6194. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6195. {
  6196. string SelectFile = "";
  6197. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6198. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6199. {
  6200. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6201. }
  6202. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6203. //打开文件
  6204. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6205. CmdList.Clear();
  6206. while (streamReader.Peek() != -1)
  6207. {
  6208. string fileLineInfo = streamReader.ReadLine();
  6209. if (fileLineInfo.IndexOf("[") != -1)
  6210. {
  6211. continue;
  6212. }
  6213. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6214. }
  6215. streamReader.Close();
  6216. }
  6217. //加载本地文件
  6218. else
  6219. {
  6220. string SelectFile = "";
  6221. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6222. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6223. CmdList.Clear();
  6224. while (streamReader.Peek() != -1)
  6225. {
  6226. string fileLineInfo = streamReader.ReadLine();
  6227. if (fileLineInfo.IndexOf("[") != -1)
  6228. {
  6229. continue;
  6230. }
  6231. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6232. }
  6233. streamReader.Close();
  6234. }
  6235. int CmdNum = CmdList.Count(); //指令个数
  6236. Delay_ms(500);
  6237. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6238. Delay_ms(500);
  6239. //开始写入
  6240. WriteCnt = 0;
  6241. for (int i = 0; i < CmdList.Count; i++)
  6242. {
  6243. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6244. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6245. WriteACK = false;
  6246. ACK_WaitCnt = 0;
  6247. while (ACK_WaitCnt <= 2) ; //1s
  6248. if (WriteACK == true)
  6249. {
  6250. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6251. }
  6252. else
  6253. {
  6254. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6255. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6256. WriteACK = false;
  6257. ACK_WaitCnt = 0;
  6258. while (ACK_WaitCnt <= 2) ; //1s
  6259. if (WriteACK == true)
  6260. {
  6261. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6262. }
  6263. else
  6264. {
  6265. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6266. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6267. WriteACK = false;
  6268. ACK_WaitCnt = 0;
  6269. while (ACK_WaitCnt <= 2) ; //1s
  6270. if (WriteACK == true)
  6271. {
  6272. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6273. }
  6274. else
  6275. {
  6276. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6277. label_FacModeStatus.Text = "存在故障!";
  6278. label_FacModeResult.BackColor = Color.Red;
  6279. label_FacModeResult.Text = "测试异常";
  6280. Delay_ms(500);
  6281. //存储异常并上传
  6282. FacMode_Stop(false);
  6283. return;
  6284. }
  6285. }
  6286. }
  6287. }
  6288. //写入完成
  6289. label_FacMode_CfgWrite.BackColor = Color.Green;
  6290. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6291. Delay_ms(500);
  6292. } while (false);
  6293. }
  6294. else
  6295. {
  6296. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6297. label_FacModeStatus.Text = "跳过参数写入!";
  6298. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6299. Delay_ms(500);
  6300. }
  6301. //BMS通讯
  6302. if (checkBox_FacModeBMS.Checked)
  6303. {
  6304. if (label_FacModeBMS.BackColor == Color.Red)
  6305. {
  6306. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6307. label_FacModeStatus.Text = "存在故障!";
  6308. label_FacModeResult.BackColor = Color.Red;
  6309. label_FacModeResult.Text = "测试异常";
  6310. Delay_ms(500);
  6311. //存储异常并上传
  6312. FacMode_Stop(false);
  6313. return;
  6314. }
  6315. }
  6316. else
  6317. {
  6318. label_FacModeBMS.BackColor = Color.Yellow;
  6319. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6320. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6321. Delay_ms(500);
  6322. }
  6323. //基础功能检测
  6324. if (checkBox_FacBaseFucTest.Checked)
  6325. {
  6326. label_FacModeStatus.Text = "基础功能检测";
  6327. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6328. //确认负载位置
  6329. if (checkBox_FacMode_MosCal.Checked)
  6330. {
  6331. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6332. {
  6333. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6334. }
  6335. else
  6336. {
  6337. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6338. label_FacModeStatus.Text = "存在故障!";
  6339. label_FacModeResult.BackColor = Color.Red;
  6340. label_FacModeResult.Text = "测试异常";
  6341. Delay_ms(500);
  6342. //存储异常并上传
  6343. FacMode_Stop(false);
  6344. return;
  6345. }
  6346. }
  6347. //发送指令进入配置模式
  6348. do
  6349. {
  6350. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6351. Code[0] = 0x01;
  6352. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6353. WriteACK = false;
  6354. WriteCnt = 0;
  6355. ACK_WaitCnt = 0;
  6356. while (ACK_WaitCnt <= 2); //1s
  6357. if (textBox_RunInfo_Vol.Text != "---")
  6358. {
  6359. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6360. }
  6361. else
  6362. {
  6363. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6364. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6365. ACK_WaitCnt = 0;
  6366. while (ACK_WaitCnt <= 2) ; //1s
  6367. if (textBox_RunInfo_Vol.Text != "---")
  6368. {
  6369. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6370. }
  6371. else
  6372. {
  6373. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6374. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6375. ACK_WaitCnt = 0;
  6376. while (ACK_WaitCnt <= 2) ; //1s
  6377. if (textBox_RunInfo_Vol.Text != "---")
  6378. {
  6379. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6380. }
  6381. else
  6382. {
  6383. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6384. label_FacModeStatus.Text = "存在故障!";
  6385. label_FacModeResult.BackColor = Color.Red;
  6386. label_FacModeResult.Text = "测试异常";
  6387. Delay_ms(500);
  6388. //存储异常并上传
  6389. FacMode_Stop(false);
  6390. return;
  6391. }
  6392. }
  6393. }
  6394. } while (false);
  6395. //发送指令启动电机
  6396. do
  6397. {
  6398. #if false //通过运行模式3启动电机
  6399. //发送指令读取调试信息
  6400. richTextBox_DebugParam.Clear();
  6401. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6402. WriteACK = false;
  6403. WriteCnt = 0;
  6404. ACK_WaitCnt = 0;
  6405. while (ACK_WaitCnt <= 2); //1s
  6406. //获取调试信息
  6407. string DebugDefaultInfo = "";
  6408. if (richTextBox_DebugParam.Text == string.Empty)
  6409. {
  6410. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6411. label_FacModeStatus.Text = "存在故障!";
  6412. label_FacModeResult.BackColor = Color.Red;
  6413. label_FacModeResult.Text = "测试异常";
  6414. Delay_ms(500);
  6415. //存储异常并上传
  6416. FacMode_Stop(false);
  6417. return;
  6418. }
  6419. else
  6420. {
  6421. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6422. }
  6423. //设置模式
  6424. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6425. strDataTemp[0] = "整体运行模式=3";
  6426. //发送数据
  6427. Code[0] = 0;
  6428. Code[1] = 0;
  6429. for (int i = 0; i < strDataTemp.Length; i++)
  6430. {
  6431. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6432. Code[2 * i + 2] = (byte)uwDataTemp;
  6433. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6434. }
  6435. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6436. label_FacModeStatus.Text = "启动电机";
  6437. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6438. #else //通过Walk模式启动电机
  6439. //设置转速100%
  6440. var Data = new byte[1];
  6441. Data[0] = (byte)100;
  6442. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6443. Delay_ms(500);
  6444. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6445. Delay_ms(500);
  6446. //启动电机进入WALK模式
  6447. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6448. Code[0] = 0x22;
  6449. Code[1] = 0xF0;
  6450. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6451. WriteACK = false;
  6452. WriteCnt = 0;
  6453. ACK_WaitCnt = 0;
  6454. while (ACK_WaitCnt <= 2) ; //1s
  6455. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6456. {
  6457. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6458. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6459. ACK_WaitCnt = 0;
  6460. while (ACK_WaitCnt <= 2) ; //1s
  6461. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6462. {
  6463. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6464. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6465. ACK_WaitCnt = 0;
  6466. while (ACK_WaitCnt <= 2) ; //1s
  6467. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6468. {
  6469. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6470. label_FacModeStatus.Text = "存在故障!";
  6471. label_FacModeResult.BackColor = Color.Red;
  6472. label_FacModeResult.Text = "测试异常";
  6473. Delay_ms(500);
  6474. //存储异常并上传
  6475. FacMode_Stop(false);
  6476. return;
  6477. }
  6478. }
  6479. }
  6480. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6481. #endif
  6482. Delay_ms(3000);
  6483. } while (false);
  6484. //判断车速
  6485. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6486. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6487. {
  6488. label_FacModeSpeed.BackColor = Color.Green;
  6489. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6490. }
  6491. else
  6492. {
  6493. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6494. label_FacModeStatus.Text = "存在故障!";
  6495. label_FacModeResult.BackColor = Color.Red;
  6496. label_FacModeResult.Text = "测试异常";
  6497. Delay_ms(500);
  6498. //存储异常并上传
  6499. FacMode_Stop(false);
  6500. return;
  6501. }
  6502. //判断电压
  6503. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6504. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6505. {
  6506. label_FacModeVolTest.BackColor = Color.Green;
  6507. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6508. }
  6509. else
  6510. {
  6511. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6512. label_FacModeStatus.Text = "存在故障!";
  6513. label_FacModeResult.BackColor = Color.Red;
  6514. label_FacModeResult.Text = "测试异常";
  6515. Delay_ms(500);
  6516. //存储异常并上传
  6517. FacMode_Stop(false);
  6518. return;
  6519. }
  6520. //判断电流
  6521. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6522. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6523. {
  6524. label_FacModeCurrentTest.BackColor = Color.Green;
  6525. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6526. }
  6527. else
  6528. {
  6529. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6530. label_FacModeStatus.Text = "存在故障!";
  6531. label_FacModeResult.BackColor = Color.Red;
  6532. label_FacModeResult.Text = "测试异常";
  6533. Delay_ms(500);
  6534. //存储异常并上传
  6535. FacMode_Stop(false);
  6536. return;
  6537. }
  6538. //判断温度
  6539. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6540. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6541. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6542. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6543. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6544. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6545. {
  6546. label_FacModeNTC.BackColor = Color.Green;
  6547. 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");
  6548. }
  6549. else
  6550. {
  6551. 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");
  6552. label_FacModeStatus.Text = "存在故障!";
  6553. label_FacModeResult.BackColor = Color.Red;
  6554. label_FacModeResult.Text = "测试异常";
  6555. Delay_ms(500);
  6556. //存储异常并上传
  6557. FacMode_Stop(false);
  6558. return;
  6559. }
  6560. //判断转速
  6561. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6562. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6563. {
  6564. label_FacModeMotorSpeed.BackColor = Color.Green;
  6565. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6566. }
  6567. else
  6568. {
  6569. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6570. label_FacModeStatus.Text = "存在故障!";
  6571. label_FacModeResult.BackColor = Color.Red;
  6572. label_FacModeResult.Text = "测试异常";
  6573. Delay_ms(500);
  6574. //存储异常并上传
  6575. FacMode_Stop(false);
  6576. return;
  6577. }
  6578. //发送指令停止电机
  6579. do
  6580. {
  6581. //设置转速0%
  6582. var Data = new byte[1];
  6583. Data[0] = (byte)0;
  6584. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6585. Delay_ms(500);
  6586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6587. Delay_ms(500);
  6588. #if false //通过修改调试模式停止电机
  6589. //获取调试信息
  6590. string DebugDefaultInfo = "";
  6591. if (richTextBox_DebugParam.Text == string.Empty)
  6592. {
  6593. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6594. label_FacModeStatus.Text = "存在故障!";
  6595. label_FacModeResult.BackColor = Color.Red;
  6596. label_FacModeResult.Text = "测试异常";
  6597. Delay_ms(500);
  6598. //存储异常并上传
  6599. FacMode_Stop(false);
  6600. return;
  6601. }
  6602. else
  6603. {
  6604. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6605. }
  6606. //设置模式
  6607. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6608. //发送数据
  6609. Code[0] = 0;
  6610. Code[1] = 0;
  6611. for (int i = 0; i < strDataTemp.Length; i++)
  6612. {
  6613. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6614. Code[2 * i + 2] = (byte)uwDataTemp;
  6615. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6616. }
  6617. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6618. label_FacModeStatus.Text = "停止电机";
  6619. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6620. #else //通过调整档位停止电机
  6621. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6622. Code[0] = 0x00;
  6623. Code[1] = 0xF0;
  6624. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6625. WriteACK = false;
  6626. WriteCnt = 0;
  6627. ACK_WaitCnt = 0;
  6628. while (ACK_WaitCnt <= 2) ; //1s
  6629. if (textBox_RunInfo_GearSt.Text != "OFF")
  6630. {
  6631. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  6632. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6633. ACK_WaitCnt = 0;
  6634. while (ACK_WaitCnt <= 2) ; //1s
  6635. if (textBox_RunInfo_GearSt.Text != "OFF")
  6636. {
  6637. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  6638. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6639. ACK_WaitCnt = 0;
  6640. while (ACK_WaitCnt <= 2) ; //1s
  6641. if (textBox_RunInfo_GearSt.Text != "OFF")
  6642. {
  6643. }
  6644. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6645. label_FacModeStatus.Text = "存在故障!";
  6646. label_FacModeResult.BackColor = Color.Red;
  6647. label_FacModeResult.Text = "测试异常";
  6648. Delay_ms(500);
  6649. //存储异常并上传
  6650. FacMode_Stop(false);
  6651. return;
  6652. }
  6653. }
  6654. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6655. #endif
  6656. Delay_ms(2000);
  6657. } while (false);
  6658. }
  6659. else
  6660. {
  6661. label_FacModeSpeed.BackColor = Color.Yellow;
  6662. label_FacModeVolTest.BackColor = Color.Yellow;
  6663. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6664. label_FacModeNTC.BackColor = Color.Yellow;
  6665. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6666. label_FacModeStatus.Text = "跳过基础功能检测!";
  6667. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6668. Delay_ms(500);
  6669. }
  6670. //力矩检测
  6671. if (checkBox_FacTor.Checked)
  6672. {
  6673. label_FacModeStatus.Text = "力矩传感器检测!";
  6674. //发送指令进入配置模式
  6675. do
  6676. {
  6677. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6678. {
  6679. break;
  6680. }
  6681. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6682. Code[0] = 0x01;
  6683. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6684. WriteACK = false;
  6685. WriteCnt = 0;
  6686. ACK_WaitCnt = 0;
  6687. while (ACK_WaitCnt <= 2) ; //1s
  6688. if (textBox_RunInfo_Vol.Text != "---")
  6689. {
  6690. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6691. Delay_ms(500);
  6692. }
  6693. else
  6694. {
  6695. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6696. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6697. ACK_WaitCnt = 0;
  6698. while (ACK_WaitCnt <= 2) ; //1s
  6699. if (textBox_RunInfo_Vol.Text != "---")
  6700. {
  6701. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6702. Delay_ms(500);
  6703. }
  6704. else
  6705. {
  6706. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6707. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6708. ACK_WaitCnt = 0;
  6709. while (ACK_WaitCnt <= 2) ; //1s
  6710. if (textBox_RunInfo_Vol.Text != "---")
  6711. {
  6712. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6713. Delay_ms(500);
  6714. }
  6715. else
  6716. {
  6717. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6718. label_FacModeStatus.Text = "存在故障!";
  6719. label_FacModeResult.BackColor = Color.Red;
  6720. label_FacModeResult.Text = "测试异常";
  6721. Delay_ms(500);
  6722. //存储异常并上传
  6723. FacMode_Stop(false);
  6724. return;
  6725. }
  6726. }
  6727. }
  6728. } while (false);
  6729. ushort Max = 0, Torque = 0;
  6730. //提示输入力矩信号
  6731. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  6732. ACK_WaitCnt = 0;
  6733. while (ACK_WaitCnt <= 20) //10s
  6734. {
  6735. //获取力矩值
  6736. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  6737. if (Torque > Max)
  6738. Max = Torque;
  6739. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  6740. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  6741. (ACK_WaitCnt >= 6))
  6742. {
  6743. label_FacModeTq.BackColor = Color.Green;
  6744. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6745. break;
  6746. }
  6747. }
  6748. if (ACK_WaitCnt >= 20)
  6749. {
  6750. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6751. label_FacModeStatus.Text = "存在故障!";
  6752. label_FacModeResult.BackColor = Color.Red;
  6753. label_FacModeResult.Text = "测试异常";
  6754. Delay_ms(500);
  6755. //存储异常并上传
  6756. FacMode_Stop(false);
  6757. return;
  6758. }
  6759. }
  6760. else
  6761. {
  6762. label_FacModeTq.BackColor = Color.Yellow;
  6763. label_FacModeStatus.Text = "跳过力矩检测!";
  6764. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  6765. Delay_ms(500);
  6766. }
  6767. //踏频检测
  6768. if (checkBox_FacCad.Checked)
  6769. {
  6770. label_FacModeStatus.Text = "踏频传感器检测!";
  6771. //发送指令进入配置模式
  6772. do
  6773. {
  6774. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6775. {
  6776. break;
  6777. }
  6778. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6779. Code[0] = 0x01;
  6780. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6781. WriteACK = false;
  6782. WriteCnt = 0;
  6783. ACK_WaitCnt = 0;
  6784. while (ACK_WaitCnt <= 2) ; //1s
  6785. if (textBox_RunInfo_Vol.Text != "---")
  6786. {
  6787. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6788. Delay_ms(500);
  6789. }
  6790. else
  6791. {
  6792. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6793. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6794. ACK_WaitCnt = 0;
  6795. while (ACK_WaitCnt <= 2) ; //1s
  6796. if (textBox_RunInfo_Vol.Text != "---")
  6797. {
  6798. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6799. Delay_ms(500);
  6800. }
  6801. else
  6802. {
  6803. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6804. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6805. ACK_WaitCnt = 0;
  6806. while (ACK_WaitCnt <= 2) ; //1s
  6807. if (textBox_RunInfo_Vol.Text != "---")
  6808. {
  6809. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6810. Delay_ms(500);
  6811. }
  6812. else
  6813. {
  6814. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6815. label_FacModeStatus.Text = "存在故障!";
  6816. label_FacModeResult.BackColor = Color.Red;
  6817. label_FacModeResult.Text = "测试异常";
  6818. Delay_ms(500);
  6819. //存储异常并上传
  6820. FacMode_Stop(false);
  6821. return;
  6822. }
  6823. }
  6824. }
  6825. } while (false);
  6826. ushort Max = 0, Cadence = 0;
  6827. //提示输入踏频信号
  6828. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  6829. ACK_WaitCnt = 0;
  6830. while (ACK_WaitCnt <= 20) //10s
  6831. {
  6832. //获取踏频
  6833. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  6834. if (Cadence > Max)
  6835. Max = Cadence;
  6836. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  6837. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  6838. (ACK_WaitCnt >= 6))
  6839. {
  6840. label_FacModeCad.BackColor = Color.Green;
  6841. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6842. break;
  6843. }
  6844. }
  6845. if (ACK_WaitCnt >= 20)
  6846. {
  6847. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  6848. label_FacModeStatus.Text = "存在故障!";
  6849. label_FacModeResult.BackColor = Color.Red;
  6850. label_FacModeResult.Text = "测试异常";
  6851. Delay_ms(500);
  6852. //存储异常并上传
  6853. FacMode_Stop(false);
  6854. return;
  6855. }
  6856. }
  6857. else
  6858. {
  6859. label_FacModeCad.BackColor = Color.Yellow;
  6860. label_FacModeStatus.Text = "跳过踏频检测!";
  6861. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  6862. Delay_ms(500);
  6863. }
  6864. //转把检测
  6865. if (checkBox_FacThrrotleTest.Checked)
  6866. {
  6867. label_FacModeStatus.Text = "转把检测";
  6868. //发送指令进入配置模式
  6869. do
  6870. {
  6871. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6872. {
  6873. break;
  6874. }
  6875. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6876. Code[0] = 0x01;
  6877. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6878. WriteACK = false;
  6879. WriteCnt = 0;
  6880. ACK_WaitCnt = 0;
  6881. while (ACK_WaitCnt <= 2) ; //1s
  6882. if (textBox_RunInfo_Vol.Text != "---")
  6883. {
  6884. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6885. Delay_ms(500);
  6886. }
  6887. else
  6888. {
  6889. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6890. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6891. ACK_WaitCnt = 0;
  6892. while (ACK_WaitCnt <= 2) ; //1s
  6893. if (textBox_RunInfo_Vol.Text != "---")
  6894. {
  6895. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6896. Delay_ms(500);
  6897. }
  6898. else
  6899. {
  6900. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6901. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6902. ACK_WaitCnt = 0;
  6903. while (ACK_WaitCnt <= 2) ; //1s
  6904. if (textBox_RunInfo_Vol.Text != "---")
  6905. {
  6906. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6907. Delay_ms(500);
  6908. }
  6909. else
  6910. {
  6911. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6912. label_FacModeStatus.Text = "存在故障!";
  6913. label_FacModeResult.BackColor = Color.Red;
  6914. label_FacModeResult.Text = "测试异常";
  6915. Delay_ms(500);
  6916. //存储异常并上传
  6917. FacMode_Stop(false);
  6918. return;
  6919. }
  6920. }
  6921. }
  6922. } while (false);
  6923. //进入TURBO档
  6924. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  6925. Code[0] = 0x04;
  6926. Code[1] = 0xF0;
  6927. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6928. WriteACK = false;
  6929. WriteCnt = 0;
  6930. ACK_WaitCnt = 0;
  6931. while (ACK_WaitCnt <= 2) ; //1s
  6932. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6933. {
  6934. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  6935. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6936. ACK_WaitCnt = 0;
  6937. while (ACK_WaitCnt <= 2) ; //1s
  6938. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6939. {
  6940. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  6941. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6942. ACK_WaitCnt = 0;
  6943. while (ACK_WaitCnt <= 2) ; //1s
  6944. if (textBox_RunInfo_GearSt.Text != "TURBO")
  6945. {
  6946. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  6947. label_FacModeStatus.Text = "存在故障!";
  6948. label_FacModeResult.BackColor = Color.Red;
  6949. label_FacModeResult.Text = "测试异常";
  6950. Delay_ms(500);
  6951. //存储异常并上传
  6952. FacMode_Stop(false);
  6953. return;
  6954. }
  6955. }
  6956. }
  6957. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  6958. ACK_WaitCnt = 0;
  6959. while (ACK_WaitCnt <= 20)
  6960. {
  6961. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  6962. {
  6963. label_FacModeGas.BackColor = Color.Green;
  6964. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  6965. break;
  6966. }
  6967. }
  6968. if (ACK_WaitCnt >= 20) //转把超时
  6969. {
  6970. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  6971. label_FacModeStatus.Text = "存在故障!";
  6972. label_FacModeResult.BackColor = Color.Red;
  6973. label_FacModeResult.Text = "测试异常";
  6974. Delay_ms(500);
  6975. //存储异常并上传
  6976. FacMode_Stop(false);
  6977. return;
  6978. }
  6979. }
  6980. else
  6981. {
  6982. label_FacModeGas.BackColor = Color.Yellow;
  6983. label_FacModeStatus.Text = "跳过转把检测!";
  6984. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  6985. Delay_ms(500);
  6986. }
  6987. //刹车检测
  6988. if (checkBox_FacBreakTest.Checked)
  6989. {
  6990. label_FacModeStatus.Text = "刹把检测";
  6991. //发送指令进入配置模式
  6992. do
  6993. {
  6994. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6995. {
  6996. break;
  6997. }
  6998. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6999. Code[0] = 0x01;
  7000. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7001. WriteACK = false;
  7002. WriteCnt = 0;
  7003. ACK_WaitCnt = 0;
  7004. while (ACK_WaitCnt <= 2) ; //1s
  7005. if (textBox_RunInfo_Vol.Text != "---")
  7006. {
  7007. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7008. Delay_ms(500);
  7009. }
  7010. else
  7011. {
  7012. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7013. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7014. ACK_WaitCnt = 0;
  7015. while (ACK_WaitCnt <= 2) ; //1s
  7016. if (textBox_RunInfo_Vol.Text != "---")
  7017. {
  7018. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7019. Delay_ms(500);
  7020. }
  7021. else
  7022. {
  7023. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7024. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7025. ACK_WaitCnt = 0;
  7026. while (ACK_WaitCnt <= 2) ; //1s
  7027. if (textBox_RunInfo_Vol.Text != "---")
  7028. {
  7029. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7030. Delay_ms(500);
  7031. }
  7032. else
  7033. {
  7034. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7035. label_FacModeStatus.Text = "存在故障!";
  7036. label_FacModeResult.BackColor = Color.Red;
  7037. label_FacModeResult.Text = "测试异常";
  7038. Delay_ms(500);
  7039. //存储异常并上传
  7040. FacMode_Stop(false);
  7041. return;
  7042. }
  7043. }
  7044. }
  7045. } while (false);
  7046. //设置转速100%
  7047. var Data = new byte[1];
  7048. Data[0] = (byte)100;
  7049. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7050. Delay_ms(500);
  7051. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7052. Delay_ms(500);
  7053. //启动电机进入WALK模式
  7054. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7055. Code[0] = 0x22;
  7056. Code[1] = 0xF0;
  7057. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7058. WriteACK = false;
  7059. WriteCnt = 0;
  7060. ACK_WaitCnt = 0;
  7061. while (ACK_WaitCnt <= 2) ; //1s
  7062. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7063. {
  7064. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7065. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7066. ACK_WaitCnt = 0;
  7067. while (ACK_WaitCnt <= 2) ; //1s
  7068. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7069. {
  7070. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7071. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7072. ACK_WaitCnt = 0;
  7073. while (ACK_WaitCnt <= 2) ; //1s
  7074. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7075. {
  7076. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7077. label_FacModeStatus.Text = "存在故障!";
  7078. label_FacModeResult.BackColor = Color.Red;
  7079. label_FacModeResult.Text = "测试异常";
  7080. Delay_ms(500);
  7081. //存储异常并上传
  7082. FacMode_Stop(false);
  7083. return;
  7084. }
  7085. }
  7086. }
  7087. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7088. ACK_WaitCnt = 0;
  7089. while (ACK_WaitCnt <= 20)
  7090. {
  7091. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7092. {
  7093. label_FacModeBreak.BackColor = Color.Green;
  7094. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7095. break;
  7096. }
  7097. }
  7098. if (ACK_WaitCnt >= 20) //剎把超时
  7099. {
  7100. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
  7101. label_FacModeStatus.Text = "存在故障!";
  7102. label_FacModeResult.BackColor = Color.Red;
  7103. label_FacModeResult.Text = "测试异常";
  7104. Delay_ms(500);
  7105. //存储异常并上传
  7106. FacMode_Stop(false);
  7107. return;
  7108. }
  7109. //停止电机
  7110. Code[0] = 0x00;
  7111. Code[1] = 0xF0;
  7112. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7113. WriteACK = false;
  7114. WriteCnt = 0;
  7115. ACK_WaitCnt = 0;
  7116. while (ACK_WaitCnt <= 2) ; //1s
  7117. if (textBox_RunInfo_GearSt.Text != "OFF")
  7118. {
  7119. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7120. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7121. ACK_WaitCnt = 0;
  7122. while (ACK_WaitCnt <= 2) ; //1s
  7123. if (textBox_RunInfo_GearSt.Text != "OFF")
  7124. {
  7125. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7126. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7127. ACK_WaitCnt = 0;
  7128. while (ACK_WaitCnt <= 2) ; //1s
  7129. if (textBox_RunInfo_GearSt.Text != "OFF")
  7130. {
  7131. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7132. label_FacModeStatus.Text = "存在故障!";
  7133. label_FacModeResult.BackColor = Color.Red;
  7134. label_FacModeResult.Text = "测试异常";
  7135. Delay_ms(500);
  7136. //存储异常并上传
  7137. FacMode_Stop(false);
  7138. return;
  7139. }
  7140. }
  7141. }
  7142. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7143. Delay_ms(500);
  7144. }
  7145. else
  7146. {
  7147. label_FacModeBreak.BackColor = Color.Yellow;
  7148. label_FacModeStatus.Text = "跳过刹车检测!";
  7149. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7150. Delay_ms(500);
  7151. }
  7152. //前后灯检测
  7153. if (checkBox_FacLightTest.Checked)
  7154. {
  7155. //前后灯检测
  7156. label_FacModeStatus.Text = "前后灯检测";
  7157. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7158. //发送指令打开车灯
  7159. Code[0] = 0x00;
  7160. Code[1] = 0xF1;
  7161. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7162. WriteACK = false;
  7163. WriteCnt = 0;
  7164. ACK_WaitCnt = 0;
  7165. while (ACK_WaitCnt <= 2) ; //1s
  7166. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7167. {
  7168. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7169. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7170. ACK_WaitCnt = 0;
  7171. while (ACK_WaitCnt <= 2); //1s
  7172. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7173. {
  7174. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7175. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7176. ACK_WaitCnt = 0;
  7177. while (ACK_WaitCnt <= 2) ; //1s
  7178. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7179. {
  7180. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7181. label_FacModeStatus.Text = "存在故障!";
  7182. label_FacModeResult.BackColor = Color.Red;
  7183. label_FacModeResult.Text = "测试异常";
  7184. Delay_ms(500);
  7185. //存储异常并上传
  7186. FacMode_Stop(false);
  7187. return;
  7188. }
  7189. }
  7190. }
  7191. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7192. Delay_ms(500);
  7193. //提示检查灯压是否正确
  7194. if (MessageBox.Show("前后灯是否正常?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7195. {
  7196. label_FacModeLightF.BackColor = Color.Green;
  7197. label_FacModeLightB.BackColor = Color.Green;
  7198. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7199. Delay_ms(500);
  7200. }
  7201. else
  7202. {
  7203. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7204. label_FacModeStatus.Text = "存在故障!";
  7205. label_FacModeResult.BackColor = Color.Red;
  7206. label_FacModeResult.Text = "测试异常";
  7207. Delay_ms(500);
  7208. //存储异常并上传
  7209. FacMode_Stop(false);
  7210. return;
  7211. }
  7212. //发送指令关闭车灯
  7213. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7214. Code[0] = 0x00;
  7215. Code[1] = 0xF0;
  7216. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7217. WriteACK = false;
  7218. WriteCnt = 0;
  7219. ACK_WaitCnt = 0;
  7220. while (ACK_WaitCnt <= 2) ; //1s
  7221. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7222. {
  7223. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7224. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7225. ACK_WaitCnt = 0;
  7226. while (ACK_WaitCnt <= 2) ; //1s
  7227. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7228. {
  7229. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7230. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7231. ACK_WaitCnt = 0;
  7232. while (ACK_WaitCnt <= 2) ; //1s
  7233. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7234. {
  7235. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7236. label_FacModeStatus.Text = "存在故障!";
  7237. label_FacModeResult.BackColor = Color.Red;
  7238. label_FacModeResult.Text = "测试异常";
  7239. Delay_ms(500);
  7240. //存储异常并上传
  7241. FacMode_Stop(false);
  7242. return;
  7243. }
  7244. }
  7245. }
  7246. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7247. Delay_ms(500);
  7248. }
  7249. else
  7250. {
  7251. label_FacModeLightF.BackColor = Color.Yellow;
  7252. label_FacModeLightB.BackColor = Color.Yellow;
  7253. label_FacModeStatus.Text = "跳过前后灯检测!";
  7254. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7255. Delay_ms(500);
  7256. }
  7257. //软件版本检测
  7258. do
  7259. {
  7260. label_FacModeStatus.Text = "软件版本确认";
  7261. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7262. //发送指令读取版本
  7263. Class_Motor_Ver.Mode = "---";
  7264. Class_Motor_Ver.SN = "---";
  7265. Class_Motor_Ver.HW = "---";
  7266. Class_Motor_Ver.FW = "---";
  7267. Class_Motor_Ver.Special = "---";
  7268. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7269. ACK_WaitCnt = 0;
  7270. while (ACK_WaitCnt <= 2) ; //1s
  7271. if (Class_Motor_Ver.Mode == "---")
  7272. {
  7273. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7274. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7275. ACK_WaitCnt = 0;
  7276. while (ACK_WaitCnt <= 2) ; //1s
  7277. if (Class_Motor_Ver.Mode == "---")
  7278. {
  7279. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7280. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7281. ACK_WaitCnt = 0;
  7282. while (ACK_WaitCnt <= 2) ; //1s
  7283. if (Class_Motor_Ver.Mode == "---")
  7284. {
  7285. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7286. label_FacModeStatus.Text = "存在故障!";
  7287. label_FacModeResult.BackColor = Color.Red;
  7288. label_FacModeResult.Text = "测试异常";
  7289. Delay_ms(500);
  7290. //存储异常并上传
  7291. FacMode_Stop(false);
  7292. return;
  7293. }
  7294. }
  7295. }
  7296. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7297. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7298. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7299. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7300. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7301. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7302. //判断版本是否正确
  7303. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7304. string VerRead = "";
  7305. try
  7306. {
  7307. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7308. }
  7309. catch (System.Exception)
  7310. {
  7311. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7312. label_FacModeStatus.Text = "存在故障!";
  7313. label_FacModeResult.BackColor = Color.Red;
  7314. label_FacModeResult.Text = "测试异常";
  7315. Delay_ms(500);
  7316. //存储异常并上传
  7317. FacMode_Stop(false);
  7318. return;
  7319. }
  7320. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7321. {
  7322. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7323. label_FacModeStatus.Text = "存在故障!";
  7324. label_FacModeResult.BackColor = Color.Red;
  7325. label_FacModeResult.Text = "测试异常";
  7326. Delay_ms(500);
  7327. //存储异常并上传
  7328. FacMode_Stop(false);
  7329. return;
  7330. }
  7331. label_FacModeFWVersion.BackColor = Color.Green;
  7332. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7333. Delay_ms(500);
  7334. } while (false);
  7335. //测试合格
  7336. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7337. label_FacModeStatus.Text = "测试结束!";
  7338. label_FacModeResult.BackColor = Color.Green;
  7339. label_FacModeResult.Text = "测试合格";
  7340. Delay_ms(500);
  7341. //存储并上传
  7342. FacMode_Stop(true);
  7343. return;
  7344. }
  7345. private void FacModelLabelInit()
  7346. {
  7347. //测试状态标签
  7348. label_FacModeResult.BackColor = Color.Yellow;
  7349. label_FacModeResult.Text = "测试中";
  7350. //测试过程标签
  7351. label_FacModeStatus.Text = "测试就绪";
  7352. //测试结果标签
  7353. foreach (Control c in groupBox28.Controls)
  7354. {
  7355. if (c is Label)
  7356. {
  7357. if (c.Text == string.Empty)
  7358. c.BackColor = Color.Red;
  7359. }
  7360. }
  7361. }
  7362. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7363. {
  7364. //更新生产配置文件目录
  7365. GetDateList(false);
  7366. }
  7367. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7368. {
  7369. //更新生产配置文件目录
  7370. GetDateList(false);
  7371. }
  7372. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7373. {
  7374. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7375. richTextBox_FacModeLog.ScrollToCaret();
  7376. }
  7377. /// <summary>
  7378. /// 参数检验测试停止
  7379. /// </summary>
  7380. /// <param name="OK_Flag"></param>
  7381. private void CheckMode_Stop(bool OK_Flag)
  7382. {
  7383. //打开开始按钮
  7384. button_CheckModeStart.Enabled = true;
  7385. //系统关机
  7386. var Code = new byte[32];//发送的指令数据
  7387. Code[0] = 0xF0;
  7388. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7389. //关闭串口
  7390. //mySerialProcess.SerialClose(false);
  7391. //路径设置
  7392. string LocalSavePath = "";
  7393. string ServerSavePath = "";
  7394. if (OK_Flag)
  7395. {
  7396. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7397. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7398. }
  7399. else
  7400. {
  7401. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  7402. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  7403. }
  7404. if (Directory.Exists(LocalSavePath) == false)
  7405. {
  7406. Directory.CreateDirectory(LocalSavePath);
  7407. }
  7408. //保存和上传
  7409. string LogSavePath = "";
  7410. string LogSaveFileName = "";
  7411. string ProductInfo = textBox_CheckModeScan.Text;
  7412. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  7413. if (Directory.Exists(LogSavePath) == false)
  7414. {
  7415. Directory.CreateDirectory(LogSavePath);
  7416. }
  7417. //测试页面
  7418. Double scaleX = PrimaryScreen.ScaleX;
  7419. Double scaleY = PrimaryScreen.ScaleY;
  7420. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  7421. Graphics g = Graphics.FromImage(bit);
  7422. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  7423. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  7424. bit.Save(LogSaveFileName);
  7425. //上传测试页面到服务器
  7426. if (myFtp.IsNetConnected == true)
  7427. {
  7428. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7429. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7430. {
  7431. myFtp.MakeDir(ServerSavePath + DateNow);
  7432. }
  7433. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7434. {
  7435. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7436. }
  7437. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7438. if (result == true)
  7439. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7440. }
  7441. //测试记录
  7442. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7443. string file_str = "";
  7444. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7445. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7446. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7447. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7448. file_str += Local_HdInformation;
  7449. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7450. //上传测试记录到服务器
  7451. if (myFtp.IsNetConnected == true)
  7452. {
  7453. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7454. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7455. {
  7456. myFtp.MakeDir(ServerSavePath + DateNow);
  7457. }
  7458. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7459. {
  7460. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7461. }
  7462. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7463. if (result == true)
  7464. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7465. }
  7466. //扫码框清空
  7467. textBox_CheckModeScan.Text = "";
  7468. }
  7469. /// <summary>
  7470. /// 参数检验开始
  7471. /// </summary>
  7472. /// <param name="sender"></param>
  7473. /// <param name="e"></param>
  7474. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7475. {
  7476. //测试项目关闭编辑
  7477. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7478. foreach (Control c in groupBox29.Controls)
  7479. {
  7480. if (c is CheckBox)
  7481. c.Enabled = false;
  7482. }
  7483. ReadLockStatus = true;
  7484. //检查配置文件
  7485. if (comboBox_CheckModeCfgFile.Text == "")
  7486. {
  7487. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7488. return;
  7489. }
  7490. //开始测试
  7491. CheckTestStart();
  7492. }
  7493. /// <summary>
  7494. /// 参数检验测试子函数
  7495. /// </summary>
  7496. private void CheckTestStart()
  7497. {
  7498. //初始化标签
  7499. CheckModeLabelInit();
  7500. richTextBox_CheckModeLog.Clear();
  7501. //按钮禁止操作
  7502. button_CheckModeStart.Enabled = false;
  7503. //记录配置文件
  7504. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7505. //检查打标信息
  7506. label_CheckModeStatus.Text = "检查扫码信息";
  7507. Delay_ms(500);
  7508. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7509. if (textBox_CheckModeScan.Text == string.Empty)
  7510. {
  7511. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7512. button__FacMode_Start.Enabled = false;
  7513. return;
  7514. }
  7515. try
  7516. {
  7517. if (中置电机ToolStripMenuItem.Checked == true)
  7518. {
  7519. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7520. {
  7521. label_CheckModeStatus.Text = "存在故障!";
  7522. label_CheckModeResult.BackColor = Color.Red;
  7523. label_CheckModeResult.Text = "标签格式错误";
  7524. button_CheckModeStart.Enabled = true;
  7525. return;
  7526. }
  7527. }
  7528. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7529. {
  7530. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  7531. {
  7532. label_CheckModeStatus.Text = "存在故障!";
  7533. label_CheckModeResult.BackColor = Color.Red;
  7534. label_CheckModeResult.Text = "标签格式错误";
  7535. button_CheckModeStart.Enabled = true;
  7536. return;
  7537. }
  7538. }
  7539. }
  7540. catch (System.Exception)
  7541. {
  7542. label_CheckModeStatus.Text = "存在故障!";
  7543. label_CheckModeResult.BackColor = Color.Red;
  7544. label_CheckModeResult.Text = "标签格式错误";
  7545. button_CheckModeStart.Enabled = true;
  7546. return;
  7547. }
  7548. //打开串口
  7549. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  7550. if (!mySerialProcess.mySerial.IsOpen)
  7551. {
  7552. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7553. button__FacMode_Start.Enabled = false;
  7554. return;
  7555. }
  7556. //流水号计数
  7557. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  7558. serial += 1;
  7559. label_CheckModeSerial.Text = serial.ToString();
  7560. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  7561. //创建线程,执行测试任务
  7562. Thread th = new Thread(CheckModeTest_Task);
  7563. th.Start();
  7564. }
  7565. /// <summary>
  7566. /// 执行一次测试任务
  7567. /// </summary>
  7568. private void CheckModeTest_Task()
  7569. {
  7570. //开始测试
  7571. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  7572. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  7573. //变量定义
  7574. var Code = new byte[255];//发送的指令数据
  7575. ushort DataTemp;
  7576. short DataTemp_Int16;
  7577. string ResultPathName = "";
  7578. label_CheckModeStatus.Text = "开始测试";
  7579. BootInfo = "";
  7580. Delay_ms(500);
  7581. label_CheckModeStatus.Text = "系统开机";
  7582. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  7583. if (uARTToolStripMenuItem.Checked)
  7584. {
  7585. Code[0] = (byte)'R';
  7586. Code[1] = (byte)'E';
  7587. Code[2] = (byte)'S';
  7588. Code[3] = (byte)'E';
  7589. Code[4] = (byte)'T';
  7590. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  7591. Delay_ms(500);
  7592. }
  7593. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  7594. //确保测试前先关机,发送关机指令再发送开机指令
  7595. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  7596. Code[0] = 0xF0;
  7597. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7598. Delay_ms(1500);
  7599. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  7600. Code[0] = 0xF1;
  7601. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7602. ACK_WaitCnt = 0;
  7603. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  7604. while (ACK_WaitCnt <= 20) ; //10s
  7605. //检查BOOT版本
  7606. if (BootInfo != string.Empty)
  7607. {
  7608. label_CheckModeBoot.BackColor = Color.Green;
  7609. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  7610. Delay_ms(500);
  7611. }
  7612. else
  7613. {
  7614. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  7615. label_CheckModeStatus.Text = "存在故障!";
  7616. label_CheckModeResult.BackColor = Color.Red;
  7617. label_CheckModeResult.Text = "测试异常";
  7618. Delay_ms(500);
  7619. //存储异常并上传
  7620. CheckMode_Stop(false);
  7621. return;
  7622. }
  7623. #if false
  7624. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7625. {
  7626. Code[0] = 0x00;//5S协议
  7627. Code[1] = 0x00;
  7628. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7629. Delay_ms(500);
  7630. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7631. Delay_ms(500);
  7632. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  7633. }
  7634. #endif
  7635. //发送指令读取版本信息
  7636. do
  7637. {
  7638. label_CheckModeStatus.Text = "读取版本信息";
  7639. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7640. //发送指令读取版本
  7641. Class_Motor_Ver.Mode = "---";
  7642. Class_Motor_Ver.SN = "---";
  7643. Class_Motor_Ver.HW = "---";
  7644. Class_Motor_Ver.FW = "---";
  7645. Class_Motor_Ver.Special = "---";
  7646. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7647. ACK_WaitCnt = 0;
  7648. while (ACK_WaitCnt <= 2) ; //1s
  7649. if (Class_Motor_Ver.Mode == "---")
  7650. {
  7651. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7652. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7653. ACK_WaitCnt = 0;
  7654. while (ACK_WaitCnt <= 2) ; //1s
  7655. if (Class_Motor_Ver.Mode == "---")
  7656. {
  7657. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7658. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7659. ACK_WaitCnt = 0;
  7660. while (ACK_WaitCnt <= 2) ; //1s
  7661. if (Class_Motor_Ver.Mode == "---")
  7662. {
  7663. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  7664. label_CheckModeStatus.Text = "存在故障!";
  7665. label_CheckModeResult.BackColor = Color.Red;
  7666. label_CheckModeResult.Text = "测试异常";
  7667. Delay_ms(500);
  7668. //存储异常并上传
  7669. CheckMode_Stop(false);
  7670. return;
  7671. }
  7672. }
  7673. }
  7674. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7675. Delay_ms(500);
  7676. } while (false);
  7677. //软件版本检查
  7678. if (checkBox_CheckModeFWVer.Checked)
  7679. {
  7680. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7681. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7682. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7683. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7684. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7685. //判断版本是否正确
  7686. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  7687. string VerRead = "";
  7688. try
  7689. {
  7690. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7691. }
  7692. catch (System.Exception)
  7693. {
  7694. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7695. label_CheckModeStatus.Text = "存在故障!";
  7696. label_CheckModeResult.BackColor = Color.Red;
  7697. label_CheckModeResult.Text = "测试异常";
  7698. Delay_ms(500);
  7699. //存储异常并上传
  7700. CheckMode_Stop(false);
  7701. return;
  7702. }
  7703. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7704. {
  7705. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7706. label_CheckModeStatus.Text = "存在故障!";
  7707. label_CheckModeResult.BackColor = Color.Red;
  7708. label_CheckModeResult.Text = "测试异常";
  7709. Delay_ms(500);
  7710. //存储异常并上传
  7711. CheckMode_Stop(false);
  7712. return;
  7713. }
  7714. label_CheckModeFWVer.BackColor = Color.Green;
  7715. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7716. Delay_ms(500);
  7717. }
  7718. else
  7719. {
  7720. label_CheckModeFWVer.BackColor = Color.Yellow;
  7721. label_CheckModeStatus.Text = "跳过软件版本查询";
  7722. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  7723. Delay_ms(500);
  7724. }
  7725. //打标信息核对
  7726. if (checkBox_CheckModeSN.Checked)
  7727. {
  7728. label_CheckModeStatus.Text = "核对打标信息";
  7729. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  7730. //根据扫码信息获取型号和SN
  7731. string ScanInfo = textBox_CheckModeScan.Text;
  7732. string regexInfo = "";
  7733. string[] InfoList = { "" };
  7734. try
  7735. {
  7736. if (中置电机ToolStripMenuItem.Checked == true)
  7737. {
  7738. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  7739. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  7740. }
  7741. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7742. {
  7743. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  7744. string Model = InfoList[0];
  7745. string Spec = InfoList[1];
  7746. string Sn = InfoList[2];
  7747. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  7748. InfoList[1] = Sn;
  7749. }
  7750. }
  7751. catch
  7752. {
  7753. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  7754. label_FacModeStatus.Text = "存在故障!";
  7755. label_FacModeResult.BackColor = Color.Red;
  7756. label_FacModeResult.Text = "标签格式错误";
  7757. Delay_ms(500);
  7758. //存储异常并上传
  7759. CheckMode_Stop(false);
  7760. return;
  7761. }
  7762. //核对型号
  7763. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  7764. {
  7765. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  7766. label_CheckModeStatus.Text = "存在故障!";
  7767. label_CheckModeResult.BackColor = Color.Red;
  7768. label_CheckModeResult.Text = "测试异常";
  7769. Delay_ms(500);
  7770. //存储异常并上传
  7771. CheckMode_Stop(false);
  7772. return;
  7773. }
  7774. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  7775. Delay_ms(500);
  7776. //核对SN
  7777. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  7778. {
  7779. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  7780. label_CheckModeStatus.Text = "存在故障!";
  7781. label_CheckModeResult.BackColor = Color.Red;
  7782. label_CheckModeResult.Text = "测试异常";
  7783. Delay_ms(500);
  7784. //存储异常并上传
  7785. CheckMode_Stop(false);
  7786. return;
  7787. }
  7788. label_CheckModeSN.BackColor = Color.Green;
  7789. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  7790. Delay_ms(500);
  7791. }
  7792. else
  7793. {
  7794. label_CheckModeSN.BackColor = Color.Yellow;
  7795. label_CheckModeStatus.Text = "跳过打标信息确认";
  7796. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  7797. Delay_ms(500);
  7798. }
  7799. //参数检验
  7800. if (checkBox_CheckModeCfg.Checked)
  7801. {
  7802. //读取配置文件信息
  7803. label_CheckModeStatus.Text = "参数检查";
  7804. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  7805. //配置文件
  7806. List<byte[]> CmdList = new List<byte[]>();
  7807. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  7808. //从服务器下载文件
  7809. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  7810. {
  7811. string SelectFile = "";
  7812. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  7813. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  7814. {
  7815. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  7816. }
  7817. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  7818. //打开文件
  7819. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  7820. ConfigCmd.Clear();
  7821. while (streamReader.Peek() != -1)
  7822. {
  7823. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  7824. if (fileLineInfo.Contains("["))
  7825. {
  7826. if (fileLineInfo.Contains("助力参数"))
  7827. {
  7828. fileLineInfo = streamReader.ReadLine();
  7829. }
  7830. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  7831. }
  7832. }
  7833. streamReader.Close();
  7834. }
  7835. //从本地加载文件
  7836. else
  7837. {
  7838. string SelectFile = "";
  7839. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  7840. //打开文件
  7841. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  7842. ConfigCmd.Clear();
  7843. while (streamReader.Peek() != -1)
  7844. {
  7845. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  7846. if (fileLineInfo.Contains("["))
  7847. {
  7848. if (fileLineInfo.Contains("助力参数"))
  7849. {
  7850. fileLineInfo = streamReader.ReadLine();
  7851. }
  7852. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  7853. }
  7854. }
  7855. streamReader.Close();
  7856. }
  7857. int CmdNum = ConfigCmd.Count(); //指令个数
  7858. Delay_ms(500);
  7859. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  7860. Delay_ms(500);
  7861. //逐条读取比较
  7862. try
  7863. {
  7864. foreach (string key in ConfigCmd.Keys)
  7865. {
  7866. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  7867. CmdRevStrTemp = "";
  7868. if (key.Contains("曲线"))
  7869. {
  7870. byte LineNum = 0;
  7871. var code = new byte[4];
  7872. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  7873. if (LineNum <= 5)
  7874. {
  7875. code[0] = (byte)(LineNum & 0xFF);
  7876. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7877. code[2] = (byte)(LineNum & 0xFF);
  7878. code[3] = (byte)((LineNum >> 8) & 0xFF);
  7879. }
  7880. else
  7881. {
  7882. code[0] = (byte)(LineNum & 0xFF);
  7883. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7884. code[2] = (byte)(5 & 0xFF);
  7885. code[3] = (byte)((5 >> 8) & 0xFF);
  7886. }
  7887. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  7888. }
  7889. else
  7890. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  7891. Delay_ms(500);
  7892. if (CmdRevStrTemp == string.Empty)
  7893. {
  7894. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  7895. if (key.Contains("曲线"))
  7896. {
  7897. byte LineNum = 0;
  7898. var code = new byte[4];
  7899. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  7900. if (LineNum <= 5)
  7901. {
  7902. code[0] = (byte)(LineNum & 0xFF);
  7903. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7904. code[2] = (byte)(LineNum & 0xFF);
  7905. code[3] = (byte)((LineNum >> 8) & 0xFF);
  7906. }
  7907. else
  7908. {
  7909. code[0] = (byte)(LineNum & 0xFF);
  7910. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7911. code[2] = (byte)(5 & 0xFF);
  7912. code[3] = (byte)((5 >> 8) & 0xFF);
  7913. }
  7914. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  7915. }
  7916. else
  7917. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  7918. Delay_ms(500);
  7919. if (CmdRevStrTemp == string.Empty)
  7920. {
  7921. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  7922. if (key.Contains("曲线"))
  7923. {
  7924. byte LineNum = 0;
  7925. var code = new byte[4];
  7926. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  7927. if (LineNum <= 5)
  7928. {
  7929. code[0] = (byte)(LineNum & 0xFF);
  7930. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7931. code[2] = (byte)(LineNum & 0xFF);
  7932. code[3] = (byte)((LineNum >> 8) & 0xFF);
  7933. }
  7934. else
  7935. {
  7936. code[0] = (byte)(LineNum & 0xFF);
  7937. code[1] = (byte)((LineNum >> 8) & 0xFF);
  7938. code[2] = (byte)(5 & 0xFF);
  7939. code[3] = (byte)((5 >> 8) & 0xFF);
  7940. }
  7941. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  7942. }
  7943. else
  7944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  7945. Delay_ms(500);
  7946. if (CmdRevStrTemp == string.Empty)
  7947. {
  7948. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  7949. label_CheckModeStatus.Text = "存在故障!";
  7950. label_CheckModeResult.BackColor = Color.Red;
  7951. label_CheckModeResult.Text = "测试异常";
  7952. Delay_ms(500);
  7953. //存储异常并上传
  7954. CheckMode_Stop(false);
  7955. return;
  7956. }
  7957. }
  7958. }
  7959. //比较当前指令,读取的配置文件和返回数据比较
  7960. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  7961. string ParamRead = "";
  7962. if (string.Compare(key, "[其它传感器参数]") == 0)
  7963. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //该指令包含力矩参数
  7964. else
  7965. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim();
  7966. if (ParamWrite.Contains(ParamRead))
  7967. {
  7968. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  7969. continue;
  7970. }
  7971. else
  7972. {
  7973. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  7974. label_CheckModeStatus.Text = "存在故障!";
  7975. label_CheckModeResult.BackColor = Color.Red;
  7976. label_CheckModeResult.Text = "测试异常";
  7977. Delay_ms(500);
  7978. //存储异常并上传
  7979. CheckMode_Stop(false);
  7980. return;
  7981. }
  7982. }
  7983. }
  7984. catch (System.Exception)
  7985. {
  7986. timer_1s.Enabled = false;
  7987. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7988. timer_1s.Enabled = true;
  7989. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  7990. }
  7991. }
  7992. else
  7993. {
  7994. label_CheckModeCfg.BackColor = Color.Yellow;
  7995. label_CheckModeStatus.Text = "跳过参数检验";
  7996. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  7997. Delay_ms(500);
  7998. }
  7999. label_CheckModeCfg.BackColor = Color.Green;
  8000. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8001. Delay_ms(500);
  8002. //读取力矩传感器
  8003. do
  8004. {
  8005. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8006. //发送指令读取力矩传感器标定数据
  8007. CmdRevStrTemp = "";
  8008. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8009. ACK_WaitCnt = 0;
  8010. while (ACK_WaitCnt <= 2) ; //1s
  8011. if (CmdRevStrTemp == "---")
  8012. {
  8013. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8014. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8015. ACK_WaitCnt = 0;
  8016. while (ACK_WaitCnt <= 2) ; //1s
  8017. if (CmdRevStrTemp == "---")
  8018. {
  8019. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8020. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8021. ACK_WaitCnt = 0;
  8022. while (ACK_WaitCnt <= 2) ; //1s
  8023. if (CmdRevStrTemp == "---")
  8024. {
  8025. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8026. label_CheckModeStatus.Text = "存在故障!";
  8027. label_CheckModeResult.BackColor = Color.Red;
  8028. label_CheckModeResult.Text = "测试异常";
  8029. Delay_ms(500);
  8030. //存储异常并上传
  8031. CheckMode_Stop(false);
  8032. return;
  8033. }
  8034. }
  8035. }
  8036. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8037. //取力矩传感器数据
  8038. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8039. ushort MaxTorque;
  8040. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8041. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8042. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8043. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8044. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8045. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8046. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8047. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8048. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8049. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8050. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8051. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8052. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8053. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8054. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8055. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8056. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8057. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8058. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8059. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8060. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8061. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8062. //传感器标定检验
  8063. if (checkBox_CheckModeTorque.Checked)
  8064. {
  8065. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8066. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8067. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8068. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8069. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8070. //与设置值比较
  8071. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8072. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8073. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8074. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8075. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8076. )
  8077. {
  8078. label_CheckModeTorque.BackColor = Color.Green;
  8079. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8080. Delay_ms(500);
  8081. }
  8082. else
  8083. {
  8084. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8085. label_CheckModeStatus.Text = "存在故障!";
  8086. label_CheckModeResult.BackColor = Color.Red;
  8087. label_CheckModeResult.Text = "测试异常";
  8088. Delay_ms(500);
  8089. //存储异常并上传
  8090. CheckMode_Stop(false);
  8091. return;
  8092. }
  8093. }
  8094. else
  8095. {
  8096. label_CheckModeTorque.BackColor = Color.Yellow;
  8097. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8098. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8099. Delay_ms(500);
  8100. }
  8101. } while (false);
  8102. //读取MOS内阻校准参数
  8103. do
  8104. {
  8105. if (checkBox_CheckModeMos.Checked)
  8106. {
  8107. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8108. //读取显示校准返回数据
  8109. foreach (Control c in groupBox21.Controls)
  8110. {
  8111. if (c is TextBox)
  8112. c.Text = "";
  8113. }
  8114. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8115. ACK_WaitCnt = 0;
  8116. while (ACK_WaitCnt <= 2) ; //1s
  8117. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8118. {
  8119. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8120. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8121. ACK_WaitCnt = 0;
  8122. while (ACK_WaitCnt <= 2) ; //1s
  8123. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8124. {
  8125. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8126. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8127. ACK_WaitCnt = 0;
  8128. while (ACK_WaitCnt <= 2) ; //1s
  8129. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8130. {
  8131. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8132. label_CheckModeStatus.Text = "存在故障!";
  8133. label_CheckModeResult.BackColor = Color.Red;
  8134. label_CheckModeResult.Text = "测试异常";
  8135. Delay_ms(500);
  8136. //存储异常并上传
  8137. CheckMode_Stop(false);
  8138. return;
  8139. }
  8140. }
  8141. }
  8142. else
  8143. {
  8144. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻:" + textBox_MOS_R1.Text + " " + textBox_MOS_R2.Text + " " + textBox_MOS_R3.Text + "\r\n");
  8145. }
  8146. //与校准返回数据对比
  8147. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8148. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8149. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8150. if ((Convert.ToUInt16(textBox_MOS_R1.Text) >= Convert.ToUInt16(MOS_R1_Th[0])) && (Convert.ToUInt16(textBox_MOS_R1.Text) <= Convert.ToUInt16(MOS_R1_Th[1])) &&
  8151. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8152. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8153. )
  8154. {
  8155. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8156. label_CheckModeMos.BackColor = Color.Green;
  8157. }
  8158. else
  8159. {
  8160. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8161. label_CheckModeStatus.Text = "存在故障!";
  8162. label_CheckModeResult.BackColor = Color.Red;
  8163. label_CheckModeResult.Text = "测试异常";
  8164. Delay_ms(500);
  8165. //存储异常并上传
  8166. CheckMode_Stop(false);
  8167. return;
  8168. }
  8169. }
  8170. else
  8171. {
  8172. label_CheckModeMos.BackColor = Color.Yellow;
  8173. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8174. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8175. Delay_ms(500);
  8176. }
  8177. } while (false);
  8178. //测试合格
  8179. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8180. label_CheckModeStatus.Text = "测试结束!";
  8181. label_CheckModeResult.BackColor = Color.Green;
  8182. label_CheckModeResult.Text = "测试合格";
  8183. Delay_ms(500);
  8184. //存储并上传
  8185. CheckMode_Stop(true);
  8186. return;
  8187. }
  8188. private void CheckModeLabelInit()
  8189. {
  8190. //测试状态标签
  8191. label_CheckModeResult.BackColor = Color.Yellow;
  8192. label_CheckModeResult.Text = "测试中";
  8193. //测试过程标签
  8194. label_CheckModeStatus.Text = "测试就绪";
  8195. //测试结果标签
  8196. foreach (Control c in groupBox31.Controls)
  8197. {
  8198. if (c is Label)
  8199. {
  8200. if (c.Text == string.Empty)
  8201. c.BackColor = Color.Red;
  8202. }
  8203. }
  8204. }
  8205. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8206. {
  8207. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8208. }
  8209. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8210. {
  8211. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8212. }
  8213. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8214. {
  8215. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8216. UInt32 hour = Time / 3600;
  8217. UInt32 min = (Time % 3600) / 60;
  8218. UInt32 s = (Time % 60);
  8219. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8220. }
  8221. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8222. {
  8223. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8224. richTextBox_CheckModeLog.ScrollToCaret();
  8225. }
  8226. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8227. {
  8228. TorqueParamsForm.ShowDialog();
  8229. }
  8230. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8231. {
  8232. if (e.KeyCode == Keys.Enter)
  8233. CheckTestStart();
  8234. }
  8235. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8236. {
  8237. if (e.KeyCode == Keys.Enter)
  8238. TestStart();
  8239. }
  8240. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8241. {
  8242. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8243. if (Percent <= 10)
  8244. Percent = 0;
  8245. else
  8246. Percent -= 10;
  8247. //生产模式转速设置值更新
  8248. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8249. //设置转速百分比
  8250. var Data = new byte[1];
  8251. Data[0] = (byte)Percent;
  8252. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8253. }
  8254. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  8255. {
  8256. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8257. if (Percent >= 90)
  8258. Percent = 100;
  8259. else
  8260. Percent += 10;
  8261. //生产模式转速设置值更新
  8262. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8263. //设置转速百分比
  8264. var Data = new byte[1];
  8265. Data[0] = (byte)Percent;
  8266. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8267. }
  8268. private void button_SpeedDec1_Click(object sender, EventArgs e)
  8269. {
  8270. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8271. if (Percent <= 1)
  8272. Percent = 0;
  8273. else
  8274. Percent -= 1;
  8275. //生产模式转速设置值更新
  8276. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8277. //设置转速百分比
  8278. var Data = new byte[1];
  8279. Data[0] = (byte)Percent;
  8280. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8281. }
  8282. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  8283. {
  8284. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8285. if (Percent >= 99)
  8286. Percent = 100;
  8287. else
  8288. Percent += 1;
  8289. //生产模式转速设置值更新
  8290. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8291. //设置转速百分比
  8292. var Data = new byte[1];
  8293. Data[0] = (byte)Percent;
  8294. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8295. }
  8296. bool WriteLockStatus = true;
  8297. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  8298. {
  8299. if (WriteLockStatus == true)
  8300. {
  8301. EnterForm1.ShowDialog();
  8302. try
  8303. {
  8304. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8305. {
  8306. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8307. {
  8308. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8309. foreach (Control c in groupBox2.Controls)
  8310. {
  8311. if (c is CheckBox)
  8312. c.Enabled = true;
  8313. }
  8314. WriteLockStatus = !WriteLockStatus;
  8315. }
  8316. else
  8317. {
  8318. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8319. }
  8320. }
  8321. else
  8322. {
  8323. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8324. }
  8325. }
  8326. catch (Exception)
  8327. {
  8328. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8329. }
  8330. }
  8331. else
  8332. {
  8333. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8334. foreach (Control c in groupBox2.Controls)
  8335. {
  8336. if (c is CheckBox)
  8337. c.Enabled = false;
  8338. }
  8339. WriteLockStatus = !WriteLockStatus;
  8340. }
  8341. }
  8342. bool ReadLockStatus = true;
  8343. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  8344. {
  8345. if (ReadLockStatus == true)
  8346. {
  8347. EnterForm1.ShowDialog();
  8348. try
  8349. {
  8350. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8351. {
  8352. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8353. {
  8354. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8355. foreach (Control c in groupBox29.Controls)
  8356. {
  8357. if (c is CheckBox)
  8358. c.Enabled = true;
  8359. }
  8360. ReadLockStatus = !ReadLockStatus;
  8361. }
  8362. else
  8363. {
  8364. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8365. }
  8366. }
  8367. else
  8368. {
  8369. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8370. }
  8371. }
  8372. catch (Exception)
  8373. {
  8374. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8375. }
  8376. }
  8377. else
  8378. {
  8379. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8380. foreach (Control c in groupBox29.Controls)
  8381. {
  8382. if (c is CheckBox)
  8383. c.Enabled = false;
  8384. }
  8385. ReadLockStatus = !ReadLockStatus;
  8386. }
  8387. }
  8388. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  8389. {
  8390. System.Diagnostics.Process.Start("osk.exe");
  8391. }
  8392. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  8393. {
  8394. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  8395. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  8396. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  8397. }
  8398. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  8399. {
  8400. comboBox_FacModeCfgDate.SelectedIndex = -1;
  8401. comboBox_FacModeCfgFile.SelectedIndex = -1;
  8402. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  8403. }
  8404. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  8405. {
  8406. VersionForm.ShowDialog();
  8407. }
  8408. private void button_MOS_Cal_Click(object sender, EventArgs e)
  8409. {
  8410. textBox_MOS_R1.Text = "";
  8411. textBox_MOS_R2.Text = "";
  8412. textBox_MOS_R3.Text = "";
  8413. try
  8414. {
  8415. var Code = new byte[18];
  8416. for (int i = 0; i < 18; i++)
  8417. Code[i] = 0;
  8418. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8419. ushort uwDataTemp = 0;
  8420. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8421. Code[2] = (byte)(uwDataTemp & 0xFF);
  8422. Code[3] = (byte)(uwDataTemp >> 8);
  8423. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8424. Code[4] = (byte)(uwDataTemp & 0xFF);
  8425. Code[5] = (byte)(uwDataTemp >> 8);
  8426. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8427. Code[6] = (byte)(uwDataTemp & 0xFF);
  8428. Code[7] = (byte)(uwDataTemp >> 8);
  8429. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8430. Code[8] = (byte)(uwDataTemp & 0xFF);
  8431. Code[9] = (byte)(uwDataTemp >> 8);
  8432. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8433. Code[10] = (byte)(uwDataTemp & 0xFF);
  8434. Code[11] = (byte)(uwDataTemp >> 8);
  8435. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  8436. }
  8437. catch (Exception)
  8438. {
  8439. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8440. }
  8441. }
  8442. private void button_MOS_Read_Click(object sender, EventArgs e)
  8443. {
  8444. foreach (Control c in groupBox21.Controls)
  8445. {
  8446. if (c is TextBox)
  8447. c.Text = "";
  8448. }
  8449. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8450. }
  8451. private void button_MOS_Write_Click(object sender, EventArgs e)
  8452. {
  8453. try
  8454. {
  8455. var Code = new byte[34];
  8456. for (int i = 0; i < 34; i++)
  8457. Code[i] = 0;
  8458. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8459. ushort uwDataTemp = 0;
  8460. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  8461. Code[2] = (byte)(uwDataTemp & 0xFF);
  8462. Code[3] = (byte)(uwDataTemp >> 8);
  8463. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  8464. Code[4] = (byte)(uwDataTemp & 0xFF);
  8465. Code[5] = (byte)(uwDataTemp >> 8);
  8466. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  8467. Code[6] = (byte)(uwDataTemp & 0xFF);
  8468. Code[7] = (byte)(uwDataTemp >> 8);
  8469. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8470. Code[8] = (byte)(uwDataTemp & 0xFF);
  8471. Code[9] = (byte)(uwDataTemp >> 8);
  8472. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8473. Code[10] = (byte)(uwDataTemp & 0xFF);
  8474. Code[11] = (byte)(uwDataTemp >> 8);
  8475. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8476. Code[12] = (byte)(uwDataTemp & 0xFF);
  8477. Code[13] = (byte)(uwDataTemp >> 8);
  8478. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8479. Code[14] = (byte)(uwDataTemp & 0xFF);
  8480. Code[15] = (byte)(uwDataTemp >> 8);
  8481. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8482. Code[16] = (byte)(uwDataTemp & 0xFF);
  8483. Code[17] = (byte)(uwDataTemp >> 8);
  8484. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  8485. }
  8486. catch (Exception)
  8487. {
  8488. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8489. }
  8490. }
  8491. /// <summary>
  8492. /// 测试模式点击文本框自动全选
  8493. /// </summary>
  8494. /// <param name="sender"></param>
  8495. /// <param name="e"></param>
  8496. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  8497. {
  8498. textBox_FacModeScan.SelectAll();
  8499. }
  8500. /// <summary>
  8501. /// 检验模式点击文本框自动全选
  8502. /// </summary>
  8503. /// <param name="sender"></param>
  8504. /// <param name="e"></param>
  8505. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  8506. {
  8507. textBox_CheckModeScan.SelectAll();
  8508. }
  8509. /// <summary>
  8510. /// 鼠标放置显示连接服务器信息
  8511. /// </summary>
  8512. /// <param name="sender"></param>
  8513. /// <param name="e"></param>
  8514. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  8515. {
  8516. // 创建the ToolTip
  8517. ToolTip toolTip1 = new ToolTip();
  8518. // 设置显示样式
  8519. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  8520. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  8521. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  8522. toolTip1.ShowAlways = true;//是否显示提示框
  8523. if (myFtp.IsNetConnected)
  8524. {
  8525. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + toolStripTextBox_ServerIP.Text);//设置故障内容显示
  8526. }
  8527. else
  8528. {
  8529. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  8530. }
  8531. }
  8532. /// <summary>
  8533. /// UART协议类型修改
  8534. /// </summary>
  8535. /// <param name="sender"></param>
  8536. /// <param name="e"></param>
  8537. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  8538. {
  8539. var Code = new byte[2];
  8540. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  8541. Code[1] = 0x00;
  8542. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8543. }
  8544. /// <summary>
  8545. /// 显示本机信息
  8546. /// </summary>
  8547. /// <param name="sender"></param>
  8548. /// <param name="e"></param>
  8549. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  8550. {
  8551. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  8552. }
  8553. /// <summary>
  8554. /// 量产模式删除当前选中文件
  8555. /// </summary>
  8556. /// <param name="sender"></param>
  8557. /// <param name="e"></param>
  8558. private void label112_DoubleClick(object sender, EventArgs e)
  8559. {
  8560. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8561. {
  8562. EnterForm1.ShowDialog();
  8563. try
  8564. {
  8565. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8566. {
  8567. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8568. {
  8569. try
  8570. {
  8571. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  8572. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  8573. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  8574. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8575. }
  8576. catch (Exception)
  8577. {
  8578. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8579. }
  8580. }
  8581. else
  8582. {
  8583. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8584. }
  8585. }
  8586. }
  8587. catch (Exception)
  8588. {
  8589. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8590. }
  8591. }
  8592. }
  8593. /// <summary>
  8594. /// 检验模式删除当前选中文件
  8595. /// </summary>
  8596. /// <param name="sender"></param>
  8597. /// <param name="e"></param>
  8598. private void label138_DoubleClick(object sender, EventArgs e)
  8599. {
  8600. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8601. {
  8602. EnterForm1.ShowDialog();
  8603. try
  8604. {
  8605. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8606. {
  8607. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8608. {
  8609. try
  8610. {
  8611. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  8612. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  8613. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  8614. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8615. }
  8616. catch (Exception)
  8617. {
  8618. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8619. }
  8620. }
  8621. else
  8622. {
  8623. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8624. }
  8625. }
  8626. }
  8627. catch (Exception)
  8628. {
  8629. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8630. }
  8631. }
  8632. }
  8633. /// <summary>
  8634. /// 读取整车信息2
  8635. /// </summary>
  8636. /// <param name="sender"></param>
  8637. /// <param name="e"></param>
  8638. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  8639. {
  8640. richTextBox_BikeParam2.Clear();
  8641. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  8642. }
  8643. /// <summary>
  8644. /// 写入整车信息2
  8645. /// </summary>
  8646. /// <param name="sender"></param>
  8647. /// <param name="e"></param>
  8648. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  8649. {
  8650. var ConfigParam = new byte[34];
  8651. for (int i = 0; i < 34; i++)
  8652. ConfigParam[i] = 0;
  8653. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8654. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8655. try
  8656. {
  8657. for (int i = 0; i < strDataTemp.Length; i++)
  8658. {
  8659. short wDataTemp = 0;
  8660. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8661. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8662. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  8663. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  8664. }
  8665. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  8666. }
  8667. catch (Exception)
  8668. {
  8669. timer_1s.Enabled = false;
  8670. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8671. timer_1s.Enabled = true;
  8672. }
  8673. }
  8674. /// <summary>
  8675. /// 读取用户骑行参数
  8676. /// </summary>
  8677. /// <param name="sender"></param>
  8678. /// <param name="e"></param>
  8679. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  8680. {
  8681. richTextBox_UsrRidesParam.Clear();
  8682. if (checkBox_UserRideParam_OBC.Checked)
  8683. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  8684. else
  8685. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  8686. }
  8687. /// <summary>
  8688. /// 写入用户骑行参数
  8689. /// </summary>
  8690. /// <param name="sender"></param>
  8691. /// <param name="e"></param>
  8692. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  8693. {
  8694. var ConfigParam = new byte[34];
  8695. for (int i = 0; i < 34; i++)
  8696. ConfigParam[i] = 0;
  8697. if (checkBox_UserRideParam_OBC.Checked)
  8698. {
  8699. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8700. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8701. try
  8702. {
  8703. for (int i = 0; i < strDataTemp.Length; i++)
  8704. {
  8705. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  8706. }
  8707. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  8708. }
  8709. catch (Exception)
  8710. {
  8711. timer_1s.Enabled = false;
  8712. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8713. timer_1s.Enabled = true;
  8714. }
  8715. }
  8716. else
  8717. {
  8718. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8719. try
  8720. {
  8721. for (int i = 0; i < strDataTemp.Length; i++)
  8722. {
  8723. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  8724. }
  8725. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  8726. }
  8727. catch (Exception)
  8728. {
  8729. timer_1s.Enabled = false;
  8730. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8731. timer_1s.Enabled = true;
  8732. }
  8733. }
  8734. }
  8735. /// <summary>
  8736. /// 读取产品标签
  8737. /// </summary>
  8738. /// <param name="sender"></param>
  8739. /// <param name="e"></param>
  8740. private void button_ReadTag_Click(object sender, EventArgs e)
  8741. {
  8742. textBox_TagInfo.Text = "---";
  8743. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  8744. }
  8745. /// <summary>
  8746. /// 写入产品标签
  8747. /// </summary>
  8748. /// <param name="sender"></param>
  8749. /// <param name="e"></param>
  8750. private void button_WriteTag_Click(object sender, EventArgs e)
  8751. {
  8752. string User = textBox_TagInfo.Text;
  8753. var UserArray = new byte[32];
  8754. for (ushort i = 0; i < User.Length; i++)
  8755. {
  8756. UserArray[i] = (byte)User[i];
  8757. }
  8758. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  8759. }
  8760. /// <summary>
  8761. /// 上位机读取骑行历史
  8762. /// </summary>
  8763. /// <param name="sender"></param>
  8764. /// <param name="e"></param>
  8765. private void button_ReadRideLog_Click(object sender, EventArgs e)
  8766. {
  8767. textBox_ODO_KM.Text = "---";
  8768. textBox_ODO_TIME.Text = "---";
  8769. textBox_TRIP_KM.Text = "---";
  8770. textBox_TRIP_TIME.Text = "---";
  8771. textBox_OBC_TRIP_KM.Text = "";
  8772. textBox_OBC_TRIP_TIME.Text = "";
  8773. textBox_OBC_ODO_KM.Text = "";
  8774. textBox_OBC_ODO_TIME.Text = "";
  8775. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  8776. }
  8777. /// <summary>
  8778. /// 上位机写入骑行历史
  8779. /// </summary>
  8780. /// <param name="sender"></param>
  8781. /// <param name="e"></param>
  8782. private void button_WriteRideLog_Click(object sender, EventArgs e)
  8783. {
  8784. UInt32 Data;
  8785. var UserArray = new byte[16];
  8786. try
  8787. {
  8788. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  8789. UserArray[0] = (byte)(Data & 0xFF);
  8790. UserArray[1] = (byte)(Data >> 8);
  8791. UserArray[2] = (byte)(Data >> 16);
  8792. UserArray[3] = (byte)(Data >> 24);
  8793. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  8794. UserArray[4] = (byte)(Data & 0xFF);
  8795. UserArray[5] = (byte)(Data >> 8);
  8796. UserArray[6] = (byte)(Data >> 16);
  8797. UserArray[7] = (byte)(Data >> 24);
  8798. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  8799. UserArray[8] = (byte)(Data & 0xFF);
  8800. UserArray[9] = (byte)(Data >> 8);
  8801. UserArray[10] = (byte)(Data >> 16);
  8802. UserArray[11] = (byte)(Data >> 24);
  8803. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  8804. UserArray[12] = (byte)(Data & 0xFF);
  8805. UserArray[13] = (byte)(Data >> 8);
  8806. UserArray[14] = (byte)(Data >> 16);
  8807. UserArray[15] = (byte)(Data >> 24);
  8808. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  8809. }
  8810. catch (Exception ex)
  8811. {
  8812. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8813. }
  8814. }
  8815. /// <summary>
  8816. /// 获取删除配置文件日期列表
  8817. /// </summary>
  8818. /// <param name="sender"></param>
  8819. /// <param name="e"></param>
  8820. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  8821. {
  8822. string[] DateList = { "" };
  8823. //网络断开时直接退出
  8824. if (!myFtp.IsNetConnected)
  8825. return;
  8826. //从服务器更新日期列表
  8827. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  8828. toolStripTextBox_DelCfgFile.Items.Clear();
  8829. //日期列表加载,显示最近30条
  8830. if (DateList.Length > 30)
  8831. {
  8832. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  8833. toolStripTextBox_DelCfgFile.Items.Add("-----");
  8834. }
  8835. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  8836. {
  8837. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  8838. }
  8839. }
  8840. /// <summary>
  8841. /// 删除指定配置文件
  8842. /// </summary>
  8843. /// <param name="sender"></param>
  8844. /// <param name="e"></param>
  8845. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  8846. {
  8847. //提示输入文件名
  8848. Scan scan_form = new Scan();
  8849. scan_form.ShowDialog();
  8850. do
  8851. {
  8852. if (scan_form.textBox_Scan.Text == string.Empty)
  8853. {
  8854. timer_1s.Enabled = false;
  8855. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8856. timer_1s.Enabled = true;
  8857. break;
  8858. }
  8859. string DelFile = scan_form.textBox_Scan.Text;
  8860. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8861. {
  8862. EnterForm1.ShowDialog();
  8863. try
  8864. {
  8865. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8866. {
  8867. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8868. {
  8869. try
  8870. {
  8871. if (DelFile.Contains("."))
  8872. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  8873. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  8874. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  8875. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  8876. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8877. }
  8878. catch (Exception)
  8879. {
  8880. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8881. }
  8882. }
  8883. else
  8884. {
  8885. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8886. }
  8887. }
  8888. }
  8889. catch (Exception)
  8890. {
  8891. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8892. }
  8893. }
  8894. } while (false);
  8895. }
  8896. /// <summary>
  8897. /// 获取删除样机测试记录日期列表
  8898. /// </summary>
  8899. /// <param name="sender"></param>
  8900. /// <param name="e"></param>
  8901. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  8902. {
  8903. string[] DateList = { "" };
  8904. //网络断开时直接退出
  8905. if (!myFtp.IsNetConnected)
  8906. return;
  8907. //从服务器更新日期列表
  8908. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  8909. toolStripTextBox_DelLogFile.Items.Clear();
  8910. //日期列表加载,显示最近30天
  8911. if (DateList.Length > 30)
  8912. {
  8913. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  8914. toolStripTextBox_DelLogFile.Items.Add("-----");
  8915. }
  8916. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  8917. {
  8918. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  8919. }
  8920. }
  8921. /// <summary>
  8922. /// 删除指定的样机测试记录
  8923. /// </summary>
  8924. /// <param name="sender"></param>
  8925. /// <param name="e"></param>
  8926. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  8927. {
  8928. //提示输入文件名
  8929. Scan scan_form = new Scan();
  8930. scan_form.ShowDialog();
  8931. do
  8932. {
  8933. if (scan_form.textBox_Scan.Text == string.Empty)
  8934. {
  8935. timer_1s.Enabled = false;
  8936. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8937. timer_1s.Enabled = true;
  8938. break;
  8939. }
  8940. string DelFile = scan_form.textBox_Scan.Text;
  8941. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8942. {
  8943. EnterForm1.ShowDialog();
  8944. try
  8945. {
  8946. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8947. {
  8948. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8949. {
  8950. try
  8951. {
  8952. //删除指定目录下面所有文件和文件夹
  8953. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  8954. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  8955. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8956. }
  8957. catch (Exception)
  8958. {
  8959. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8960. }
  8961. }
  8962. else
  8963. {
  8964. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8965. }
  8966. }
  8967. }
  8968. catch (Exception)
  8969. {
  8970. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8971. }
  8972. }
  8973. } while (false);
  8974. }
  8975. /// <summary>
  8976. /// CAN协议选择
  8977. /// </summary>
  8978. /// <param name="sender"></param>
  8979. /// <param name="e"></param>
  8980. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  8981. {
  8982. cANToolStripMenuItem.Checked= true;
  8983. uARTToolStripMenuItem.Checked = false;
  8984. UART协议ToolStripMenuItem.Visible = false;
  8985. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8986. }
  8987. /// <summary>
  8988. /// UART协议选择
  8989. /// </summary>
  8990. /// <param name="sender"></param>
  8991. /// <param name="e"></param>
  8992. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  8993. {
  8994. cANToolStripMenuItem.Checked = false;
  8995. uARTToolStripMenuItem.Checked = true;
  8996. UART协议ToolStripMenuItem.Visible = true;
  8997. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  8998. }
  8999. /// <summary>
  9000. /// 清除流水号
  9001. /// </summary>
  9002. /// <param name="sender"></param>
  9003. /// <param name="e"></param>
  9004. private void label131_DoubleClick(object sender, EventArgs e)
  9005. {
  9006. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9007. {
  9008. label_FacModeSerial.Text = "0";
  9009. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9010. }
  9011. }
  9012. /// <summary>
  9013. /// 清除流水号
  9014. /// </summary>
  9015. /// <param name="sender"></param>
  9016. /// <param name="e"></param>
  9017. private void label135_DoubleClick(object sender, EventArgs e)
  9018. {
  9019. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9020. {
  9021. label_CheckModeSerial.Text = "0";
  9022. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9023. }
  9024. }
  9025. /// <summary>
  9026. /// 打开自动更新
  9027. /// </summary>
  9028. /// <param name="sender"></param>
  9029. /// <param name="e"></param>
  9030. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9031. {
  9032. 打开ToolStripMenuItem.Checked = true;
  9033. 关闭ToolStripMenuItem.Checked = false;
  9034. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9035. }
  9036. /// <summary>
  9037. /// 关闭自动更新
  9038. /// </summary>
  9039. /// <param name="sender"></param>
  9040. /// <param name="e"></param>
  9041. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9042. {
  9043. 打开ToolStripMenuItem.Checked = false;
  9044. 关闭ToolStripMenuItem.Checked = true;
  9045. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9046. }
  9047. /// <summary>
  9048. /// 显示完整配置文件
  9049. /// </summary>
  9050. /// <param name="sender"></param>
  9051. /// <param name="e"></param>
  9052. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9053. {
  9054. // 创建the ToolTip
  9055. ToolTip toolTip1 = new ToolTip();
  9056. // 设置显示样式
  9057. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9058. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9059. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9060. toolTip1.ShowAlways = true;//是否显示提示框
  9061. // 设置伴随的对象.
  9062. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9063. }
  9064. /// <summary>
  9065. /// 显示完整配置文件
  9066. /// </summary>
  9067. /// <param name="sender"></param>
  9068. /// <param name="e"></param>
  9069. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9070. {
  9071. // 创建the ToolTip
  9072. ToolTip toolTip1 = new ToolTip();
  9073. // 设置显示样式
  9074. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9075. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9076. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9077. toolTip1.ShowAlways = true;//是否显示提示框
  9078. // 设置伴随的对象.
  9079. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9080. }
  9081. /// <summary>
  9082. /// 手动发送指令
  9083. /// </summary>
  9084. /// <param name="sender"></param>
  9085. /// <param name="e"></param>
  9086. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9087. {
  9088. //提示
  9089. MessageBoxTimeOut.Show("按照16进制填写,相邻字节用空格隔开\r\n依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9090. Scan scan_form = new Scan();
  9091. scan_form.ShowDialog();
  9092. //发送写入的指令,填写ID、类型、命令字、数据
  9093. do
  9094. {
  9095. if (scan_form.textBox_Scan.Text == string.Empty)
  9096. {
  9097. timer_1s.Enabled = false;
  9098. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9099. timer_1s.Enabled = true;
  9100. break;
  9101. }
  9102. //输入文本转换为字节流
  9103. var InputData = new byte[256];
  9104. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9105. //ID
  9106. ushort ID;
  9107. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9108. //Mode
  9109. byte Mode;
  9110. Mode = InputData[2];
  9111. //Cmd
  9112. ushort Cmd;
  9113. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9114. //Data
  9115. var Data = new byte[Cmd & 0x00FF];
  9116. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9117. Data[i] = InputData[5 + i];
  9118. //发送数据
  9119. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9120. } while (false);
  9121. }
  9122. /// <summary>
  9123. /// 打开或关闭指令窗口
  9124. /// </summary>
  9125. /// <param name="sender"></param>
  9126. /// <param name="e"></param>
  9127. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  9128. {
  9129. if (指令调试ToolStripMenuItem.Checked == false)
  9130. {
  9131. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  9132. {
  9133. DebugForm.debug1 = new DebugForm();
  9134. DebugForm.debug1.Show();
  9135. this.DebugWindowIsOpen = true;
  9136. }
  9137. else
  9138. {
  9139. DebugForm.debug1.Activate();
  9140. this.DebugWindowIsOpen = true;
  9141. }
  9142. 指令调试ToolStripMenuItem.Checked = true;
  9143. }
  9144. else
  9145. {
  9146. if (this.DebugWindowIsOpen == true)
  9147. {
  9148. DebugForm.debug1.Close();
  9149. this.DebugWindowIsOpen = false;
  9150. this.DebugDataDisplayEnable = false;
  9151. }
  9152. 指令调试ToolStripMenuItem.Checked = false;
  9153. }
  9154. }
  9155. }
  9156. }