mainForm.cs 481 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196
  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.3.0";
  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. public string ServerIP = "";
  35. public string ServerPort = "";
  36. public string ServerUser = "";
  37. public string ServerPassWd = "";
  38. public bool OfflineFlag = false;
  39. //MC运行信息超时计数
  40. bool MC_RunInfo_Refresh = false;
  41. ushort MC_RunInfo_Refresh_Cnt = 0;
  42. //MC调试信息超时计数
  43. bool MC_DebugInfo_Refresh = false;
  44. ushort MC_DebugInfo_Refresh_Cnt = 0;
  45. //MC故障码超时计数
  46. bool MC_ErrorCode_Refresh = false;
  47. ushort MC_ErrorCode_Refresh_Cnt = 0;
  48. //配置参数实例
  49. Params myParams = new Params();
  50. //记录文件名称
  51. string RunInfoSaveFilename = "";
  52. //BMS运行信息超时计数
  53. bool BMS_RunInfo_Refresh = false;
  54. ushort BMS_RunInfo_Refresh_Cnt = 0;
  55. //生产模式关机指令反馈状态
  56. bool PowerOffAckStatus = false;
  57. //登录窗口
  58. public static Login EnterForm1 = new Login();
  59. //生产配置文件信息
  60. ArrayList array_CfgInfo = new ArrayList();
  61. //写入参数返回标志和计数
  62. public bool WriteACK = false;
  63. public ushort WriteCnt = 0;
  64. public ushort ACK_WaitCnt = 0;
  65. //写入参数返回提示标志
  66. public bool ACK_DisFlag = true;
  67. //Boot版本信息
  68. public string BootInfo = "";
  69. //接收指令临时缓存,转string
  70. public string CmdRevStrTemp = "";
  71. //计时器,用于统计运行时间
  72. public Stopwatch stopwatch = new Stopwatch();
  73. //力矩传感器检验参数窗口
  74. public static TorqueParams TorqueParamsForm = new TorqueParams();
  75. //参数生成窗口
  76. public static GenerateParams GenerateParamsForm = new GenerateParams();
  77. //版本信息窗口
  78. public static Version VersionForm = new Version();
  79. //本机硬件信息
  80. public string Local_HdInformation = "";
  81. //指令窗口显示
  82. public bool DebugWindowIsOpen = false, DebugDataDisplayEnable = false;
  83. //位置传感器数据记录
  84. string[] AngledataRecord = new string[42];
  85. //服务器设置窗口
  86. public static ServerSelect ServerCfgForm1 = new ServerSelect();
  87. #endregion
  88. #region 故障日志结构体定义
  89. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  90. [StructLayout(LayoutKind.Sequential)]
  91. public struct MC_ErrorLogSaveInfo_Struct_t
  92. {
  93. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  94. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  95. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  96. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  97. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  98. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  99. //电机运行信息,占用空间32bytes
  100. [StructLayout(LayoutKind.Sequential)]
  101. public struct MC_RunInfo_Struct_t
  102. {
  103. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  104. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  105. public ushort Power; //电功率 1W,地址偏移4
  106. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  107. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  108. public byte Cadence; //踏频 1rpm,地址偏移10
  109. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  110. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  111. public byte GearSt; //助力档位,地址偏移13
  112. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  113. public byte SOC; //剩余电量 1%,地址偏移15
  114. public ushort RemainDistance; //续航里程 1km,地址偏移16
  115. public ushort Torque_AD; //力矩寄存器,地址偏移18
  116. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  117. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  118. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  119. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  120. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  121. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  122. public UInt32 RS; //预留 4bytes
  123. };
  124. [MarshalAs(UnmanagedType.Struct)]
  125. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  126. //控制变量
  127. public Int16 IqCurrent; //Pu, 地址偏移 48
  128. public Int16 IqVoltage; //Pu, 地址偏移 50
  129. public Int16 IdCurrent; //Pu, 地址偏移 52
  130. public Int16 IdVoltage; //Pu, 地址偏移 54
  131. //状态机
  132. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  133. //预留
  134. public UInt16 RS1;
  135. public UInt16 RS2;
  136. public UInt16 RS3;
  137. };
  138. #endregion
  139. #region 屏幕缩放比例获取
  140. public class PrimaryScreen
  141. {
  142. #region Win32 API
  143. [DllImport("user32.dll")]
  144. static extern IntPtr GetDC(IntPtr ptr);
  145. [DllImport("gdi32.dll")]
  146. static extern int GetDeviceCaps(
  147. IntPtr hdc, // handle to DC
  148. int nIndex // index of capability
  149. );
  150. [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  151. static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
  152. #endregion
  153. #region DeviceCaps常量
  154. const int HORZRES = 8;
  155. const int VERTRES = 10;
  156. const int LOGPIXELSX = 88;
  157. const int LOGPIXELSY = 90;
  158. const int DESKTOPVERTRES = 117;
  159. const int DESKTOPHORZRES = 118;
  160. #endregion
  161. #region 属性
  162. /// <summary>
  163. /// 获取屏幕分辨率当前物理大小
  164. /// </summary>
  165. public static Size WorkingArea
  166. {
  167. get
  168. {
  169. IntPtr hdc = GetDC(IntPtr.Zero);
  170. Size size = new Size();
  171. size.Width = GetDeviceCaps(hdc, HORZRES);
  172. size.Height = GetDeviceCaps(hdc, VERTRES);
  173. ReleaseDC(IntPtr.Zero, hdc);
  174. return size;
  175. }
  176. }
  177. /// <summary>
  178. /// 当前系统DPI_X 大小 一般为96
  179. /// </summary>
  180. public static int DpiX
  181. {
  182. get
  183. {
  184. IntPtr hdc = GetDC(IntPtr.Zero);
  185. int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
  186. ReleaseDC(IntPtr.Zero, hdc);
  187. return DpiX;
  188. }
  189. }
  190. /// <summary>
  191. /// 当前系统DPI_Y 大小 一般为96
  192. /// </summary>
  193. public static int DpiY
  194. {
  195. get
  196. {
  197. IntPtr hdc = GetDC(IntPtr.Zero);
  198. int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
  199. ReleaseDC(IntPtr.Zero, hdc);
  200. return DpiX;
  201. }
  202. }
  203. /// <summary>
  204. /// 获取真实设置的桌面分辨率大小
  205. /// </summary>
  206. public static Size DESKTOP
  207. {
  208. get
  209. {
  210. IntPtr hdc = GetDC(IntPtr.Zero);
  211. Size size = new Size();
  212. size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
  213. size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
  214. ReleaseDC(IntPtr.Zero, hdc);
  215. return size;
  216. }
  217. }
  218. /// <summary>
  219. /// 获取宽度缩放百分比
  220. /// </summary>
  221. public static float ScaleX
  222. {
  223. get
  224. {
  225. IntPtr hdc = GetDC(IntPtr.Zero);
  226. int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
  227. int d = GetDeviceCaps(hdc, HORZRES);
  228. float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
  229. ReleaseDC(IntPtr.Zero, hdc);
  230. return ScaleX;
  231. }
  232. }
  233. /// <summary>
  234. /// 获取高度缩放百分比
  235. /// </summary>
  236. public static float ScaleY
  237. {
  238. get
  239. {
  240. IntPtr hdc = GetDC(IntPtr.Zero);
  241. float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
  242. ReleaseDC(IntPtr.Zero, hdc);
  243. return ScaleY;
  244. }
  245. }
  246. #endregion
  247. }
  248. #endregion
  249. public static mainForm mainform1 = null;
  250. public mainForm()
  251. {
  252. InitializeComponent();
  253. mainform1 = this;
  254. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  255. stopwatch.Start();
  256. //端口初始化
  257. mySerialProcess.Init();
  258. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  259. //检查备忘录文件
  260. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  261. {
  262. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
  263. }
  264. //检验流水号记录文件
  265. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
  266. {
  267. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
  268. }
  269. if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
  270. {
  271. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
  272. }
  273. //检查文件夹
  274. if (!Directory.Exists(localInfo.LocalPath))
  275. {
  276. Directory.CreateDirectory(localInfo.LocalPath);
  277. }
  278. if (!Directory.Exists(localInfo.LocalDataPath))
  279. {
  280. Directory.CreateDirectory(localInfo.LocalDataPath);
  281. }
  282. if (!Directory.Exists(localInfo.ToolsPath))
  283. {
  284. Directory.CreateDirectory(localInfo.ToolsPath);
  285. }
  286. if (!Directory.Exists(localInfo.LocalPath + localInfo.CfgPathName))
  287. {
  288. Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
  289. }
  290. //服务器初始化
  291. do
  292. {
  293. //检查是否存在配置文件
  294. if (File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName)) //存在配置文件从文件选择
  295. {
  296. //打开文件
  297. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ServerCfgFileName);
  298. string sLine = "";
  299. ArrayList array_CfgInfo = new ArrayList();
  300. array_CfgInfo.Clear();
  301. while (sLine != null)
  302. {
  303. sLine = objReader.ReadLine();
  304. array_CfgInfo.Add(sLine);
  305. }
  306. objReader.Close();
  307. //解析配置文件
  308. ServerIP = array_CfgInfo[0].ToString();
  309. ServerPort = array_CfgInfo[1].ToString();
  310. ServerUser = array_CfgInfo[2].ToString();
  311. ServerPassWd = array_CfgInfo[3].ToString();
  312. if (array_CfgInfo[4].ToString() == "True")
  313. {
  314. OfflineFlag = true;
  315. checkBox_OffLineFacMode.Checked = true;
  316. checkBox_OffLineCheckMode.Checked = true;
  317. }
  318. }
  319. else //不存在配置文件由用户选择
  320. {
  321. ServerCfgForm1.ShowDialog();
  322. switch (ServerCfgForm1.comboBox_Server.SelectedIndex)
  323. {
  324. case 0: //武汉园区
  325. case 1: //顺德工厂
  326. {
  327. ServerIP = "10.177.130.30";
  328. ServerPort = "15021";
  329. ServerUser = "factory_test";
  330. ServerPassWd = "ttium";
  331. OfflineFlag = false;
  332. checkBox_OffLineFacMode.Checked = false;
  333. checkBox_OffLineCheckMode.Checked = false;
  334. break;
  335. }
  336. case 2: //威灵园区
  337. case 3: //越南工厂
  338. case 4: //公司外部
  339. {
  340. ServerIP = "8.134.109.44";
  341. ServerPort = "21";
  342. ServerUser = "ttium";
  343. ServerPassWd = "ttium123";
  344. OfflineFlag = false;
  345. checkBox_OffLineFacMode.Checked = false;
  346. checkBox_OffLineCheckMode.Checked = false;
  347. break;
  348. }
  349. case 5: //离线使用
  350. {
  351. //输入管理员密码
  352. Scan scan_form = new Scan();
  353. scan_form.label1.Text = "请输入管理员密码";
  354. scan_form.textBox_Scan.UseSystemPasswordChar = true;
  355. scan_form.ShowDialog();
  356. if (scan_form.textBox_Scan.Text == "ttium.123")
  357. {
  358. OfflineFlag = true;
  359. checkBox_OffLineFacMode.Checked = true;
  360. checkBox_OffLineCheckMode.Checked = true;
  361. }
  362. else
  363. {
  364. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  365. System.Environment.Exit(0);
  366. }
  367. break;
  368. }
  369. default: //无效
  370. {
  371. System.Environment.Exit(0);
  372. break;
  373. }
  374. }
  375. //保存配置文件
  376. if (ServerCfgForm1.checkBox_NoticeSw.Checked)
  377. {
  378. string str = ServerIP + "\r\n" + ServerPort + "\r\n" + ServerUser + "\r\n" + ServerPassWd + "\r\n" + (OfflineFlag == true).ToString();
  379. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.ServerCfgFileName, str);
  380. }
  381. }
  382. } while (false);
  383. //检查配置文件
  384. if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  385. {
  386. //打开文件
  387. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  388. string sLine = "";
  389. ArrayList array_CfgInfo = new ArrayList();
  390. array_CfgInfo.Clear();
  391. while (sLine != null)
  392. {
  393. sLine = objReader.ReadLine();
  394. array_CfgInfo.Add(sLine);
  395. }
  396. objReader.Close();
  397. //解析配置文件
  398. try
  399. {
  400. //Port Set
  401. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  402. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  403. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  404. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  405. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  406. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  407. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  408. //Option
  409. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  410. //Server Set
  411. toolStripTextBox_ServerPath.Text = array_CfgInfo[11].ToString().Split(':')[1];
  412. //MacInfo
  413. toolStripTextBox_MAC.Text = array_CfgInfo[14].ToString().Split(':')[1];
  414. toolStripTextBoxMACAddr.Text = array_CfgInfo[15].ToString().Split(':')[1];
  415. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  416. toolStripTextBox_MACPD.Text = array_CfgInfo[17].ToString().Split(':')[1];
  417. //Log Address
  418. textBox_LogAddrBegin.Text = array_CfgInfo[20].ToString().Split(':')[1];
  419. textBox_LogAddrEnd.Text = array_CfgInfo[21].ToString().Split(':')[1];
  420. //电机类型
  421. 中置电机ToolStripMenuItem.Checked = (array_CfgInfo[24].ToString().Split(':')[1] == "True");
  422. 轮毂电机ToolStripMenuItem.Checked = !中置电机ToolStripMenuItem.Checked;
  423. //检测阈值
  424. toolStripTextBox_ThVol.Text = array_CfgInfo[28].ToString().Split(':')[1];
  425. toolStripTextBox_ThCur.Text = array_CfgInfo[29].ToString().Split(':')[1];
  426. toolStripTextBox_ThSpeed.Text = array_CfgInfo[30].ToString().Split(':')[1];
  427. toolStripTextBox_ThTor.Text = array_CfgInfo[31].ToString().Split(':')[1];
  428. toolStripTextBox_ThCad.Text = array_CfgInfo[32].ToString().Split(':')[1];
  429. toolStripTextBox_ThBikeSpeed.Text = array_CfgInfo[33].ToString().Split(':')[1];
  430. toolStripTextBox_ThT_PCB.Text = array_CfgInfo[34].ToString().Split(':')[1];
  431. toolStripTextBox_ThT_MCU.Text = array_CfgInfo[35].ToString().Split(':')[1];
  432. toolStripTextBox_ThT_Motor.Text = array_CfgInfo[36].ToString().Split(':')[1];
  433. //MOS内阻校准系数
  434. toolStripTextBox_MosCalK.Text = array_CfgInfo[39].ToString().Split(':')[1];
  435. toolStripTextBox_MOS1.Text= array_CfgInfo[40].ToString().Split(':')[1];
  436. toolStripTextBox_MOS2.Text = array_CfgInfo[41].ToString().Split(':')[1];
  437. toolStripTextBox_MOS3.Text = array_CfgInfo[42].ToString().Split(':')[1];
  438. //通信协议类型
  439. cANToolStripMenuItem.Checked = (array_CfgInfo[45].ToString().Split(':')[1] == "True");
  440. uARTToolStripMenuItem.Checked = !cANToolStripMenuItem.Checked;
  441. //自动更新开关
  442. 打开ToolStripMenuItem.Checked = (array_CfgInfo[49].ToString().Split(':')[1] == "True");
  443. 关闭ToolStripMenuItem.Checked = !打开ToolStripMenuItem.Checked;
  444. //位置校准偏差
  445. textBox_AngleDiffTh.Text = array_CfgInfo[52].ToString().Split(':')[1];
  446. toolStripTextBox_AngleAvgMax.Text = textBox_AngleDiffTh.Text;
  447. textBox_AngleZeroTh.Text = array_CfgInfo[53].ToString().Split(':')[1];
  448. toolStripTextBox_AngleZeroMax.Text = textBox_AngleZeroTh.Text;
  449. }
  450. catch (System.Exception)
  451. {
  452. timer_500ms.Enabled = false;
  453. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  454. timer_500ms.Enabled = true;
  455. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  456. }
  457. }
  458. else //不存在配置文件,生成文件写入默认值
  459. {
  460. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  461. }
  462. //解析本地流水号记录
  463. do
  464. {
  465. //测试模式
  466. label_FacModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName1);
  467. //检验模式
  468. label_CheckModeSerial.Text = File.ReadAllText(localInfo.LocalPath + localInfo.SerialNumFileName2);
  469. } while (false);
  470. //获取本机信息,读取时间较长,优先从本地文件获取
  471. do
  472. {
  473. try
  474. {
  475. //本地文件为空,读取信息保存
  476. if (!File.Exists(localInfo.LocalPath + localInfo.PC_InfoFileName))
  477. {
  478. Local_HdInformation = "";
  479. Local_HdInformation += "计算机名称: " + System.Environment.UserName + "\r\n";
  480. Local_HdInformation += "IP地址: " + PC_Information.GetIpAddress() + "\r\n";
  481. Local_HdInformation += "系统ID: " + PC_Information.GetSystemID() + "\r\n";
  482. Local_HdInformation += "操作系统类型: " + PC_Information.GetSystemType() + "\r\n";
  483. Local_HdInformation += "主板型号: " + PC_Information.GetBoardType() + "\r\n";
  484. Local_HdInformation += "主板厂商: " + PC_Information.GetBoardManufacturer() + "\r\n";
  485. Local_HdInformation += "主板ID: " + PC_Information.GetBIOSSerialNumber() + "\r\n";
  486. Local_HdInformation += "CPU型号: " + PC_Information.GetCpuName() + "\r\n";
  487. Local_HdInformation += "CPU厂商: " + PC_Information.GetCpuManufacturer() + "\r\n";
  488. Local_HdInformation += "CPU ID: " + PC_Information.GetCPUSerialNumber() + "\r\n";
  489. Local_HdInformation += "内存容量: " + PC_Information.GetPhysicalMemory() + " GB" + "\r\n";
  490. Local_HdInformation += "MAC ID: " + PC_Information.GetNetCardMACAddress().Replace(":", "-") + "\r\n";
  491. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  492. }
  493. //从本地读取,计算机名和IP地址重新读
  494. else
  495. {
  496. Local_HdInformation = "";
  497. string[] fileInfo = File.ReadAllLines(localInfo.LocalPath + localInfo.PC_InfoFileName, Encoding.UTF8);
  498. fileInfo[0] = "计算机名称: " + System.Environment.UserName;
  499. fileInfo[1] = "IP地址: " + PC_Information.GetIpAddress();
  500. for (int i = 0; i < fileInfo.Length; i++)
  501. Local_HdInformation += fileInfo[i] + "\r\n";
  502. File.Delete(localInfo.LocalPath + localInfo.PC_InfoFileName);
  503. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.PC_InfoFileName, Local_HdInformation);
  504. }
  505. }
  506. catch(Exception)
  507. {
  508. }
  509. } while (false);
  510. //系统登录
  511. do
  512. {
  513. EnterForm1.ShowDialog();
  514. try
  515. {
  516. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  517. {
  518. if (EnterForm1.comboBox_User.Text.Contains("量产"))
  519. {
  520. //隐藏设置项
  521. 其它配置项ToolStripMenuItem.Visible = false;
  522. 写入存储ToolStripMenuItem.Visible = false;
  523. 服务器配置ToolStripMenuItem.Visible = false;
  524. 判断阈值ToolStripMenuItem.Visible = false;
  525. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  526. mOS内阻范围ToolStripMenuItem.Visible = false;
  527. 力矩传感器检验ToolStripMenuItem.Visible = false;
  528. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  529. //显示生产信息
  530. 生产信息ToolStripMenuItem.Visible = true;
  531. //显示电机类型,但不可编辑
  532. 电机类型ToolStripMenuItem.Visible = true;
  533. 中置电机ToolStripMenuItem.Enabled = false;
  534. 轮毂电机ToolStripMenuItem.Enabled = false;
  535. if (uARTToolStripMenuItem.Checked)
  536. UART协议ToolStripMenuItem.Visible = true;
  537. //隐藏研发调试界面
  538. tabPage_MotorParam.Parent = null;
  539. tabPage_BikeParam.Parent = null;
  540. tabPage_BikeParam2.Parent = null;
  541. tabPage_ControlParam.Parent = null;
  542. tabPage_SensorParam.Parent = null;
  543. tabPage_AssistParam.Parent = null;
  544. tabPage_UsrRideParam.Parent = null;
  545. tabPage_DebugParam.Parent = null;
  546. tabPage_RecordInfo.Parent = null;
  547. tabPage_OtherInfo.Parent = null;
  548. tabPage_OBC.Parent = null;
  549. tabPage_RAMorFLASH.Parent = null;
  550. tabPage_FactoryMode.Parent = null;
  551. tabPage_DebugInfo.Parent = null;
  552. tabPage_AngleCal.Parent = null;
  553. //显示运行信息
  554. tabPage_RunInfo.Parent = tabControl2;
  555. //根据电机类型修改生产信息和电机类型
  556. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  557. {
  558. 中置电机ToolStripMenuItem.Checked = true;
  559. 轮毂电机ToolStripMenuItem.Checked = false;
  560. toolStripTextBox_MACPD.Text = "MM_MC1";
  561. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  562. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  563. }
  564. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  565. {
  566. 中置电机ToolStripMenuItem.Checked = false;
  567. 轮毂电机ToolStripMenuItem.Checked = true;
  568. toolStripTextBox_MACPD.Text = "GF_250_1";
  569. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  570. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  571. }
  572. //显示对应生产测试界面
  573. if (EnterForm1.comboBox_User.Text.Contains("写入"))
  574. {
  575. tabPage_ProductMode_Write.Parent = tabControl1;
  576. tabPage_ProductMode_Write.Select();
  577. tabPage_ProductMode_Read.Parent = null;
  578. }
  579. else if (EnterForm1.comboBox_User.Text.Contains("检验"))
  580. {
  581. tabPage_ProductMode_Read.Parent = tabControl1;
  582. tabPage_ProductMode_Read.Select();
  583. tabPage_ProductMode_Write.Parent = null;
  584. }
  585. //应答指令不提示
  586. ACK_DisFlag = false;
  587. //退出登录
  588. break;
  589. }
  590. else if (EnterForm1.comboBox_User.Text == "工程参数配置")
  591. {
  592. //隐藏工作台内容,新建窗口完成配置
  593. groupBox1.Visible = false;
  594. groupBox3.Visible = false;
  595. tabControl2.Visible = false;
  596. //隐藏提示信息
  597. label_StarInfo.Visible = false;
  598. //打开参数配置框
  599. GenerateParamsForm.ShowDialog();
  600. System.Environment.Exit(0);
  601. //退出登录
  602. break;
  603. }
  604. else if (EnterForm1.comboBox_User.Text.Contains("样机"))
  605. {
  606. //隐藏量产界面
  607. tabPage_ProductMode_Read.Parent = null;
  608. tabPage_ProductMode_Write.Parent = null;
  609. //隐藏配置项
  610. 其它配置项ToolStripMenuItem.Visible = false;
  611. 服务器配置ToolStripMenuItem.Visible = false;
  612. 判断阈值ToolStripMenuItem.Visible = false;
  613. 力矩传感器检验ToolStripMenuItem.Visible = false;
  614. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  615. mOS内阻范围ToolStripMenuItem.Visible = false;
  616. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  617. //显示生产信息
  618. 生产信息ToolStripMenuItem.Visible = true;
  619. //显示电机类型,但不可编辑
  620. 电机类型ToolStripMenuItem.Visible = true;
  621. 中置电机ToolStripMenuItem.Enabled = true;
  622. 轮毂电机ToolStripMenuItem.Enabled = true;
  623. if (uARTToolStripMenuItem.Checked)
  624. UART协议ToolStripMenuItem.Visible = true;
  625. if (EnterForm1.comboBox_User.Text.Contains("中置"))
  626. {
  627. 中置电机ToolStripMenuItem.Checked = true;
  628. 轮毂电机ToolStripMenuItem.Checked = false;
  629. toolStripTextBox_MACPD.Text = "MM_MC1";
  630. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  631. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  632. }
  633. else if (EnterForm1.comboBox_User.Text.Contains("轮毂"))
  634. {
  635. 中置电机ToolStripMenuItem.Checked = false;
  636. 轮毂电机ToolStripMenuItem.Checked = true;
  637. toolStripTextBox_MACPD.Text = "GF_250_1";
  638. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  639. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  640. }
  641. //退出登录
  642. break;
  643. }
  644. else if (EnterForm1.comboBox_User.Text == "FCT治具测试")
  645. {
  646. //隐藏设置项
  647. 其它配置项ToolStripMenuItem.Visible = false;
  648. 写入存储ToolStripMenuItem.Visible = false;
  649. 服务器配置ToolStripMenuItem.Visible = false;
  650. 判断阈值ToolStripMenuItem.Visible = false;
  651. mOS内阻校准系数ToolStripMenuItem.Visible = false;
  652. mOS内阻范围ToolStripMenuItem.Visible = false;
  653. 力矩传感器检验ToolStripMenuItem.Visible = false;
  654. 位置校准偏差范围ToolStripMenuItem.Visible = false;
  655. //显示生产信息
  656. 生产信息ToolStripMenuItem.Visible = true;
  657. //显示电机类型,但不可编辑
  658. 电机类型ToolStripMenuItem.Visible = false;
  659. 中置电机ToolStripMenuItem.Enabled = false;
  660. 轮毂电机ToolStripMenuItem.Enabled = false;
  661. if (uARTToolStripMenuItem.Checked)
  662. UART协议ToolStripMenuItem.Visible = true;
  663. //隐藏研发调试界面
  664. tabPage_MotorParam.Parent = null;
  665. tabPage_BikeParam.Parent = null;
  666. tabPage_BikeParam2.Parent = null;
  667. tabPage_ControlParam.Parent = null;
  668. tabPage_SensorParam.Parent = null;
  669. tabPage_AssistParam.Parent = null;
  670. tabPage_UsrRideParam.Parent = null;
  671. tabPage_DebugParam.Parent = null;
  672. tabPage_RecordInfo.Parent = null;
  673. tabPage_OtherInfo.Parent = null;
  674. tabPage_OBC.Parent = null;
  675. tabPage_RAMorFLASH.Parent = null;
  676. tabPage_FactoryMode.Parent = null;
  677. tabPage_DebugInfo.Parent = null;
  678. tabPage_AngleCal.Parent = null;
  679. //显示运行信息
  680. tabPage_RunInfo.Parent = tabControl2;
  681. //目前仅轮毂使用
  682. 中置电机ToolStripMenuItem.Checked = false;
  683. 轮毂电机ToolStripMenuItem.Checked = true;
  684. toolStripTextBox_MACPD.Text = "GF_250_1";
  685. toolStripTextBox_ServerPath.Text = "HUB_Control_FCT";
  686. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  687. //显示量产测试界面
  688. tabPage_ProductMode_Write.Parent = tabControl1;
  689. tabPage_ProductMode_Write.Select();
  690. tabPage_ProductMode_Read.Parent = null;
  691. checkBox_OffLineFacMode.Checked = false;
  692. checkBox_OffLineFacMode.Enabled = true;
  693. checkBox_OffLineCheckMode.Checked = false;
  694. checkBox_OffLineCheckMode.Enabled = true;
  695. //应答指令不提示
  696. ACK_DisFlag = false;
  697. //退出登录
  698. break;
  699. }
  700. else if (EnterForm1.comboBox_User.Text == "研发调试")
  701. {
  702. //隐藏量产界面
  703. tabPage_ProductMode_Read.Parent = null;
  704. tabPage_ProductMode_Write.Parent = null;
  705. 服务器配置ToolStripMenuItem.Visible = false;
  706. if (uARTToolStripMenuItem.Checked)
  707. UART协议ToolStripMenuItem.Visible = true;
  708. //退出登录
  709. break;
  710. }
  711. else if (EnterForm1.comboBox_User.Text == "管理员")
  712. {
  713. //不隐藏任何界面
  714. //...
  715. //退出登录
  716. break;
  717. }
  718. else
  719. {
  720. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  721. //重新登录
  722. continue;
  723. }
  724. }
  725. else
  726. {
  727. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  728. //重新登录
  729. continue;
  730. }
  731. }
  732. catch (Exception)
  733. {
  734. System.Environment.Exit(0);
  735. }
  736. } while (true);
  737. //配置网络FTP服务器
  738. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPassWd, "admin", "ttium_admin");
  739. //创建线程,定时检测网络连接状态
  740. Thread th = new Thread(NetworkCheck);
  741. th.IsBackground = true;
  742. th.Start();
  743. //允许跨线程访问
  744. Control.CheckForIllegalCrossThreadCalls = false;
  745. }
  746. /// <summary>
  747. /// 检查网络状态线程
  748. /// </summary>
  749. private void NetworkCheck()
  750. {
  751. //允许离线使用,直接退出
  752. if (OfflineFlag == true) //允许离线使用
  753. {
  754. timer_500ms.Enabled = false;
  755. MessageBoxTimeOut.Show("离线使用,不检测网络状态!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  756. timer_500ms.Enabled = true;
  757. return;
  758. }
  759. //不允许离线使用,实时监测网络状态
  760. else
  761. {
  762. //初始化第一次连接FTP服务器
  763. bool Result = myFtp.CheckFtp();
  764. if (Result == true)//服务器连接成功
  765. {
  766. myFtp.IsNetConnected = true;
  767. //上传登录日志
  768. do
  769. {
  770. //日志文件名
  771. string date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff");
  772. string fileName = date;
  773. //日志内容
  774. string fileInfo = Local_HdInformation;
  775. //保存本地
  776. if (!Directory.Exists(localInfo.LocalLogPath))
  777. Directory.CreateDirectory(localInfo.LocalLogPath);
  778. System.IO.File.WriteAllText(localInfo.LocalLogPath + fileName, fileInfo);
  779. //上传服务器
  780. myFtp.UploadFile(localInfo.LocalLogPath + fileName, "/Tools/Welling_Motor_Debug_Tool/log");
  781. } while (false);
  782. }
  783. else//服务器连接失败
  784. {
  785. myFtp.IsNetConnected = false;
  786. if (EnterForm1.comboBox_User.Text != "管理员")
  787. {
  788. timer_500ms.Enabled = false;
  789. MessageBoxTimeOut.Show("网络断开,将自动关闭!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  790. timer_500ms.Enabled = true;
  791. this.Close();
  792. }
  793. }
  794. //创建定时器,定时30s检查网络
  795. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  796. timer_CheckNet.Enabled = true;
  797. timer_CheckNet.Interval = 30000;
  798. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  799. timer_CheckNet.Start();
  800. while (true)
  801. {
  802. Thread.Sleep(1);
  803. if (myFtp.IsNetConnected == false)
  804. {
  805. label_Server_ComStatus.Text = "网络已断开";
  806. label_ServerStatus.BackColor = Color.Red;
  807. }
  808. else
  809. {
  810. label_Server_ComStatus.Text = "网络已连接";
  811. label_ServerStatus.BackColor = Color.Green;
  812. }
  813. }
  814. }
  815. }
  816. /// <summary>
  817. /// 线程中定时任务,检查网络状态
  818. /// </summary>
  819. /// <param name="sender"></param>
  820. /// <param name="e"></param>
  821. private void timer_CheckNet_Tick(object sender, EventArgs e)
  822. {
  823. //连接FTP服务器
  824. bool Result = myFtp.CheckFtp();
  825. if (Result == true)//服务器连接成功
  826. {
  827. myFtp.IsNetConnected = true;
  828. //允许使用
  829. groupBox1.Enabled = true;
  830. groupBox3.Enabled = true;
  831. tabControl2.Enabled = true;
  832. }
  833. else//服务器连接失败
  834. {
  835. myFtp.IsNetConnected = false;
  836. if (EnterForm1.comboBox_User.Text != "管理员")
  837. {
  838. timer_500ms.Enabled = false;
  839. MessageBoxTimeOut.Show("网络断开, 请检查网络!", "提示", 2000, MessageBoxButtons.OK, MessageBoxIcon.Warning); //提示框自动3s关闭
  840. timer_500ms.Enabled = true;
  841. //禁止使用
  842. groupBox1.Enabled = false;
  843. groupBox3.Enabled = false;
  844. tabControl2.Enabled = false;
  845. }
  846. }
  847. }
  848. #region 非独占性延时函数
  849. public static void Delay_ms(int milliSecond)
  850. {
  851. int start = Environment.TickCount;
  852. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  853. {
  854. Application.DoEvents();
  855. }
  856. }
  857. #endregion
  858. private void MainForm_Load(object sender, System.EventArgs e)
  859. {
  860. //页面初始化
  861. label_BuildTime.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  862. label_Computername.Text = System.Environment.UserName;
  863. label_UserName.Text = EnterForm1.comboBox_User.Text;
  864. //位置校准表格初始化
  865. for (int i = 0; i < 7; i++)
  866. {
  867. int index = dataGridView_AngleCal.Rows.Add();
  868. dataGridView_AngleCal.Rows[index].Cells[0].Value = i + 1;
  869. }
  870. dataGridView_AngleCal.AllowUserToAddRows = false;
  871. this.Text += Version;
  872. //检查版本,自动更新
  873. do
  874. {
  875. if ((打开ToolStripMenuItem.Checked == false) || OfflineFlag == true)//关闭自动更新或离线时
  876. {
  877. break;
  878. }
  879. //检查网络状态
  880. if (myFtp.CheckFtp() == false)
  881. {
  882. MessageBoxTimeOut.Show("网络断开,自动更新失败!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  883. break;
  884. }
  885. else
  886. {
  887. //检查本地文件删除
  888. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  889. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  890. //读取最新版本号
  891. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  892. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  893. string sLine = "";
  894. ArrayList arrText = new ArrayList();//创建一个动态数组
  895. while (sLine != null)
  896. {
  897. sLine = objReader.ReadLine();
  898. arrText.Add(sLine);
  899. }
  900. objReader.Close();
  901. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  902. //检查是否有最新版本
  903. string[] VerOld = mainForm.Version.Trim().Split('.');
  904. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  905. int VerOld_int = Convert.ToInt32(VerOld[0]) * 10000 + Convert.ToInt32(VerOld[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerOld[2].PadLeft(2, '0'));
  906. int VerNew_int = Convert.ToInt32(VerNew[0]) * 10000 + Convert.ToInt32(VerNew[1].PadLeft(2, '0')) * 100 + Convert.ToInt32(VerNew[2].PadLeft(2, '0'));
  907. if (VerNew_int <= VerOld_int)
  908. {
  909. //版本已是最新,跳出
  910. break;
  911. }
  912. //确认下载最新版本
  913. if (MessageBox.Show("是否更新新版本?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  914. {
  915. string SavePath = Directory.GetCurrentDirectory();
  916. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  917. foreach (string file in FileList)
  918. {
  919. if (file.Contains(".exe"))
  920. {
  921. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  922. MessageBox.Show("新版本下载完成,请手动删除旧版本!\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  923. System.Environment.Exit(0);
  924. }
  925. }
  926. }
  927. }
  928. } while (false);
  929. //下拉控件初始值设定
  930. comboBox_WorkMode.SelectedIndex = 0;
  931. comboBox_GearSt.SelectedIndex = 0;
  932. comboBox_LightSwitch.SelectedIndex = 1;
  933. comboBox_OBC_SetGearST.SelectedIndex = 0;
  934. comboBox_OBC_LightSw.SelectedIndex = 1;
  935. comboBox_AssistTorque.SelectedIndex = 0;
  936. comboBox_AssistCadence.SelectedIndex = 0;
  937. //combobox事件定义
  938. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  939. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  940. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  941. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  942. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  943. //端口自动连接
  944. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  945. {
  946. try
  947. {
  948. PortConnect();
  949. }
  950. catch (System.Exception)
  951. {
  952. timer_500ms.Enabled = false;
  953. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  954. timer_500ms.Enabled = true;
  955. }
  956. }
  957. //不识别联动装置盒自动打开界面
  958. #if true
  959. groupBox1.Visible = true;
  960. groupBox3.Visible = true;
  961. tabControl2.Visible = true;
  962. label_StarInfo.Visible = false;
  963. #endif
  964. //创建线程,定时解析数据
  965. Thread th = new Thread(Task_SerialProcess);
  966. th.IsBackground = true;
  967. th.Start();
  968. }
  969. #region 结构体与字节流相互转换
  970. public static class MyConverter
  971. {
  972. /// <summary>
  973. /// 由结构体转换为byte数组
  974. /// </summary>
  975. public static byte[] StructureToByte<T>(T structure)
  976. {
  977. int size = Marshal.SizeOf(typeof(T));
  978. byte[] buffer = new byte[size];
  979. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  980. try
  981. {
  982. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  983. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  984. }
  985. finally
  986. {
  987. Marshal.FreeHGlobal(bufferIntPtr);
  988. }
  989. return buffer;
  990. }
  991. /// <summary>
  992. /// 由byte数组转换为结构体
  993. /// </summary>
  994. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  995. {
  996. object structure = null;
  997. int size = Marshal.SizeOf(typeof(T));
  998. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  999. try
  1000. {
  1001. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  1002. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  1003. }
  1004. finally
  1005. {
  1006. Marshal.FreeHGlobal(allocIntPtr);
  1007. }
  1008. return (T)structure;
  1009. }
  1010. }
  1011. #endregion
  1012. #region 故障日志解析显示
  1013. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  1014. {
  1015. string SaveData = "";
  1016. //Log1
  1017. if (Log1.Error_Index != 0xFFFF)
  1018. {
  1019. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  1020. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  1021. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  1022. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  1023. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1024. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  1025. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1026. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  1027. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  1028. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  1029. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  1030. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  1031. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  1032. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1033. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1034. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1035. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  1036. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  1037. {
  1038. SaveData += "续航:" + "---km" + ", ";
  1039. }
  1040. else
  1041. {
  1042. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  1043. }
  1044. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  1045. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1046. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  1047. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  1048. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  1049. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1050. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  1051. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  1052. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  1053. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  1054. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  1055. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1056. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1057. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1058. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1059. SaveData += "\r\n\r\n";
  1060. richTextBox_Record.AppendText(SaveData);
  1061. SaveData = "";
  1062. }
  1063. //Log2
  1064. if (Log2.Error_Index != 0xFFFF)
  1065. {
  1066. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  1067. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  1068. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  1069. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  1070. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  1071. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  1072. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  1073. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  1074. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  1075. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  1076. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  1077. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  1078. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  1079. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  1080. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  1081. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  1082. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  1083. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  1084. {
  1085. SaveData += "续航:" + "---km" + ", ";
  1086. }
  1087. else
  1088. {
  1089. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  1090. }
  1091. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  1092. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  1093. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  1094. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  1095. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  1096. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  1097. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  1098. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  1099. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  1100. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  1101. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  1102. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  1103. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  1104. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  1105. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  1106. SaveData += "\r\n\r\n";
  1107. richTextBox_Record.AppendText(SaveData);
  1108. SaveData = "";
  1109. }
  1110. }
  1111. #endregion
  1112. #region 串口数据解析线程
  1113. /// <summary>
  1114. /// 串口数据解析线程
  1115. /// </summary>
  1116. private void Task_SerialProcess()
  1117. {
  1118. //创建定时器,定时读取串口数据
  1119. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  1120. timer_ReadSerial.Enabled = true;
  1121. timer_ReadSerial.Interval = 20;
  1122. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  1123. timer_ReadSerial.Start();
  1124. while (true)
  1125. {
  1126. Thread.Sleep(1);
  1127. };
  1128. }
  1129. /// <summary>
  1130. /// 串口解析定时器
  1131. /// </summary>
  1132. /// <param name="sender"></param>
  1133. /// <param name="e"></param>
  1134. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  1135. {
  1136. //串口解析
  1137. Serial_process(mySerialProcess.buffer);
  1138. }
  1139. #endregion
  1140. #region 数据解析
  1141. public void Serial_process(List<byte> buffer)
  1142. {
  1143. byte DataNum = 0; //记录每条命令数据段的长度
  1144. ushort PackageID, Cmd;
  1145. byte[] Data = new byte[1024];
  1146. try
  1147. {
  1148. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1149. {
  1150. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1151. {
  1152. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1153. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  1154. {
  1155. int CmdLen = buffer[5];
  1156. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1157. while (CmdLen > 0) //读取命令段
  1158. {
  1159. Cmd = (ushort)(buffer[6] * 256 + buffer[7]);
  1160. DataNum = (byte)(buffer[7]);//命令字的第二个字节的表示数据位的长度
  1161. if (DataNum <= (CmdLen - 2))
  1162. {
  1163. for (int i = 0; i < DataNum; i++)
  1164. {
  1165. Data[i] = buffer[i + 8];
  1166. }
  1167. // 串口接收的数据 显示在子窗口
  1168. if (this.DebugWindowIsOpen && this.DebugDataDisplayEnable)
  1169. {
  1170. string strTemp = String.Empty;
  1171. strTemp += System.DateTimeOffset.Now.ToString("HH:mm:ss.fff") + " <-- ";
  1172. for (int i = 0; i < CmdLen + 11; i++)
  1173. {
  1174. strTemp += (buffer[i].ToString("X2") + " ");
  1175. }
  1176. strTemp += "\n";
  1177. DebugForm.debug1.richTextBox_DebugRev.Text += strTemp;
  1178. }
  1179. buffer.RemoveRange(0, CmdLen + 11);
  1180. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  1181. DataRevToString(Cmd, Data);//指令数据转为字符串
  1182. }
  1183. }
  1184. }
  1185. else
  1186. {
  1187. buffer.RemoveAt(0);//ID不对
  1188. }
  1189. }
  1190. else
  1191. {
  1192. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1193. }
  1194. }
  1195. }
  1196. catch (Exception)
  1197. {
  1198. }
  1199. }
  1200. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  1201. {
  1202. int DataTemp;
  1203. ushort uData16;
  1204. unchecked
  1205. {
  1206. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  1207. }
  1208. #region 解析发送给CDL的指令
  1209. if (ID == 0x7FF)
  1210. {
  1211. switch (CmdTemp)
  1212. {
  1213. case 0x1100://
  1214. {
  1215. unchecked
  1216. {
  1217. this.Invoke((EventHandler)(delegate
  1218. {
  1219. //CDL连接成功
  1220. mySerialProcess.CDL_Online_Flag = true;
  1221. MessageBoxTimeOut.Show("连接成功!", "提示", 500);
  1222. groupBox1.Visible = true;
  1223. groupBox3.Visible = true;
  1224. tabControl2.Visible = true;
  1225. label_StarInfo.Visible = false;
  1226. }));
  1227. }
  1228. break;
  1229. }
  1230. default: break;
  1231. }
  1232. }
  1233. #endregion
  1234. #region 解析电机的命令
  1235. else if ((ID == 0x715) || (ID == 0x710))
  1236. {
  1237. switch (CmdTemp)
  1238. {
  1239. case 0x1020://电机运行信息
  1240. {
  1241. unchecked
  1242. {
  1243. this.Invoke((EventHandler)(delegate
  1244. {
  1245. MC_RunInfo_Refresh = true;
  1246. //车速
  1247. DataTemp = (int)(Data[1] * 256 + Data[0]);
  1248. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1249. //输出转速
  1250. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  1251. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1252. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  1253. Class_MotorSpeed.Data = DataTemp;
  1254. //电功率
  1255. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  1256. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1257. //母线电压
  1258. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  1259. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  1260. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  1261. //母线电流
  1262. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1263. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1264. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  1265. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1266. Class_CurrentData.Data = DataTemp;
  1267. //踏频
  1268. DataTemp = (ushort)(Data[10]);
  1269. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1270. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  1271. Class_CadenceData.Data = DataTemp;
  1272. //踩踏力矩
  1273. DataTemp = (ushort)(Data[11]);
  1274. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1275. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1276. Class_TorqueData.Data = DataTemp;
  1277. //踩踏方向
  1278. DataTemp = (ushort)(Data[12]);
  1279. if (DataTemp == 0)
  1280. {
  1281. textBox_RunInfo_Dir.Text = "正向";
  1282. }
  1283. else if (DataTemp == 1)
  1284. {
  1285. textBox_RunInfo_Dir.Text = "反向";
  1286. }
  1287. else if (DataTemp == 2)
  1288. {
  1289. textBox_RunInfo_Dir.Text = "停止";
  1290. }
  1291. //助力档位
  1292. DataTemp = (ushort)(Data[13]);
  1293. if (DataTemp == 0x33)
  1294. {
  1295. textBox_RunInfo_GearSt.Text = "SMART";
  1296. //comboBox_GearSt.SelectedIndex = 5;
  1297. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  1298. }
  1299. else if (DataTemp == 0x22)
  1300. {
  1301. textBox_RunInfo_GearSt.Text = "WALK";
  1302. //comboBox_GearSt.SelectedIndex = 6;
  1303. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  1304. }
  1305. else
  1306. {
  1307. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  1308. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  1309. //comboBox_GearSt.SelectedIndex = DataTemp;
  1310. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  1311. }
  1312. //大灯状态
  1313. DataTemp = (ushort)(Data[14]);
  1314. if (DataTemp == 0xF0)
  1315. {
  1316. textBox_RunInfo_LightSwitch.Text = "OFF";
  1317. //comboBox_LightSwitch.SelectedIndex = 1;
  1318. //comboBox_OBC_LightSw.SelectedIndex = 1;
  1319. }
  1320. else if (DataTemp == 0xF1)
  1321. {
  1322. textBox_RunInfo_LightSwitch.Text = "ON";
  1323. //comboBox_LightSwitch.SelectedIndex = 0;
  1324. //comboBox_OBC_LightSw.SelectedIndex = 0;
  1325. }
  1326. //剩余电量
  1327. DataTemp = (ushort)(Data[15]);
  1328. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1329. //剩余续航里程
  1330. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  1331. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1332. {
  1333. textBox_RunInfo_Range.Text = "---";
  1334. }
  1335. else
  1336. {
  1337. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1338. }
  1339. //预留(显示力矩Reg),空2bytes
  1340. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  1341. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  1342. //平均功耗
  1343. DataTemp = (ushort)(Data[20]);
  1344. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1345. //PCB温度
  1346. DataTemp = (ushort)(Data[21]);
  1347. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1348. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  1349. Class_MotorTemp.Data = DataTemp - 40;
  1350. //绕组温度
  1351. DataTemp = (ushort)(Data[22]);
  1352. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1353. //MCU温度
  1354. DataTemp = (ushort)(Data[23]);
  1355. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  1356. //单次里程
  1357. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  1358. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1359. //单次时间
  1360. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  1361. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  1362. //数据保存
  1363. RunInfoAutoSave();
  1364. }));
  1365. }
  1366. break;
  1367. }
  1368. case 0x1104://故障码
  1369. {
  1370. unchecked
  1371. {
  1372. this.Invoke((EventHandler)(delegate
  1373. {
  1374. MC_ErrorCode_Refresh = true;
  1375. textBox_ErrorCode.Text =
  1376. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  1377. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  1378. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  1379. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  1380. "H";
  1381. }));
  1382. }
  1383. break;
  1384. }
  1385. case 0xA903://反馈指令
  1386. {
  1387. unchecked
  1388. {
  1389. this.Invoke((EventHandler)(delegate
  1390. {
  1391. if (ACK_DisFlag == true)
  1392. {
  1393. timer_500ms.Enabled = false;
  1394. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1395. timer_500ms.Enabled = true;
  1396. //关机反馈
  1397. PowerOffAckStatus = true;
  1398. }
  1399. //应答标志置位
  1400. WriteACK = true;
  1401. WriteCnt++;
  1402. }));
  1403. }
  1404. break;
  1405. }
  1406. case 0xB226://马达参数
  1407. {
  1408. unchecked
  1409. {
  1410. this.Invoke((EventHandler)(delegate
  1411. {
  1412. richTextBox_MotorParam.Clear();
  1413. for (int i = 0; i < myParams.MotorParam.Count; i++)
  1414. {
  1415. if (i == 6)
  1416. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1417. else
  1418. richTextBox_MotorParam.AppendText(myParams.MotorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1419. }
  1420. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  1421. }));
  1422. }
  1423. break;
  1424. }
  1425. case 0xB31A://整车信息
  1426. {
  1427. unchecked
  1428. {
  1429. this.Invoke((EventHandler)(delegate
  1430. {
  1431. richTextBox_BikeParam.Clear();
  1432. for (int i = 0; i < myParams.BikeParam.Count; i++)
  1433. {
  1434. if (i == 9)
  1435. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1436. else
  1437. richTextBox_BikeParam.AppendText(myParams.BikeParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1438. //更新前后灯参数
  1439. if (i == 8)
  1440. {
  1441. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  1442. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  1443. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  1444. }
  1445. //更新开关机参数
  1446. else if (i == 11)
  1447. {
  1448. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  1449. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  1450. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  1451. }
  1452. }
  1453. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  1454. }));
  1455. }
  1456. break;
  1457. }
  1458. case 0xB420://控制器参数
  1459. {
  1460. unchecked
  1461. {
  1462. this.Invoke((EventHandler)(delegate
  1463. {
  1464. richTextBox_ControlParam.Clear();
  1465. for (int i = 0; i < myParams.ControlParam.Count; i++)
  1466. {
  1467. richTextBox_ControlParam.AppendText(myParams.ControlParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1468. //转把定速巡航
  1469. if (i == 13)
  1470. {
  1471. comboBox_Bike_CCS.SelectedIndex = ((Data[2 * i]) == 0xAA) ? 1 : 2;
  1472. }
  1473. }
  1474. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  1475. }));
  1476. }
  1477. break;
  1478. }
  1479. case 0xB528://传感器参数
  1480. {
  1481. unchecked
  1482. {
  1483. this.Invoke((EventHandler)(delegate
  1484. {
  1485. richTextBox_SensorParam.Clear();
  1486. for (int i = 0; i < myParams.SensorParam.Count; i++)
  1487. {
  1488. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1489. }
  1490. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  1491. //更新生产模式页面传感器零点和标定值
  1492. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  1493. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  1494. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  1495. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  1496. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  1497. }));
  1498. }
  1499. break;
  1500. }
  1501. case 0xB64C://助力参数
  1502. {
  1503. unchecked
  1504. {
  1505. this.Invoke((EventHandler)(delegate
  1506. {
  1507. richTextBox_AssistParam.Clear();
  1508. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  1509. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  1510. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  1511. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  1512. for (int i = 0; i < myParams.AssistParam.Count; i++)
  1513. {
  1514. if (i < index_1) //数据占用2bytes
  1515. {
  1516. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1517. }
  1518. else if (i <= index_2) //数据占用4bytes
  1519. {
  1520. 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])) + ", ");
  1521. }
  1522. else if (i < index_3) //数据占用2bytes,无符号
  1523. {
  1524. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1525. }
  1526. else if (i <= index_4) //数据占用2bytes,有符号
  1527. {
  1528. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1529. }
  1530. else //数据占用2bytes,无符号
  1531. {
  1532. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  1533. }
  1534. }
  1535. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  1536. }));
  1537. }
  1538. break;
  1539. }
  1540. case 0xB74C://历史记录
  1541. {
  1542. unchecked
  1543. {
  1544. this.Invoke((EventHandler)(delegate
  1545. {
  1546. richTextBox_Record.Clear();
  1547. for (int i = 0; i < myParams.Record.Count; i++)
  1548. {
  1549. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  1550. }
  1551. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  1552. }));
  1553. }
  1554. break;
  1555. }
  1556. case 0xB83A://调试参数
  1557. {
  1558. unchecked
  1559. {
  1560. this.Invoke((EventHandler)(delegate
  1561. {
  1562. richTextBox_DebugParam.Clear();
  1563. for (int i = 0; i < myParams.DebugParam.Count; i++)
  1564. {
  1565. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  1566. }
  1567. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  1568. }));
  1569. }
  1570. break;
  1571. }
  1572. case 0xB904://存储标志
  1573. {
  1574. unchecked
  1575. {
  1576. this.Invoke((EventHandler)(delegate
  1577. {
  1578. ushort Flag = 0;
  1579. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  1580. if (Flag == 0)
  1581. {
  1582. radioButton_EE_SaveNo.Checked = true;
  1583. radioButton_EE_SaveYes.Checked = false;
  1584. }
  1585. else
  1586. {
  1587. radioButton_EE_SaveNo.Checked = false;
  1588. radioButton_EE_SaveYes.Checked = true;
  1589. }
  1590. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  1591. if (Flag == 0)
  1592. {
  1593. radioButton_SIP_SaveNo.Checked = true;
  1594. radioButton_SIP_SaveYes.Checked = false;
  1595. }
  1596. else
  1597. {
  1598. radioButton_SIP_SaveNo.Checked = false;
  1599. radioButton_SIP_SaveYes.Checked = true;
  1600. }
  1601. }));
  1602. }
  1603. break;
  1604. }
  1605. case 0x1240://电机版本信息
  1606. {
  1607. unchecked
  1608. {
  1609. this.Invoke((EventHandler)(delegate
  1610. {
  1611. //电机型号
  1612. textBox_Model.Text = "";
  1613. textBox_OBC_ReadModel.Text = "";
  1614. textBox_FacModeName.Text = "";
  1615. for (ushort i = 0; i < 16; i++)
  1616. {
  1617. if (Data[i] == 0x2E)
  1618. {
  1619. break;
  1620. }
  1621. textBox_Model.Text += ((char)Data[i]).ToString();
  1622. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  1623. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  1624. }
  1625. Class_Motor_Ver.Mode = textBox_Model.Text;
  1626. //电机SN
  1627. textBox_SN.Text = "";
  1628. textBox_OBC_ReadSN.Text = "";
  1629. textBox_FacModeNum.Text = "";
  1630. for (ushort i = 0; i < 16; i++)
  1631. {
  1632. if (Data[16 + i] == 0x2E)
  1633. {
  1634. break;
  1635. }
  1636. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  1637. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  1638. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  1639. }
  1640. Class_Motor_Ver.SN = textBox_SN.Text;
  1641. //电机HW
  1642. textBox_HW.Text = "";
  1643. textBox_OBC_ReadHW.Text = "";
  1644. textBox_FacModeHW.Text = "";
  1645. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  1646. {
  1647. if (Data[32 + i] == 0x2E)
  1648. {
  1649. break;
  1650. }
  1651. else if (Data[32 + i] == 'r')
  1652. {
  1653. Data[32 + i] = (byte)'.';
  1654. break;
  1655. }
  1656. string strTemp = "";
  1657. strTemp = ((char)Data[32 + i]).ToString();
  1658. textBox_HW.Text += strTemp;
  1659. textBox_OBC_ReadHW.Text += strTemp;
  1660. textBox_FacModeHW.Text += strTemp;
  1661. }
  1662. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  1663. {
  1664. if (Data[40 + i] == 0x2E)
  1665. {
  1666. break;
  1667. }
  1668. else if (Data[40 + i] == 'r')
  1669. {
  1670. Data[40 + i] = (byte)'.';
  1671. break;
  1672. }
  1673. string strTemp = "";
  1674. strTemp = ((char)Data[40 + i]).ToString();
  1675. textBox_HW.Text += strTemp;
  1676. textBox_OBC_ReadHW.Text += strTemp;
  1677. textBox_FacModeHW.Text += strTemp;
  1678. }
  1679. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1680. {
  1681. string strTemp = "";
  1682. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1683. textBox_HW.Text += strTemp;
  1684. textBox_OBC_ReadHW.Text += strTemp;
  1685. textBox_FacModeHW.Text += strTemp;
  1686. }
  1687. Class_Motor_Ver.HW = textBox_HW.Text;
  1688. //电机FW
  1689. textBox_FW.Text = "";
  1690. textBox_OBC_ReadFW.Text = "";
  1691. textBox_FacModeFW.Text = "";
  1692. for (ushort i = 0; i < 16; i++)
  1693. {
  1694. if ((Data[48 + i] == 0x2E) || (Data[48 + i] == 0x00) || (Data[48 + i] == (char)' '))
  1695. {
  1696. break;
  1697. }
  1698. if (Data[48 + i] == 'r')
  1699. {
  1700. Data[48 + i] = (byte)'.';
  1701. }
  1702. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1703. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1704. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1705. }
  1706. Class_Motor_Ver.FW = textBox_FW.Text;
  1707. }));
  1708. }
  1709. break;
  1710. }
  1711. case 0xA610://自定义1
  1712. {
  1713. unchecked
  1714. {
  1715. this.Invoke((EventHandler)(delegate
  1716. {
  1717. textBox_User1.Text = "";
  1718. for (ushort i = 0; i < 16; i++)
  1719. {
  1720. if (Data[i] == 0x2E)
  1721. {
  1722. break;
  1723. }
  1724. textBox_User1.Text += ((char)Data[i]).ToString();
  1725. }
  1726. }));
  1727. }
  1728. break;
  1729. }
  1730. case 0xA710://自定义2
  1731. {
  1732. unchecked
  1733. {
  1734. this.Invoke((EventHandler)(delegate
  1735. {
  1736. textBox_User2.Text = "";
  1737. for (ushort i = 0; i < 16; i++)
  1738. {
  1739. if (Data[i] == 0x2E)
  1740. {
  1741. break;
  1742. }
  1743. textBox_User2.Text += ((char)Data[i]).ToString();
  1744. }
  1745. }));
  1746. }
  1747. break;
  1748. }
  1749. case 0xA810://自定义1
  1750. {
  1751. unchecked
  1752. {
  1753. this.Invoke((EventHandler)(delegate
  1754. {
  1755. textBox_User3.Text = "";
  1756. for (ushort i = 0; i < 16; i++)
  1757. {
  1758. if (Data[i] == 0x2E)
  1759. {
  1760. break;
  1761. }
  1762. textBox_User3.Text += ((char)Data[i]).ToString();
  1763. }
  1764. }));
  1765. }
  1766. break;
  1767. }
  1768. case 0xA520://生产信息
  1769. {
  1770. unchecked
  1771. {
  1772. this.Invoke((EventHandler)(delegate
  1773. {
  1774. //生产商
  1775. textBox_MAC.Text = "";
  1776. for (ushort i = 0; i < 8; i++)
  1777. {
  1778. if (Data[i] == 0x2E)
  1779. {
  1780. break;
  1781. }
  1782. textBox_MAC.Text += ((char)Data[i]).ToString();
  1783. }
  1784. //生产地
  1785. textBox_MACAdd.Text = "";
  1786. for (ushort i = 0; i < 8; i++)
  1787. {
  1788. if (Data[8 + i] == 0x2E)
  1789. {
  1790. break;
  1791. }
  1792. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1793. }
  1794. //生产日期
  1795. textBox_MACDate.Text = "";
  1796. for (ushort i = 0; i < 8; i++)
  1797. {
  1798. if (Data[16 + i] == 0x2E)
  1799. {
  1800. break;
  1801. }
  1802. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1803. }
  1804. //品牌信息
  1805. textBox_PP.Text = "";
  1806. for (ushort i = 0; i < 8; i++)
  1807. {
  1808. if (Data[24 + i] == 0x2E)
  1809. {
  1810. break;
  1811. }
  1812. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1813. }
  1814. }));
  1815. }
  1816. break;
  1817. }
  1818. case 0xA408://密钥
  1819. {
  1820. unchecked
  1821. {
  1822. this.Invoke((EventHandler)(delegate
  1823. {
  1824. textBox_Key.Text = "";
  1825. for (ushort i = 0; i < 8; i++)
  1826. {
  1827. textBox_Key.Text += ((char)Data[i]).ToString();
  1828. }
  1829. }));
  1830. }
  1831. break;
  1832. }
  1833. case 0xAB09://存储器数据
  1834. case 0xAB0A:
  1835. case 0xAB0B:
  1836. case 0xAB0C:
  1837. {
  1838. unchecked
  1839. {
  1840. this.Invoke((EventHandler)(delegate
  1841. {
  1842. long ByteNum = 0;
  1843. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1844. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1845. {
  1846. for (int i = 0; i < ByteNum; i++)
  1847. {
  1848. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1849. }
  1850. }
  1851. else //根据设置自动转换10进制显示
  1852. {
  1853. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1854. {
  1855. switch (ByteNum)
  1856. {
  1857. case 1:
  1858. {
  1859. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1860. break;
  1861. }
  1862. case 2:
  1863. {
  1864. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1865. break;
  1866. }
  1867. case 3:
  1868. {
  1869. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1870. break;
  1871. }
  1872. case 4:
  1873. {
  1874. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1875. break;
  1876. }
  1877. default:
  1878. {
  1879. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1880. break;
  1881. }
  1882. }
  1883. }
  1884. else //16进制显示
  1885. {
  1886. switch (ByteNum)
  1887. {
  1888. case 1:
  1889. {
  1890. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1891. break;
  1892. }
  1893. case 2:
  1894. {
  1895. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1896. break;
  1897. }
  1898. case 3:
  1899. {
  1900. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1901. break;
  1902. }
  1903. case 4:
  1904. {
  1905. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1906. break;
  1907. }
  1908. default:
  1909. {
  1910. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1911. break;
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }));
  1917. }
  1918. break;
  1919. }
  1920. case 0xAB88://故障日志
  1921. {
  1922. unchecked
  1923. {
  1924. this.Invoke((EventHandler)(delegate
  1925. {
  1926. //电机存储的故障日志,一包128字节包含2条故障日志
  1927. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1928. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1929. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1930. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1931. //数据显示
  1932. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1933. }));
  1934. }
  1935. break;
  1936. }
  1937. case 0x1401://在线检测结果
  1938. {
  1939. unchecked
  1940. {
  1941. this.Invoke((EventHandler)(delegate
  1942. {
  1943. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1944. }));
  1945. }
  1946. break;
  1947. }
  1948. case 0x1510://骑行历史信息
  1949. {
  1950. unchecked
  1951. {
  1952. this.Invoke((EventHandler)(delegate
  1953. {
  1954. long DataTemp32;
  1955. //ODO里程
  1956. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1957. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1958. textBox_ODO_KM.Text = DataTemp32.ToString();
  1959. //ODO时间
  1960. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1961. if (DataTemp32 >= 60 * 100000)
  1962. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1963. else
  1964. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1965. textBox_ODO_TIME.Text = DataTemp32.ToString();
  1966. //TRIP里程
  1967. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1968. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1969. textBox_TRIP_KM.Text = DataTemp32.ToString();
  1970. //TRIP时间
  1971. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1972. if (DataTemp32 >= 60 * 100000)
  1973. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1974. else
  1975. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1976. textBox_TRIP_TIME.Text = DataTemp32.ToString();
  1977. }));
  1978. }
  1979. break;
  1980. }
  1981. case 0x1720://客户信息
  1982. {
  1983. unchecked
  1984. {
  1985. this.Invoke((EventHandler)(delegate
  1986. {
  1987. //软件标识
  1988. textBox_SP.Text = "";
  1989. textBox_OBC_ReadSP.Text = "";
  1990. textBox_FacModeSP.Text = "";
  1991. for (ushort i = 0; i < 23; i++)
  1992. {
  1993. if (Data[i] == 'r')
  1994. {
  1995. Data[i] = (byte)'.';
  1996. }
  1997. textBox_SP.Text += ((char)Data[i]).ToString();
  1998. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1999. textBox_FacModeSP.Text += ((char)Data[i]).ToString();
  2000. }
  2001. //Git提交版本信息
  2002. textBox_FacModeGit.Text = "";
  2003. for (ushort i = 0; i < 9; i++)
  2004. {
  2005. textBox_SP.Text += ((char)Data[23 + i]).ToString();
  2006. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  2007. }
  2008. Class_Motor_Ver.Special = textBox_SP.Text;
  2009. }));
  2010. }
  2011. break;
  2012. }
  2013. case 0xBA20: //调试信息
  2014. {
  2015. unchecked
  2016. {
  2017. this.Invoke((EventHandler)(delegate
  2018. {
  2019. MC_DebugInfo_Refresh = true;
  2020. //系统状态机
  2021. DataTemp = (short)(Data[0]);
  2022. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  2023. //二层状态机
  2024. DataTemp = (short)(Data[1]);
  2025. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  2026. //电机状态机
  2027. DataTemp = (short)(Data[2]);
  2028. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  2029. //助力状态机
  2030. DataTemp = (short)(Data[3]);
  2031. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  2032. //IdRef
  2033. DataTemp = (short)(Data[5] * 256 + Data[4]);
  2034. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  2035. //IqRef
  2036. DataTemp = (short)(Data[7] * 256 + Data[6]);
  2037. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  2038. //UdRef
  2039. DataTemp = (short)(Data[9] * 256 + Data[8]);
  2040. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  2041. //UqRef
  2042. DataTemp = (short)(Data[11] * 256 + Data[10]);
  2043. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  2044. //瞬时力矩
  2045. DataTemp = (short)(Data[13] * 256 + Data[12]);
  2046. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  2047. //时间滤波力矩
  2048. DataTemp = (short)(Data[15] * 256 + Data[14]);
  2049. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  2050. //踏频滤波力矩
  2051. DataTemp = (short)(Data[17] * 256 + Data[16]);
  2052. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  2053. //IdFdb
  2054. DataTemp = (short)(Data[19] * 256 + Data[18]);
  2055. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  2056. //IqFdb
  2057. DataTemp = (short)(Data[21] * 256 + Data[20]);
  2058. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  2059. //助力输出
  2060. DataTemp = (short)(Data[23] * 256 + Data[22]);
  2061. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  2062. //转把百分比
  2063. DataTemp = (short)(Data[25] * 256 + Data[24]);
  2064. textBox_DebugInfo_ThrottlePer.Text = Convert.ToString(DataTemp);
  2065. //数据保存
  2066. RunInfoAutoSave();
  2067. }));
  2068. }
  2069. break;
  2070. }
  2071. case 0xBB20: //产品标签信息
  2072. {
  2073. unchecked
  2074. {
  2075. this.Invoke((EventHandler)(delegate
  2076. {
  2077. //产品标签
  2078. textBox_TagInfo.Text = "";
  2079. for (ushort i = 0; i < 32; i++)
  2080. {
  2081. textBox_TagInfo.Text += ((char)Data[i]).ToString();
  2082. }
  2083. }));
  2084. }
  2085. break;
  2086. }
  2087. case 0xBC20: //内阻校正信息
  2088. {
  2089. unchecked
  2090. {
  2091. this.Invoke((EventHandler)(delegate
  2092. {
  2093. //内阻1
  2094. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2095. textBox_MOS_R1.Text = Convert.ToString(uData16);
  2096. //内阻2
  2097. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2098. textBox_MOS_R2.Text = Convert.ToString(uData16);
  2099. //内阻3
  2100. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2101. textBox_MOS_R3.Text = Convert.ToString(uData16);
  2102. //K1
  2103. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2104. textBox_MOS_K1.Text = Convert.ToString(uData16);
  2105. //K2
  2106. uData16 = (ushort)(Data[9] * 256 + Data[8]);
  2107. textBox_MOS_K2.Text = Convert.ToString(uData16);
  2108. //K3
  2109. uData16 = (ushort)(Data[11] * 256 + Data[10]);
  2110. textBox_MOS_K3.Text = Convert.ToString(uData16);
  2111. //K4
  2112. uData16 = (ushort)(Data[13] * 256 + Data[12]);
  2113. textBox_MOS_K4.Text = Convert.ToString(uData16);
  2114. //K5
  2115. uData16 = (ushort)(Data[15] * 256 + Data[14]);
  2116. textBox_MOS_K5.Text = Convert.ToString(uData16);
  2117. }));
  2118. }
  2119. break;
  2120. }
  2121. case 0xBD20: //整车信息2
  2122. {
  2123. unchecked
  2124. {
  2125. this.Invoke((EventHandler)(delegate
  2126. {
  2127. richTextBox_BikeParam2.Clear();
  2128. for (int i = 0; i < myParams.BikeParam2.Count; i++)
  2129. {
  2130. richTextBox_BikeParam2.AppendText(myParams.BikeParam2[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  2131. }
  2132. richTextBox_BikeParam2.Text = richTextBox_BikeParam2.Text.Substring(0, richTextBox_BikeParam2.Text.Length - 2);
  2133. }));
  2134. }
  2135. break;
  2136. }
  2137. case 0xBE20: //用户骑行参数
  2138. {
  2139. unchecked
  2140. {
  2141. this.Invoke((EventHandler)(delegate
  2142. {
  2143. richTextBox_UsrRidesParam.Clear();
  2144. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2145. {
  2146. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2147. }
  2148. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2149. }));
  2150. }
  2151. break;
  2152. }
  2153. case 0xBF58:
  2154. {
  2155. unchecked
  2156. {
  2157. this.Invoke((EventHandler)(delegate
  2158. {
  2159. string[] str1 = new string[42];
  2160. double[] error1 = new double[42];
  2161. //更新校准数据
  2162. for (int i = 0; i < 42; i++)
  2163. {
  2164. double data1 = (Data[4 + i * 2] + (Data[4 + i * 2 + 1] << 8)) / 32767.0 * 360;
  2165. error1[i] = data1 - (60 * (i % 6) + 60);
  2166. if (error1[i] < -180)
  2167. {
  2168. error1[i] = error1[i] + 360;
  2169. }
  2170. str1[i] = data1.ToString("F2");
  2171. AngledataRecord[i] = str1[i];
  2172. }
  2173. for (int i = 0; i < 7; i++)
  2174. for (int j = 0; j < 6; j++)
  2175. {
  2176. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = str1[6 * i + j];
  2177. }
  2178. //计算偏差最小值、最大值和平均值
  2179. //Array.ConvertAll(error1, Math.Abs);
  2180. textBox_AngleDiffMin.Text = error1.Min().ToString("F2");
  2181. textBox_AngleDiffMax.Text = error1.Max().ToString("F2");
  2182. textBox_AngleDiffAvg.Text = error1.Average().ToString("F2");
  2183. //计算零点偏差
  2184. double tmp1 = ((Int16)(Data[0] + (Data[1] << 8))) / 32767.0 * 360;
  2185. textBox_AngleZeroInit.Text = tmp1.ToString("F2");
  2186. double tmp2 = ((Int16)(Data[2] + (Data[3] << 8))) / 32767.0 * 360;
  2187. textBox_AngleZeroCur.Text = tmp2.ToString("F2");
  2188. double tmp3 = (tmp2 - tmp1);
  2189. textBox_AngleZeroDiff.Text = tmp3.ToString("F2");
  2190. }));
  2191. }
  2192. break;
  2193. }
  2194. case 0xC109: //Boot版本信息
  2195. {
  2196. BootInfo = "";
  2197. for (ushort i = 0; i < 9; i++)
  2198. {
  2199. BootInfo += ((char)Data[i]).ToString();
  2200. }
  2201. break;
  2202. }
  2203. default:
  2204. {
  2205. break;
  2206. }
  2207. }
  2208. //存储器导出数据显示
  2209. if ((CmdTemp & 0xFF00) == 0xAB00)
  2210. {
  2211. unchecked
  2212. {
  2213. this.Invoke((EventHandler)(delegate
  2214. {
  2215. long ByteNum = 0;
  2216. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  2217. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2218. {
  2219. for (int i = 0; i < ByteNum; i++)
  2220. {
  2221. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2222. }
  2223. }
  2224. }));
  2225. }
  2226. }
  2227. }
  2228. #endregion
  2229. #region 解析BMS广播的命令
  2230. else if (ID == 0x720)
  2231. {
  2232. switch (CmdTemp)
  2233. {
  2234. case 0x1010://BMS运行信息
  2235. {
  2236. unchecked
  2237. {
  2238. this.Invoke((EventHandler)(delegate
  2239. {
  2240. BMS_RunInfo_Refresh = true;
  2241. richTextBox_OBC_BMS_RunInfo.Clear();
  2242. //电压
  2243. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  2244. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  2245. //电流
  2246. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  2247. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  2248. //剩余容量
  2249. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  2250. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2251. //满充容量
  2252. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  2253. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  2254. //电芯温度
  2255. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  2256. //剩余电量
  2257. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  2258. //电池状态
  2259. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  2260. //SOH
  2261. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  2262. //循环次数
  2263. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  2264. }));
  2265. }
  2266. break;
  2267. }
  2268. default: break;
  2269. }
  2270. }
  2271. #endregion
  2272. #region 解析电机发送OBC的命令
  2273. else if (ID == 0x713)
  2274. {
  2275. switch (CmdTemp)
  2276. {
  2277. case 0x5408://电机用户参数
  2278. {
  2279. unchecked
  2280. {
  2281. this.Invoke((EventHandler)(delegate
  2282. {
  2283. richTextBox_OBC_ReadUserInfo.Clear();
  2284. //默认周长
  2285. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  2286. //启动模式
  2287. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  2288. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  2289. //限速
  2290. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  2291. //周长微调
  2292. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  2293. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  2294. //助力方案
  2295. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  2296. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  2297. //关机时间
  2298. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  2299. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  2300. //限速微调
  2301. numericUpDown_OBC_SpeedLimitAdj.Value = (int)(Data[6] > 128 ? (Data[6] - 256) : Data[6]);
  2302. richTextBox_OBC_ReadUserInfo.AppendText("限速微调:" + Convert.ToString(numericUpDown_OBC_SpeedLimitAdj.Value) + " km/h" + "\r\n");
  2303. //定速巡航
  2304. comboBox_OBC_BikeCCS.SelectedIndex = (Data[7] == 0xAA) ? 1 : 2;
  2305. richTextBox_OBC_ReadUserInfo.AppendText("转把巡航:" + comboBox_OBC_BikeCCS.Text + "\r\n");
  2306. }));
  2307. }
  2308. break;
  2309. }
  2310. case 0x5303://电机应答反馈
  2311. {
  2312. unchecked
  2313. {
  2314. this.Invoke((EventHandler)(delegate
  2315. {
  2316. timer_500ms.Enabled = false;
  2317. MessageBoxTimeOut.Show("OK", "反馈指令", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  2318. timer_500ms.Enabled = true;
  2319. }));
  2320. }
  2321. break;
  2322. }
  2323. case 0x5620: //用户骑行参数
  2324. {
  2325. unchecked
  2326. {
  2327. this.Invoke((EventHandler)(delegate
  2328. {
  2329. richTextBox_UsrRidesParam.Clear();
  2330. for (int i = 0; i < myParams.UsrRideParam.Count; i++)
  2331. {
  2332. richTextBox_UsrRidesParam.AppendText(myParams.UsrRideParam[i] + "=" + Convert.ToString(Data[i]) + ", ");
  2333. }
  2334. richTextBox_UsrRidesParam.Text = richTextBox_UsrRidesParam.Text.Substring(0, richTextBox_UsrRidesParam.Text.Length - 2);
  2335. }));
  2336. }
  2337. break;
  2338. }
  2339. default: break;
  2340. }
  2341. }
  2342. #endregion
  2343. }
  2344. private void DataRevToString(ushort CmdTemp, byte[] Data)
  2345. {
  2346. CmdRevStrTemp = "";
  2347. CmdRevStrTemp += Convert.ToString(CmdTemp >> 8, 16).PadLeft(2, '0').ToUpper() + " ";
  2348. CmdRevStrTemp += Convert.ToString(CmdTemp & 0xFF, 16).PadLeft(2, '0').ToUpper() + " ";
  2349. ushort len = (ushort)(CmdTemp & 0x00FF);
  2350. for (int i = 0; i < len ; i++)
  2351. {
  2352. CmdRevStrTemp += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  2353. }
  2354. }
  2355. #endregion
  2356. /// <summary>
  2357. /// 端口连接或断开
  2358. /// </summary>
  2359. private void PortConnect()
  2360. {
  2361. bool result = false;
  2362. if (连接ToolStripMenuItem.Text == "连接")
  2363. {
  2364. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  2365. if (result)
  2366. {
  2367. toolStripComboBox_ComNum.Enabled = false;
  2368. toolStripComboBox_Baudrate.Enabled = false;
  2369. 刷新ToolStripMenuItem.Enabled = false;
  2370. 连接ToolStripMenuItem.Text = "断开";
  2371. 连接ToolStripMenuItem.Checked = true;
  2372. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  2373. label_PortStatus.BackColor = Color.Green;
  2374. }
  2375. }
  2376. else if (连接ToolStripMenuItem.Text == "断开")
  2377. {
  2378. checkBox_OBC_StartSetGearSt.Checked = false;
  2379. checkBox_OBC_StartReadBMS.Checked = false;
  2380. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2381. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2382. toolStripComboBox_ComNum.Enabled = true;
  2383. toolStripComboBox_Baudrate.Enabled = true;
  2384. 刷新ToolStripMenuItem.Enabled = true;
  2385. 连接ToolStripMenuItem.Text = "连接";
  2386. 连接ToolStripMenuItem.Checked = false;
  2387. label_COM_Sta.Text = "连接状态:未连接";
  2388. label_PortStatus.BackColor = Color.Red;
  2389. }
  2390. }
  2391. /// <summary>
  2392. /// 端口连接事件
  2393. /// </summary>
  2394. /// <param name="sender"></param>
  2395. /// <param name="e"></param>
  2396. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  2397. {
  2398. PortConnect();
  2399. }
  2400. /// <summary>
  2401. /// 端口号刷新事件
  2402. /// </summary>
  2403. /// <param name="sender"></param>
  2404. /// <param name="e"></param>
  2405. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  2406. {
  2407. toolStripComboBox_ComNum.Items.Clear();
  2408. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  2409. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  2410. }
  2411. /// <summary>
  2412. /// 存储标志修改事件
  2413. /// </summary>
  2414. /// <param name="sender"></param>
  2415. /// <param name="e"></param>
  2416. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  2417. {
  2418. if (写入存储ToolStripMenuItem.Checked)
  2419. {
  2420. EnterForm1.ShowDialog();
  2421. try
  2422. {
  2423. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  2424. {
  2425. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  2426. {
  2427. 写入存储ToolStripMenuItem.Checked = false;
  2428. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2429. }
  2430. else
  2431. {
  2432. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2433. }
  2434. }
  2435. else
  2436. {
  2437. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2438. }
  2439. }
  2440. catch (Exception)
  2441. {
  2442. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2443. }
  2444. }
  2445. else
  2446. {
  2447. 写入存储ToolStripMenuItem.Checked = true;
  2448. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  2449. }
  2450. }
  2451. /// <summary>
  2452. /// 1s定时器
  2453. /// </summary>
  2454. /// <param name="sender"></param>
  2455. /// <param name="e"></param>
  2456. private void timer_1s_Tick(object sender, EventArgs e)
  2457. {
  2458. //时间更新
  2459. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2460. //MC_Runinfo超时清除
  2461. if (MC_RunInfo_Refresh == false)
  2462. {
  2463. MC_RunInfo_Refresh_Cnt++;
  2464. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  2465. {
  2466. MC_RunInfo_Clear();
  2467. MC_RunInfo_Refresh_Cnt = 0;
  2468. }
  2469. }
  2470. else
  2471. {
  2472. MC_RunInfo_Refresh_Cnt = 0;
  2473. }
  2474. MC_RunInfo_Refresh = false;
  2475. //MC_Debuginfo超时清除
  2476. if (MC_DebugInfo_Refresh == false)
  2477. {
  2478. MC_DebugInfo_Refresh_Cnt++;
  2479. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  2480. {
  2481. MC_DebugInfo_Clear();
  2482. MC_DebugInfo_Refresh_Cnt = 0;
  2483. }
  2484. }
  2485. else
  2486. {
  2487. MC_DebugInfo_Refresh_Cnt = 0;
  2488. }
  2489. MC_DebugInfo_Refresh = false;
  2490. //BMS_RunInfo超时清除
  2491. if (BMS_RunInfo_Refresh == false)
  2492. {
  2493. BMS_RunInfo_Refresh_Cnt++;
  2494. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  2495. {
  2496. richTextBox_OBC_BMS_RunInfo.Clear();
  2497. BMS_RunInfo_Refresh_Cnt = 0;
  2498. }
  2499. }
  2500. else
  2501. {
  2502. BMS_RunInfo_Refresh_Cnt = 0;
  2503. }
  2504. BMS_RunInfo_Refresh = false;
  2505. //故障码超时清除
  2506. if (MC_ErrorCode_Refresh == false)
  2507. {
  2508. MC_ErrorCode_Refresh_Cnt++;
  2509. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  2510. {
  2511. textBox_ErrorCode.Text = "---";
  2512. MC_ErrorCode_Refresh_Cnt = 0;
  2513. }
  2514. }
  2515. else
  2516. {
  2517. MC_ErrorCode_Refresh_Cnt = 0;
  2518. }
  2519. MC_ErrorCode_Refresh = false;
  2520. //CDL连接超时
  2521. if (识别通讯盒ToolStripMenuItem.Checked)
  2522. {
  2523. if (mySerialProcess.CDL_Online_Flag == false)
  2524. {
  2525. mySerialProcess.CDL_OnlineCheck_Cnt++;
  2526. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  2527. {
  2528. timer_500ms.Enabled = false;
  2529. MessageBox.Show("连接失败!", "提示");
  2530. timer_500ms.Enabled = true;
  2531. //关闭串口
  2532. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  2533. toolStripComboBox_ComNum.Enabled = true;
  2534. toolStripComboBox_Baudrate.Enabled = true;
  2535. 刷新ToolStripMenuItem.Enabled = true;
  2536. 连接ToolStripMenuItem.Text = "连接";
  2537. 连接ToolStripMenuItem.Checked = false;
  2538. label_COM_Sta.Text = "连接状态:未连接";
  2539. label_PortStatus.BackColor = Color.Red;
  2540. }
  2541. }
  2542. }
  2543. //OBC定时发送设置档位
  2544. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2545. {
  2546. var CtrlCode = new byte[2];
  2547. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  2548. CtrlCode[0] = 0x33;
  2549. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  2550. CtrlCode[0] = 0x22;
  2551. else
  2552. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  2553. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  2554. CtrlCode[1] = 0xF1;
  2555. else
  2556. CtrlCode[1] = 0xF0;
  2557. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  2558. {
  2559. checkBox_OBC_StartSetGearSt.Checked = false;
  2560. }
  2561. }
  2562. //OBC定时发送查询电池
  2563. if (checkBox_OBC_StartReadBMS.Checked == true)
  2564. {
  2565. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  2566. {
  2567. checkBox_OBC_StartReadBMS.Checked = false;
  2568. }
  2569. }
  2570. //定时读取存储器
  2571. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  2572. {
  2573. var Address = new byte[4];
  2574. UInt32 Address_Begin;
  2575. UInt32 Addres_End;
  2576. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  2577. richTextBox_RamFlasgData.Clear();
  2578. do
  2579. {
  2580. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2581. {
  2582. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2583. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2584. continue;
  2585. }
  2586. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2587. {
  2588. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2589. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2590. continue;
  2591. }
  2592. else
  2593. {
  2594. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2595. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2596. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2597. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2598. if (Addres_End < Address_Begin)
  2599. {
  2600. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2601. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2602. continue;
  2603. }
  2604. else
  2605. {
  2606. var SendByte = new byte[8];
  2607. SendByte[0] = (byte)(Address_Begin >> 24);
  2608. SendByte[1] = (byte)(Address_Begin >> 16);
  2609. SendByte[2] = (byte)(Address_Begin >> 8);
  2610. SendByte[3] = (byte)(Address_Begin);
  2611. SendByte[4] = (byte)(Addres_End >> 24);
  2612. SendByte[5] = (byte)(Addres_End >> 16);
  2613. SendByte[6] = (byte)(Addres_End >> 8);
  2614. SendByte[7] = (byte)(Addres_End);
  2615. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2616. checkBox_ReadRanFlash_AutoSW.Checked = false;
  2617. }
  2618. }
  2619. } while (false);
  2620. }
  2621. //写入参数等待计时
  2622. ACK_WaitCnt++;
  2623. }
  2624. /// <summary>
  2625. /// 运行信息清除
  2626. /// </summary>
  2627. private void MC_RunInfo_Clear()
  2628. {
  2629. foreach (Control c in tabPage_RunInfo.Controls)
  2630. {
  2631. if ((c is TextBox))
  2632. {
  2633. if (c.Name != textBox_ErrorCode.ToString())
  2634. c.Text = "---";
  2635. }
  2636. }
  2637. }
  2638. /// <summary>
  2639. /// 调试信息清除
  2640. /// </summary>
  2641. private void MC_DebugInfo_Clear()
  2642. {
  2643. foreach (Control c in tabPage_DebugInfo.Controls)
  2644. {
  2645. if ((c is TextBox))
  2646. {
  2647. if (c.Name != textBox_ErrorCode.ToString())
  2648. c.Text = "---";
  2649. }
  2650. }
  2651. }
  2652. /// <summary>
  2653. /// 读取马达参数
  2654. /// </summary>
  2655. /// <param name="sender"></param>
  2656. /// <param name="e"></param>
  2657. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  2658. {
  2659. richTextBox_MotorParam.Clear();
  2660. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  2661. }
  2662. /// <summary>
  2663. /// 写入马达参数
  2664. /// </summary>
  2665. /// <param name="sender"></param>
  2666. /// <param name="e"></param>
  2667. private void button_Write_Click(object sender, EventArgs e)
  2668. {
  2669. var ConfigParam = new byte[40];
  2670. for (int i = 0; i < 40; i++)
  2671. ConfigParam[i] = 0;
  2672. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2673. short wDataTemp = 0;
  2674. ushort DataTemp = 0;
  2675. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2676. try
  2677. {
  2678. for (int i = 0; i < strDataTemp.Length; i++)
  2679. {
  2680. if (i == 6)
  2681. {
  2682. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2683. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2684. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2685. }
  2686. else
  2687. {
  2688. DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2689. ConfigParam[2 * i + 2] = (byte)DataTemp;
  2690. ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
  2691. }
  2692. }
  2693. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  2694. }
  2695. catch (Exception)
  2696. {
  2697. timer_500ms.Enabled = false;
  2698. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2699. timer_500ms.Enabled = true;
  2700. }
  2701. }
  2702. /// <summary>
  2703. /// 读取整车信息
  2704. /// </summary>
  2705. /// <param name="sender"></param>
  2706. /// <param name="e"></param>
  2707. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  2708. {
  2709. richTextBox_BikeParam.Clear();
  2710. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2711. }
  2712. /// <summary>
  2713. /// 写入整车信息
  2714. /// </summary>
  2715. /// <param name="sender"></param>
  2716. /// <param name="e"></param>
  2717. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  2718. {
  2719. var ConfigParam = new byte[28];
  2720. for (int i = 0; i < 28; i++)
  2721. ConfigParam[i] = 0;
  2722. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2723. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2724. try
  2725. {
  2726. for (int i = 0; i < strDataTemp.Length; i++)
  2727. {
  2728. short wDataTemp = 0;
  2729. //前后灯参数修改
  2730. if (i == 8)
  2731. {
  2732. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  2733. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  2734. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  2735. }
  2736. //开关机参数
  2737. else if (i == 11)
  2738. {
  2739. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  2740. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  2741. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  2742. }
  2743. else
  2744. {
  2745. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  2746. }
  2747. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  2748. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  2749. }
  2750. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2751. }
  2752. catch (Exception)
  2753. {
  2754. timer_500ms.Enabled = false;
  2755. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2756. timer_500ms.Enabled = true;
  2757. }
  2758. }
  2759. /// <summary>
  2760. /// 读取控制器参数
  2761. /// </summary>
  2762. /// <param name="sender"></param>
  2763. /// <param name="e"></param>
  2764. private void button_ReadControlParam_Click(object sender, EventArgs e)
  2765. {
  2766. richTextBox_ControlParam.Clear();
  2767. comboBox_Bike_CCS.SelectedIndex = 0;
  2768. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  2769. }
  2770. /// <summary>
  2771. /// 写入控制器参数
  2772. /// </summary>
  2773. /// <param name="sender"></param>
  2774. /// <param name="e"></param>
  2775. private void button_WriteControlParam_Click(object sender, EventArgs e)
  2776. {
  2777. var ConfigParam = new byte[34];
  2778. for (int i = 0; i < 34; i++)
  2779. ConfigParam[i] = 0;
  2780. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2781. ushort uwDataTemp = 0;
  2782. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2783. try
  2784. {
  2785. for (int i = 0; i < strDataTemp.Length; i++)
  2786. {
  2787. if (i == 13)
  2788. {
  2789. uwDataTemp = (comboBox_Bike_CCS.SelectedIndex == 1) ? (ushort)0x00AA : (ushort)0x0000;
  2790. }
  2791. else
  2792. {
  2793. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2794. }
  2795. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2796. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2797. }
  2798. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  2799. }
  2800. catch (Exception)
  2801. {
  2802. timer_500ms.Enabled = false;
  2803. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2804. timer_500ms.Enabled = true;
  2805. }
  2806. }
  2807. /// <summary>
  2808. /// 读取助力参数
  2809. /// </summary>
  2810. /// <param name="sender"></param>
  2811. /// <param name="e"></param>
  2812. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  2813. {
  2814. var ConfigParam = new byte[4];
  2815. int AssistNum = 0;
  2816. try
  2817. {
  2818. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  2819. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  2820. ConfigParam[1] = (byte)(AssistNum >> 8);
  2821. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  2822. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  2823. ConfigParam[3] = (byte)(AssistNum >> 8);
  2824. richTextBox_AssistParam.Clear();
  2825. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2826. }
  2827. catch (Exception)
  2828. {
  2829. timer_500ms.Enabled = false;
  2830. MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2831. timer_500ms.Enabled = true;
  2832. }
  2833. }
  2834. /// <summary>
  2835. /// 写入助力参数
  2836. /// </summary>
  2837. /// <param name="sender"></param>
  2838. /// <param name="e"></param>
  2839. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2840. {
  2841. var ConfigParam = new byte[80];
  2842. for (int i = 0; i < 80; i++)
  2843. ConfigParam[i] = 0;
  2844. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2845. long lDataTemp = 0;
  2846. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2847. int index_1 = 0, index_2 = 0;
  2848. try
  2849. {
  2850. for (int i = 0; i < strDataTemp.Length; i++)
  2851. {
  2852. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2853. {
  2854. index_1 = i;
  2855. break;
  2856. }
  2857. }
  2858. for (int i = 0; i < strDataTemp.Length; i++)
  2859. {
  2860. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2861. {
  2862. index_2 = i;
  2863. break;
  2864. }
  2865. }
  2866. for (int i = 0; i < strDataTemp.Length; i++)
  2867. {
  2868. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2869. if (i < index_1)
  2870. {
  2871. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2872. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2873. }
  2874. else if (i <= index_2)
  2875. {
  2876. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2877. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2878. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2879. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2880. }
  2881. else
  2882. {
  2883. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2884. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2885. }
  2886. }
  2887. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2888. }
  2889. catch (Exception)
  2890. {
  2891. timer_500ms.Enabled = false;
  2892. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2893. timer_500ms.Enabled = true;
  2894. }
  2895. }
  2896. /// <summary>
  2897. /// 读取调试参数
  2898. /// </summary>
  2899. /// <param name="sender"></param>
  2900. /// <param name="e"></param>
  2901. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2902. {
  2903. richTextBox_DebugParam.Clear();
  2904. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2905. }
  2906. /// <summary>
  2907. /// 写入调试参数
  2908. /// </summary>
  2909. /// <param name="sender"></param>
  2910. /// <param name="e"></param>
  2911. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2912. {
  2913. var ConfigParam = new byte[60];
  2914. for (int i = 0; i < 60; i++)
  2915. ConfigParam[i] = 0;
  2916. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2917. ushort uwDataTemp = 0;
  2918. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2919. try
  2920. {
  2921. for (int i = 0; i < strDataTemp.Length; i++)
  2922. {
  2923. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2924. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2925. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2926. }
  2927. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2928. }
  2929. catch (Exception)
  2930. {
  2931. timer_500ms.Enabled = false;
  2932. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2933. timer_500ms.Enabled = true;
  2934. }
  2935. }
  2936. /// <summary>
  2937. /// 读取历史
  2938. /// </summary>
  2939. /// <param name="sender"></param>
  2940. /// <param name="e"></param>
  2941. private void button_ReadRecord_Click(object sender, EventArgs e)
  2942. {
  2943. richTextBox_Record.Clear();
  2944. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2945. }
  2946. /// <summary>
  2947. /// 读取传感器参数
  2948. /// </summary>
  2949. /// <param name="sender"></param>
  2950. /// <param name="e"></param>
  2951. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2952. {
  2953. richTextBox_SensorParam.Clear();
  2954. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2955. }
  2956. /// <summary>
  2957. /// 写入力矩传感器标定值
  2958. /// </summary>
  2959. /// <param name="sender"></param>
  2960. /// <param name="e"></param>
  2961. private void button_Write_Cal_Click(object sender, EventArgs e)
  2962. {
  2963. var ConfigParam = new byte[4];
  2964. for (int i = 0; i < 4; i++)
  2965. ConfigParam[i] = 0;
  2966. ushort uwDataTemp = 0;
  2967. try
  2968. {
  2969. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2970. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2971. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2972. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2973. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2974. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2975. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2976. }
  2977. catch (Exception)
  2978. {
  2979. timer_500ms.Enabled = false;
  2980. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2981. timer_500ms.Enabled = true;
  2982. }
  2983. }
  2984. /// <summary>
  2985. /// 写入传感器参数
  2986. /// </summary>
  2987. /// <param name="sender"></param>
  2988. /// <param name="e"></param>
  2989. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2990. {
  2991. var ConfigParam = new byte[14];
  2992. for (int i = 0; i < 14; i++)
  2993. ConfigParam[i] = 0;
  2994. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2995. ushort uwDataTemp = 0;
  2996. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2997. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2998. int index = 0;
  2999. try
  3000. {
  3001. for (int i = 0; i < strDataTemp.Length; i++)
  3002. {
  3003. if (strDataTemp[i].Split('=')[0] == "力矩传感器踏频脉冲数")
  3004. {
  3005. index = i;
  3006. break;
  3007. }
  3008. }
  3009. for (int i = 0; i < (strDataTemp.Length - index); i++)
  3010. {
  3011. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  3012. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3013. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3014. }
  3015. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  3016. }
  3017. catch (Exception)
  3018. {
  3019. timer_500ms.Enabled = false;
  3020. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3021. timer_500ms.Enabled = true;
  3022. }
  3023. }
  3024. /// <summary>
  3025. /// 写入型号
  3026. /// </summary>
  3027. /// <param name="sender"></param>
  3028. /// <param name="e"></param>
  3029. private void button_WriteModel_Click(object sender, EventArgs e)
  3030. {
  3031. string Mode = textBox_Model.Text;
  3032. var ModeArray = new byte[16];
  3033. for (ushort i = 0; i < Mode.Length; i++)
  3034. {
  3035. ModeArray[i] = (byte)Mode[i];
  3036. }
  3037. if (Mode.Length < 16)
  3038. {
  3039. ModeArray[Mode.Length] = (byte)'.';
  3040. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3041. {
  3042. ModeArray[Mode.Length + 1 + i] = 0x20;
  3043. }
  3044. }
  3045. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3046. }
  3047. /// <summary>
  3048. /// 写入SN
  3049. /// </summary>
  3050. /// <param name="sender"></param>
  3051. /// <param name="e"></param>
  3052. private void button_WriteSN_Click(object sender, EventArgs e)
  3053. {
  3054. string SN = textBox_SN.Text;
  3055. var SNArray = new byte[16];
  3056. for (ushort i = 0; i < SN.Length; i++)
  3057. {
  3058. SNArray[i] = (byte)SN[i];
  3059. }
  3060. if (SN.Length < 16)
  3061. {
  3062. SNArray[SN.Length] = (byte)'.';
  3063. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3064. {
  3065. SNArray[SN.Length + 1 + i] = 0x20;
  3066. }
  3067. }
  3068. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3069. }
  3070. /// <summary>
  3071. /// 查询版本信息
  3072. /// </summary>
  3073. /// <param name="sender"></param>
  3074. /// <param name="e"></param>
  3075. private void button_ReadVersion_Click(object sender, EventArgs e)
  3076. {
  3077. textBox_Model.Text = "---";
  3078. textBox_SN.Text = "---";
  3079. textBox_HW.Text = "---";
  3080. textBox_FW.Text = "---";
  3081. textBox_SP.Text = "---";
  3082. textBox_OBC_ReadModel.Text = "---";
  3083. textBox_OBC_ReadSN.Text = "---";
  3084. textBox_OBC_ReadHW.Text = "---";
  3085. textBox_OBC_ReadFW.Text = "---";
  3086. textBox_OBC_ReadSP.Text = "---";
  3087. textBox_FacModeName.Text = "---";
  3088. textBox_FacModeNum.Text = "---";
  3089. textBox_FacModeHW.Text = "---";
  3090. textBox_FacModeFW.Text = "---";
  3091. textBox_FacModeSP.Text = "---";
  3092. Class_Motor_Ver.Mode = "---";
  3093. Class_Motor_Ver.SN = "---";
  3094. Class_Motor_Ver.HW = "---";
  3095. Class_Motor_Ver.FW = "---";
  3096. Class_Motor_Ver.Special = "---";
  3097. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3098. }
  3099. /// <summary>
  3100. /// 查询自定义1
  3101. /// </summary>
  3102. /// <param name="sender"></param>
  3103. /// <param name="e"></param>
  3104. private void button_ReadUser1_Click(object sender, EventArgs e)
  3105. {
  3106. textBox_User1.Text = "---";
  3107. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  3108. }
  3109. /// <summary>
  3110. /// 查询自定义2
  3111. /// </summary>
  3112. /// <param name="sender"></param>
  3113. /// <param name="e"></param>
  3114. private void button_ReadUser2_Click(object sender, EventArgs e)
  3115. {
  3116. textBox_User2.Text = "---";
  3117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  3118. }
  3119. /// <summary>
  3120. /// 查询自定义3
  3121. /// </summary>
  3122. /// <param name="sender"></param>
  3123. /// <param name="e"></param>
  3124. private void button_ReadUser3_Click(object sender, EventArgs e)
  3125. {
  3126. textBox_User3.Text = "---";
  3127. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  3128. }
  3129. /// <summary>
  3130. /// 写入自定义字符串1
  3131. /// </summary>
  3132. /// <param name="sender"></param>
  3133. /// <param name="e"></param>
  3134. private void button_WriteUser1_Click(object sender, EventArgs e)
  3135. {
  3136. string User = textBox_User1.Text;
  3137. var UserArray = new byte[16];
  3138. for (ushort i = 0; i < User.Length; i++)
  3139. {
  3140. UserArray[i] = (byte)User[i];
  3141. }
  3142. if (User.Length < 16)
  3143. {
  3144. UserArray[User.Length] = (byte)'.';
  3145. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3146. {
  3147. UserArray[User.Length + 1 + i] = 0x20;
  3148. }
  3149. }
  3150. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  3151. }
  3152. /// <summary>
  3153. /// 写入自定义字符串2
  3154. /// </summary>
  3155. /// <param name="sender"></param>
  3156. /// <param name="e"></param>
  3157. private void button_WriteUser2_Click(object sender, EventArgs e)
  3158. {
  3159. string User = textBox_User2.Text;
  3160. var UserArray = new byte[16];
  3161. for (ushort i = 0; i < User.Length; i++)
  3162. {
  3163. UserArray[i] = (byte)User[i];
  3164. }
  3165. if (User.Length < 16)
  3166. {
  3167. UserArray[User.Length] = (byte)'.';
  3168. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3169. {
  3170. UserArray[User.Length + 1 + i] = 0x20;
  3171. }
  3172. }
  3173. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  3174. }
  3175. /// <summary>
  3176. /// 写入自定义字符串3
  3177. /// </summary>
  3178. /// <param name="sender"></param>
  3179. /// <param name="e"></param>
  3180. private void button_WriteUser3_Click(object sender, EventArgs e)
  3181. {
  3182. string User = textBox_User3.Text;
  3183. var UserArray = new byte[16];
  3184. for (ushort i = 0; i < User.Length; i++)
  3185. {
  3186. UserArray[i] = (byte)User[i];
  3187. }
  3188. if (User.Length < 16)
  3189. {
  3190. UserArray[User.Length] = (byte)'.';
  3191. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  3192. {
  3193. UserArray[User.Length + 1 + i] = 0x20;
  3194. }
  3195. }
  3196. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  3197. }
  3198. /// <summary>
  3199. /// 查询生产信息
  3200. /// </summary>
  3201. /// <param name="sender"></param>
  3202. /// <param name="e"></param>
  3203. private void button_ReadMAC_Click(object sender, EventArgs e)
  3204. {
  3205. textBox_MAC.Text = "---";
  3206. textBox_MACAdd.Text = "---";
  3207. textBox_MACDate.Text = "---";
  3208. textBox_PP.Text = "---";
  3209. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  3210. }
  3211. /// <summary>
  3212. /// 写入生产信息
  3213. /// </summary>
  3214. /// <param name="sender"></param>
  3215. /// <param name="e"></param>
  3216. private void button_WriteMac_Click(object sender, EventArgs e)
  3217. {
  3218. var MACArray = new byte[32];
  3219. //填入生产商
  3220. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  3221. {
  3222. MACArray[i] = (byte)textBox_MAC.Text[i];
  3223. }
  3224. if (textBox_MAC.Text.Length < 8)
  3225. {
  3226. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  3227. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  3228. {
  3229. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  3230. }
  3231. }
  3232. //填入生产地
  3233. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  3234. {
  3235. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  3236. }
  3237. if (textBox_MACAdd.Text.Length < 8)
  3238. {
  3239. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  3240. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  3241. {
  3242. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  3243. }
  3244. }
  3245. //填入生产日期
  3246. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  3247. {
  3248. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  3249. }
  3250. if (textBox_MACDate.Text.Length < 8)
  3251. {
  3252. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  3253. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  3254. {
  3255. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  3256. }
  3257. }
  3258. //填入品牌
  3259. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  3260. {
  3261. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  3262. }
  3263. if (textBox_PP.Text.Length < 8)
  3264. {
  3265. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  3266. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  3267. {
  3268. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  3269. }
  3270. }
  3271. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3272. }
  3273. /// <summary>
  3274. /// 查询密钥
  3275. /// </summary>
  3276. /// <param name="sender"></param>
  3277. /// <param name="e"></param>
  3278. private void button_ReadKey_Click(object sender, EventArgs e)
  3279. {
  3280. textBox_Key.Text = "---";
  3281. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  3282. }
  3283. /// <summary>
  3284. /// 写入校验密钥
  3285. /// </summary>
  3286. /// <param name="sender"></param>
  3287. /// <param name="e"></param>
  3288. private void button_WriteKey_Click(object sender, EventArgs e)
  3289. {
  3290. string Key = textBox_Key.Text;
  3291. var KeyArray = new byte[8];
  3292. if (Key.Length != 8)
  3293. {
  3294. timer_500ms.Enabled = false;
  3295. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3296. timer_500ms.Enabled = true;
  3297. return;
  3298. }
  3299. for (ushort i = 0; i < Key.Length; i++)
  3300. {
  3301. KeyArray[i] = (byte)Key[i];
  3302. }
  3303. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  3304. }
  3305. /// <summary>
  3306. /// 查询在线检测结果
  3307. /// </summary>
  3308. /// <param name="sender"></param>
  3309. /// <param name="e"></param>
  3310. private void button_ReadOnLine_Click(object sender, EventArgs e)
  3311. {
  3312. textBox_Online.Text = "---";
  3313. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  3314. }
  3315. /// <summary>
  3316. /// 系统清除
  3317. /// </summary>
  3318. /// <param name="sender"></param>
  3319. /// <param name="e"></param>
  3320. private void button_SystemClear_Click(object sender, EventArgs e)
  3321. {
  3322. var Code = new byte[5];
  3323. Code[0] = (byte)'C';
  3324. Code[1] = (byte)'L';
  3325. Code[2] = (byte)'E';
  3326. Code[3] = (byte)'A';
  3327. Code[4] = (byte)'R';
  3328. timer_500ms.Enabled = false;
  3329. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3330. {
  3331. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3332. {
  3333. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3334. {
  3335. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  3336. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3337. }
  3338. }
  3339. }
  3340. timer_500ms.Enabled = true;
  3341. }
  3342. /// <summary>
  3343. /// 参数还原
  3344. /// </summary>
  3345. /// <param name="sender"></param>
  3346. /// <param name="e"></param>
  3347. private void button_Recovery_Click(object sender, EventArgs e)
  3348. {
  3349. var Code = new byte[8];
  3350. Code[0] = (byte)'R';
  3351. Code[1] = (byte)'E';
  3352. Code[2] = (byte)'C';
  3353. Code[3] = (byte)'O';
  3354. Code[4] = (byte)'V';
  3355. Code[5] = (byte)'E';
  3356. Code[6] = (byte)'R';
  3357. Code[7] = (byte)'Y';
  3358. timer_500ms.Enabled = false;
  3359. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3360. {
  3361. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3362. {
  3363. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3364. {
  3365. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3366. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3367. }
  3368. }
  3369. }
  3370. timer_500ms.Enabled = true;
  3371. }
  3372. /// <summary>
  3373. /// 系统复位
  3374. /// </summary>
  3375. /// <param name="sender"></param>
  3376. /// <param name="e"></param>
  3377. private void button_Reset_Click(object sender, EventArgs e)
  3378. {
  3379. var Code_Off = new byte[5];
  3380. var Code_Reset = new byte[5];
  3381. Code_Off[0] = (byte)'O';
  3382. Code_Off[1] = (byte)'F';
  3383. Code_Off[2] = (byte)'F';
  3384. Code_Off[3] = (byte)'.';
  3385. Code_Off[4] = (byte)'.';
  3386. Code_Reset[0] = (byte)'R';
  3387. Code_Reset[1] = (byte)'E';
  3388. Code_Reset[2] = (byte)'S';
  3389. Code_Reset[3] = (byte)'E';
  3390. Code_Reset[4] = (byte)'T';
  3391. timer_500ms.Enabled = false;
  3392. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3393. {
  3394. timer_500ms.Enabled = true;
  3395. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3396. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3397. PowerOffAckStatus = false;
  3398. Delay_ms(250);
  3399. int TryCnt = 3;
  3400. while ((TryCnt--) >= 0)
  3401. {
  3402. if (!PowerOffAckStatus)
  3403. {
  3404. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  3405. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  3406. PowerOffAckStatus = false;
  3407. Delay_ms(250);
  3408. }
  3409. else break;
  3410. }
  3411. if (PowerOffAckStatus)
  3412. {
  3413. timer_500ms.Enabled = false;
  3414. MessageBoxTimeOut.Show("已关机!", "提示", 3000, MessageBoxButtons.OK, MessageBoxIcon.None);
  3415. timer_500ms.Enabled = true;
  3416. }
  3417. else
  3418. {
  3419. timer_500ms.Enabled = false;
  3420. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3421. timer_500ms.Enabled = true;
  3422. }
  3423. }
  3424. timer_500ms.Enabled = true;
  3425. }
  3426. /// <summary>
  3427. /// 记录清除
  3428. /// </summary>
  3429. /// <param name="sender"></param>
  3430. /// <param name="e"></param>
  3431. private void button_ClearLog_Click(object sender, EventArgs e)
  3432. {
  3433. var Code = new byte[9];
  3434. Code[0] = (byte)'L';
  3435. Code[1] = (byte)'O';
  3436. Code[2] = (byte)'G';
  3437. Code[3] = (byte)' ';
  3438. Code[4] = (byte)'C';
  3439. Code[5] = (byte)'L';
  3440. Code[6] = (byte)'E';
  3441. Code[7] = (byte)'A';
  3442. Code[8] = (byte)'R';
  3443. timer_500ms.Enabled = false;
  3444. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3445. {
  3446. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3447. {
  3448. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3449. {
  3450. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3451. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3452. }
  3453. }
  3454. }
  3455. timer_500ms.Enabled = true;
  3456. }
  3457. /// <summary>
  3458. /// 打开系统计算器
  3459. /// </summary>
  3460. /// <param name="sender"></param>
  3461. /// <param name="e"></param>
  3462. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  3463. {
  3464. System.Diagnostics.Process.Start("calc.exe");
  3465. }
  3466. /// <summary>
  3467. ///故障转换和显示
  3468. /// </summary>
  3469. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  3470. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  3471. "",""};
  3472. private string ErrorInfoDisplay(UInt32 Code)
  3473. {
  3474. string Result = "";
  3475. if (Code == 0)
  3476. {
  3477. Result = "无故障";
  3478. }
  3479. else
  3480. {
  3481. for (int i = 0; i < 32; i++)
  3482. {
  3483. if ((Code & 0x01) == 0x01)
  3484. {
  3485. Result += ErrorInfo[i] + " ";
  3486. }
  3487. Code >>= 1;
  3488. }
  3489. }
  3490. return Result;
  3491. }
  3492. /// <summary>
  3493. /// 鼠标滑过故障码显示具体内容
  3494. /// </summary>
  3495. /// <param name="sender"></param>
  3496. /// <param name="e"></param>
  3497. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  3498. {
  3499. // 创建the ToolTip
  3500. ToolTip toolTip1 = new ToolTip();
  3501. // 设置显示样式
  3502. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  3503. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3504. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3505. toolTip1.ShowAlways = true;//是否显示提示框
  3506. // 设置伴随的对象.
  3507. string ErrorCode = this.textBox_ErrorCode.Text;
  3508. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3509. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3510. }
  3511. /// <summary>
  3512. /// 数据记录
  3513. /// </summary>
  3514. private void RunInfoAutoSave()
  3515. {
  3516. if (运行信息记录ToolStripMenuItem.Checked == true)
  3517. {
  3518. if (RunInfoSaveFilename == string.Empty)
  3519. {
  3520. return;
  3521. }
  3522. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  3523. foreach (Control c in tabPage_RunInfo.Controls)
  3524. {
  3525. if (c is TextBox)
  3526. {
  3527. SaveData += c.Text + " , ";
  3528. }
  3529. }
  3530. foreach (Control c in tabPage_DebugInfo.Controls)
  3531. {
  3532. if (c is TextBox)
  3533. {
  3534. SaveData += c.Text + " , ";
  3535. }
  3536. }
  3537. SaveData += "\r\n";
  3538. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  3539. }
  3540. }
  3541. /// <summary>
  3542. /// 打开或关闭数据记录
  3543. /// </summary>
  3544. /// <param name="sender"></param>
  3545. /// <param name="e"></param>
  3546. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  3547. {
  3548. if (运行信息记录ToolStripMenuItem.Checked == false)
  3549. {
  3550. if (mySerialProcess.mySerial.IsOpen == true)
  3551. {
  3552. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  3553. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  3554. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  3555. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  3556. timer_500ms.Enabled = false;
  3557. MessageBoxTimeOut.Show("开始记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3558. timer_500ms.Enabled = true;
  3559. 运行信息记录ToolStripMenuItem.Checked = true;
  3560. }
  3561. else
  3562. {
  3563. timer_500ms.Enabled = false;
  3564. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  3565. timer_500ms.Enabled = true;
  3566. }
  3567. }
  3568. else
  3569. {
  3570. 运行信息记录ToolStripMenuItem.Checked = false;
  3571. timer_500ms.Enabled = false;
  3572. MessageBoxTimeOut.Show("停止记录", "提示", 500, MessageBoxButtons.OK, MessageBoxIcon.Information);
  3573. timer_500ms.Enabled = true;
  3574. }
  3575. }
  3576. /// <summary>
  3577. /// 仪表启动控制档位开关事件
  3578. /// </summary>
  3579. /// <param name="sender"></param>
  3580. /// <param name="e"></param>
  3581. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  3582. {
  3583. if (checkBox_OBC_StartSetGearSt.Checked == true)
  3584. {
  3585. //检查串口是否打开
  3586. if (!mySerialProcess.mySerial.IsOpen)
  3587. {
  3588. timer_500ms.Enabled = false;
  3589. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3590. timer_500ms.Enabled = true;
  3591. checkBox_OBC_StartSetGearSt.Checked = false;
  3592. return;
  3593. }
  3594. //检查是否选择档位和打开车灯
  3595. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  3596. {
  3597. timer_500ms.Enabled = false;
  3598. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3599. timer_500ms.Enabled = true;
  3600. checkBox_OBC_StartSetGearSt.Checked = false;
  3601. return;
  3602. }
  3603. }
  3604. }
  3605. /// <summary>
  3606. /// OBC查询电机用户参数
  3607. /// </summary>
  3608. /// <param name="sender"></param>
  3609. /// <param name="e"></param>
  3610. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  3611. {
  3612. richTextBox_OBC_ReadUserInfo.Clear();
  3613. comboBox_OBC_BikeCCS.SelectedIndex = 0;
  3614. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  3615. }
  3616. /// <summary>
  3617. /// OBC设置电机用户参数
  3618. /// </summary>
  3619. /// <param name="sender"></param>
  3620. /// <param name="e"></param>
  3621. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  3622. {
  3623. var UserInfoCode = new byte[8];
  3624. for (int i = 0; i < UserInfoCode.Length; i++)
  3625. UserInfoCode[i] = 0;
  3626. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  3627. {
  3628. timer_500ms.Enabled = false;
  3629. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3630. timer_500ms.Enabled = true;
  3631. return;
  3632. }
  3633. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  3634. {
  3635. timer_500ms.Enabled = false;
  3636. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3637. timer_500ms.Enabled = true;
  3638. return;
  3639. }
  3640. //周长微调
  3641. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  3642. //启动模式
  3643. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  3644. //助力方案
  3645. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  3646. //自动关机时间
  3647. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  3648. //限速微调
  3649. UserInfoCode[4] = (byte)(int)numericUpDown_OBC_SpeedLimitAdj.Value;
  3650. //定速巡航开关
  3651. UserInfoCode[5] = (byte)((comboBox_OBC_BikeCCS.SelectedIndex == 1) ? 0xAA : 0x00);
  3652. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  3653. }
  3654. /// <summary>
  3655. /// OBC查询电机版本信息
  3656. /// </summary>
  3657. /// <param name="sender"></param>
  3658. /// <param name="e"></param>
  3659. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  3660. {
  3661. textBox_Model.Text = "---";
  3662. textBox_SN.Text = "---";
  3663. textBox_HW.Text = "---";
  3664. textBox_FW.Text = "---";
  3665. textBox_SP.Text = "---";
  3666. textBox_OBC_ReadModel.Text = "---";
  3667. textBox_OBC_ReadSN.Text = "---";
  3668. textBox_OBC_ReadHW.Text = "---";
  3669. textBox_OBC_ReadFW.Text = "---";
  3670. textBox_OBC_ReadSP.Text = "---";
  3671. textBox_FacModeName.Text = "---";
  3672. textBox_FacModeNum.Text = "---";
  3673. textBox_FacModeHW.Text = "---";
  3674. textBox_FacModeFW.Text = "---";
  3675. textBox_FacModeSP.Text = "---";
  3676. Class_Motor_Ver.Mode = "---";
  3677. Class_Motor_Ver.SN = "---";
  3678. Class_Motor_Ver.HW = "---";
  3679. Class_Motor_Ver.FW = "---";
  3680. Class_Motor_Ver.Special = "---";
  3681. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3682. }
  3683. /// <summary>
  3684. /// OBC读取骑行历史
  3685. /// </summary>
  3686. /// <param name="sender"></param>
  3687. /// <param name="e"></param>
  3688. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  3689. {
  3690. textBox_OBC_TRIP_KM.Text = "";
  3691. textBox_OBC_TRIP_TIME.Text = "";
  3692. textBox_OBC_ODO_KM.Text = "";
  3693. textBox_OBC_ODO_TIME.Text = "";
  3694. textBox_ODO_KM.Text = "---";
  3695. textBox_ODO_TIME.Text = "---";
  3696. textBox_TRIP_KM.Text = "---";
  3697. textBox_TRIP_TIME.Text = "---";
  3698. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  3699. }
  3700. /// <summary>
  3701. /// OBC清除TRIP里程
  3702. /// </summary>
  3703. /// <param name="sender"></param>
  3704. /// <param name="e"></param>
  3705. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  3706. {
  3707. var Code = new byte[5];
  3708. Code[0] = (byte)'C';
  3709. Code[1] = (byte)'L';
  3710. Code[2] = (byte)'E';
  3711. Code[3] = (byte)'A';
  3712. Code[4] = (byte)'R';
  3713. timer_500ms.Enabled = false;
  3714. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3715. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  3716. timer_500ms.Enabled = true;
  3717. }
  3718. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  3719. {
  3720. if (checkBox_OBC_StartReadBMS.Checked == true)
  3721. {
  3722. //检查串口是否打开
  3723. if (!mySerialProcess.mySerial.IsOpen)
  3724. {
  3725. timer_500ms.Enabled = false;
  3726. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3727. timer_500ms.Enabled = true;
  3728. checkBox_OBC_StartReadBMS.Checked = false;
  3729. return;
  3730. }
  3731. }
  3732. }
  3733. /// <summary>
  3734. /// 写入力矩传感器参数
  3735. /// </summary>
  3736. /// <param name="sender"></param>
  3737. /// <param name="e"></param>
  3738. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  3739. {
  3740. var ConfigParam = new byte[46];
  3741. for (int i = 0; i < 14; i++)
  3742. ConfigParam[i] = 0;
  3743. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  3744. ushort uwDataTemp = 0;
  3745. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  3746. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  3747. int index = 0;
  3748. try
  3749. {
  3750. for (int i = 0; i < strDataTemp.Length; i++)
  3751. {
  3752. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  3753. {
  3754. index = i;
  3755. break;
  3756. }
  3757. }
  3758. for (int i = 0; i < (index + 1); i++)
  3759. {
  3760. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3761. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3762. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3763. }
  3764. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  3765. }
  3766. catch (Exception)
  3767. {
  3768. timer_500ms.Enabled = false;
  3769. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3770. timer_500ms.Enabled = true;
  3771. }
  3772. }
  3773. /// <summary>
  3774. /// 查询存储标志
  3775. /// </summary>
  3776. /// <param name="sender"></param>
  3777. /// <param name="e"></param>
  3778. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  3779. {
  3780. radioButton_EE_SaveYes.Checked = false;
  3781. radioButton_EE_SaveNo.Checked = false;
  3782. radioButton_SIP_SaveYes.Checked = false;
  3783. radioButton_SIP_SaveNo.Checked = false;
  3784. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  3785. }
  3786. /// <summary>
  3787. /// 写入存储标志
  3788. /// </summary>
  3789. /// <param name="sender"></param>
  3790. /// <param name="e"></param>
  3791. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  3792. {
  3793. var SaveFlag = new byte[6];
  3794. for (int i = 0; i < 6; i++)
  3795. SaveFlag[i] = 0;
  3796. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  3797. {
  3798. timer_500ms.Enabled = false;
  3799. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3800. timer_500ms.Enabled = true;
  3801. return;
  3802. }
  3803. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  3804. {
  3805. timer_500ms.Enabled = false;
  3806. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3807. timer_500ms.Enabled = true;
  3808. return;
  3809. }
  3810. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  3811. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  3812. SaveFlag[3] = 0;
  3813. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  3814. SaveFlag[5] = 0;
  3815. timer_500ms.Enabled = false;
  3816. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3817. {
  3818. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  3819. }
  3820. timer_500ms.Enabled = true;
  3821. }
  3822. /// <summary>
  3823. /// 读取指定地址数据
  3824. /// </summary>
  3825. /// <param name="sender"></param>
  3826. /// <param name="e"></param>
  3827. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  3828. {
  3829. var Address = new byte[4];
  3830. UInt32 Address_Begin;
  3831. UInt32 Addres_End;
  3832. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  3833. richTextBox_RamFlasgData.Clear();
  3834. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  3835. {
  3836. timer_500ms.Enabled = false;
  3837. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3838. timer_500ms.Enabled = true;
  3839. return;
  3840. }
  3841. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  3842. {
  3843. timer_500ms.Enabled = false;
  3844. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3845. timer_500ms.Enabled = true;
  3846. return;
  3847. }
  3848. else
  3849. {
  3850. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  3851. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3852. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3853. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3854. if (Addres_End < Address_Begin)
  3855. {
  3856. timer_500ms.Enabled = false;
  3857. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3858. timer_500ms.Enabled = true;
  3859. return;
  3860. }
  3861. else
  3862. {
  3863. var SendByte = new byte[8];
  3864. SendByte[0] = (byte)(Address_Begin >> 24);
  3865. SendByte[1] = (byte)(Address_Begin >> 16);
  3866. SendByte[2] = (byte)(Address_Begin >> 8);
  3867. SendByte[3] = (byte)(Address_Begin);
  3868. SendByte[4] = (byte)(Addres_End >> 24);
  3869. SendByte[5] = (byte)(Addres_End >> 16);
  3870. SendByte[6] = (byte)(Addres_End >> 8);
  3871. SendByte[7] = (byte)(Addres_End);
  3872. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3873. }
  3874. }
  3875. }
  3876. /// <summary>
  3877. /// 工作模式选择
  3878. /// </summary>
  3879. /// <param name="sender"></param>
  3880. /// <param name="e"></param>
  3881. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3882. {
  3883. var RunMode = new byte[1];
  3884. if (comboBox_WorkMode.Text == "配置模式")
  3885. RunMode[0] = 0x01;
  3886. else if (comboBox_WorkMode.Text == "调试模式")
  3887. RunMode[0] = 0x02;
  3888. else
  3889. RunMode[0] = 0x00;
  3890. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3891. }
  3892. /// <summary>
  3893. /// 助力档位选择
  3894. /// </summary>
  3895. /// <param name="sender"></param>
  3896. /// <param name="e"></param>
  3897. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3898. {
  3899. var CtrlCode = new byte[2];
  3900. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3901. CtrlCode[0] = 0x33;
  3902. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3903. CtrlCode[0] = 0x22;
  3904. else
  3905. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3906. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3907. CtrlCode[1] = 0xF1;
  3908. else
  3909. CtrlCode[1] = 0xF0;
  3910. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3911. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3912. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3913. }
  3914. /// <summary>
  3915. /// 仪表档位选择
  3916. /// </summary>
  3917. /// <param name="sender"></param>
  3918. /// <param name="e"></param>
  3919. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3920. {
  3921. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3922. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3923. }
  3924. /// <summary>
  3925. /// 生产模式初始化
  3926. /// </summary>
  3927. /// <param name="sender"></param>
  3928. /// <param name="e"></param>
  3929. private void button_FacModeInit_Click(object sender, EventArgs e)
  3930. {
  3931. var Code = new byte[5];
  3932. Code[0] = (byte)'C';
  3933. Code[1] = (byte)'L';
  3934. Code[2] = (byte)'E';
  3935. Code[3] = (byte)'A';
  3936. Code[4] = (byte)'R';
  3937. timer_500ms.Enabled = false;
  3938. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3939. {
  3940. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3941. {
  3942. timer_500ms.Enabled = true;
  3943. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3944. PowerOffAckStatus = false;
  3945. Delay_ms(250);
  3946. int TryCnt = 3;
  3947. while ((TryCnt--) >= 0)
  3948. {
  3949. if (!PowerOffAckStatus)
  3950. {
  3951. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3952. PowerOffAckStatus = false;
  3953. Delay_ms(250);
  3954. }
  3955. else break;
  3956. }
  3957. if (PowerOffAckStatus)
  3958. {
  3959. timer_500ms.Enabled = false;
  3960. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3961. timer_500ms.Enabled = true;
  3962. }
  3963. else
  3964. {
  3965. timer_500ms.Enabled = false;
  3966. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3967. timer_500ms.Enabled = true;
  3968. }
  3969. timer_500ms.Enabled = true;
  3970. }
  3971. }
  3972. timer_500ms.Enabled = true;
  3973. //清除历史测试记录
  3974. textBox_FacModeSensorADC0.Text = "";
  3975. textBox_FacModeSensorADC1.Text = "";
  3976. textBox_FacModeSensorADC2.Text = "";
  3977. textBox_FacModeSensorADC3.Text = "";
  3978. textBox_FacModeSensorADC4.Text = "";
  3979. LightSwitchStatus = false;
  3980. MotorRunStatus = false;
  3981. textBox_MotorSpeedPercent.Text = "5";
  3982. textBox_FacModeName.Text = "";
  3983. textBox_FacModeNum.Text = "";
  3984. textBox_FacModeHW.Text = "";
  3985. textBox_FacModeFW.Text = "";
  3986. }
  3987. /// <summary>
  3988. /// 生产模式读取传感器参数
  3989. /// </summary>
  3990. /// <param name="sender"></param>
  3991. /// <param name="e"></param>
  3992. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3993. {
  3994. richTextBox_SensorParam.Clear();
  3995. textBox_FacModeSensorADC0.Text = "";
  3996. textBox_FacModeSensorADC1.Text = "";
  3997. textBox_FacModeSensorADC2.Text = "";
  3998. textBox_FacModeSensorADC3.Text = "";
  3999. textBox_FacModeSensorADC4.Text = "";
  4000. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4001. }
  4002. /// <summary>
  4003. /// 生产模式传感器标定1
  4004. /// </summary>
  4005. /// <param name="sender"></param>
  4006. /// <param name="e"></param>
  4007. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  4008. {
  4009. var ConfigParam = new byte[4];
  4010. for (int i = 0; i < 4; i++)
  4011. ConfigParam[i] = 0;
  4012. ushort uwDataTemp = 0;
  4013. try
  4014. {
  4015. uwDataTemp = 1;//负载序号
  4016. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4017. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4018. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  4019. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4020. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4021. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4022. Delay_ms(200);
  4023. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4024. }
  4025. catch (Exception)
  4026. {
  4027. timer_500ms.Enabled = false;
  4028. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4029. timer_500ms.Enabled = true;
  4030. }
  4031. }
  4032. /// <summary>
  4033. /// 生产模式传感器标定2
  4034. /// </summary>
  4035. /// <param name="sender"></param>
  4036. /// <param name="e"></param>
  4037. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  4038. {
  4039. var ConfigParam = new byte[4];
  4040. for (int i = 0; i < 4; i++)
  4041. ConfigParam[i] = 0;
  4042. ushort uwDataTemp = 0;
  4043. try
  4044. {
  4045. uwDataTemp = 2;//负载序号
  4046. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4047. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4048. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  4049. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4050. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4051. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4052. Delay_ms(200);
  4053. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4054. }
  4055. catch (Exception)
  4056. {
  4057. timer_500ms.Enabled = false;
  4058. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4059. timer_500ms.Enabled = true;
  4060. }
  4061. }
  4062. /// <summary>
  4063. /// 生产模式传感器标定3
  4064. /// </summary>
  4065. /// <param name="sender"></param>
  4066. /// <param name="e"></param>
  4067. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  4068. {
  4069. var ConfigParam = new byte[4];
  4070. for (int i = 0; i < 4; i++)
  4071. ConfigParam[i] = 0;
  4072. ushort uwDataTemp = 0;
  4073. try
  4074. {
  4075. uwDataTemp = 3;//负载序号
  4076. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4077. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4078. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  4079. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4080. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4081. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4082. Delay_ms(200);
  4083. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4084. }
  4085. catch (Exception)
  4086. {
  4087. timer_500ms.Enabled = false;
  4088. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4089. timer_500ms.Enabled = true;
  4090. }
  4091. }
  4092. /// <summary>
  4093. /// 生产模式传感器标定3
  4094. /// </summary>
  4095. /// <param name="sender"></param>
  4096. /// <param name="e"></param>
  4097. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  4098. {
  4099. var ConfigParam = new byte[4];
  4100. for (int i = 0; i < 4; i++)
  4101. ConfigParam[i] = 0;
  4102. ushort uwDataTemp = 0;
  4103. try
  4104. {
  4105. uwDataTemp = 4;//负载序号
  4106. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  4107. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  4108. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  4109. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  4110. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  4111. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  4112. Delay_ms(200);
  4113. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  4114. }
  4115. catch (Exception)
  4116. {
  4117. timer_500ms.Enabled = false;
  4118. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4119. timer_500ms.Enabled = true;
  4120. }
  4121. }
  4122. /// <summary>
  4123. /// 生产模式开关灯
  4124. /// </summary>
  4125. /// <param name="sender"></param>
  4126. /// <param name="e"></param>
  4127. bool LightSwitchStatus = false;
  4128. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  4129. {
  4130. var CtrlCode = new byte[2];
  4131. CtrlCode[0] = 0x00;
  4132. if (LightSwitchStatus)
  4133. {
  4134. CtrlCode[1] = 0xF0;
  4135. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  4136. }
  4137. else
  4138. {
  4139. CtrlCode[1] = 0xF1;
  4140. button_FacModeLightSW.BackColor = Color.Yellow;
  4141. }
  4142. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  4143. {
  4144. LightSwitchStatus = !LightSwitchStatus;
  4145. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4146. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  4147. }
  4148. }
  4149. /// <summary>
  4150. /// 生产模式电机控制
  4151. /// </summary>
  4152. /// <param name="sender"></param>
  4153. /// <param name="e"></param>
  4154. bool MotorRunStatus = false;
  4155. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  4156. {
  4157. string DebugDefaultInfo = "";
  4158. //获取调试信息
  4159. if (richTextBox_DebugParam.Text == string.Empty)
  4160. {
  4161. richTextBox_DebugParam.Clear();
  4162. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  4163. }
  4164. Delay_ms(200);
  4165. DebugDefaultInfo = richTextBox_DebugParam.Text;
  4166. //获取参数
  4167. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4168. if (strDataTemp.Length != 29)
  4169. {
  4170. timer_500ms.Enabled = false;
  4171. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4172. timer_500ms.Enabled = true;
  4173. return;
  4174. }
  4175. //设置参数
  4176. var ConfigParam = new byte[60];
  4177. for (int i = 0; i < 60; i++)
  4178. ConfigParam[i] = 0;
  4179. ConfigParam[0] = 0x00;
  4180. ushort uwDataTemp = 0;
  4181. if (!MotorRunStatus) //停止状态
  4182. {
  4183. //设置速度环
  4184. strDataTemp[0] = "整体运行模式=3";
  4185. //发送数据
  4186. try
  4187. {
  4188. for (int i = 0; i < strDataTemp.Length; i++)
  4189. {
  4190. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4191. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4192. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4193. }
  4194. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4195. return;
  4196. }
  4197. catch (Exception)
  4198. {
  4199. timer_500ms.Enabled = false;
  4200. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4201. timer_500ms.Enabled = true;
  4202. }
  4203. Delay_ms(200);
  4204. //设置转速百分比100%
  4205. textBox_MotorSpeedPercent.Text = "100";
  4206. ConfigParam[0] = (byte)100;
  4207. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4208. MotorRunStatus = !MotorRunStatus;
  4209. button_FacModeMotorRun.BackColor = Color.Yellow;
  4210. Delay_ms(200);
  4211. //电机进入配置模式
  4212. var RunMode = new byte[1];
  4213. RunMode[0] = 0x01;
  4214. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4215. }
  4216. else //运转状态
  4217. {
  4218. //设置转速百分比0%
  4219. textBox_MotorSpeedPercent.Text = "0";
  4220. ConfigParam[0] = (byte)0;
  4221. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, ConfigParam);
  4222. MotorRunStatus = !MotorRunStatus;
  4223. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  4224. Delay_ms(200);
  4225. //还原为原始值
  4226. strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  4227. try
  4228. {
  4229. for (int i = 0; i < strDataTemp.Length; i++)
  4230. {
  4231. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  4232. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  4233. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  4234. }
  4235. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  4236. return;
  4237. }
  4238. catch (Exception)
  4239. {
  4240. timer_500ms.Enabled = false;
  4241. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4242. timer_500ms.Enabled = true;
  4243. }
  4244. Delay_ms(200);
  4245. //电机退出配置模式
  4246. var RunMode = new byte[1];
  4247. RunMode[0] = 0x00;
  4248. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  4249. }
  4250. }
  4251. /// <summary>
  4252. /// 生产模式写入型号
  4253. /// </summary>
  4254. /// <param name="sender"></param>
  4255. /// <param name="e"></param>
  4256. private void button_FacModeSetName_Click(object sender, EventArgs e)
  4257. {
  4258. string Mode = textBox_FacModeName.Text;
  4259. var ModeArray = new byte[16];
  4260. for (ushort i = 0; i < Mode.Length; i++)
  4261. {
  4262. ModeArray[i] = (byte)Mode[i];
  4263. }
  4264. if (Mode.Length < 16)
  4265. {
  4266. ModeArray[Mode.Length] = (byte)'.';
  4267. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4268. {
  4269. ModeArray[Mode.Length + 1 + i] = 0x20;
  4270. }
  4271. }
  4272. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4273. }
  4274. /// <summary>
  4275. /// 生产模式写入SN
  4276. /// </summary>
  4277. /// <param name="sender"></param>
  4278. /// <param name="e"></param>
  4279. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  4280. {
  4281. string SN = textBox_FacModeNum.Text;
  4282. var SNArray = new byte[16];
  4283. for (ushort i = 0; i < SN.Length; i++)
  4284. {
  4285. SNArray[i] = (byte)SN[i];
  4286. }
  4287. if (SN.Length < 16)
  4288. {
  4289. SNArray[SN.Length] = (byte)'.';
  4290. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4291. {
  4292. SNArray[SN.Length + 1 + i] = 0x20;
  4293. }
  4294. }
  4295. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4296. }
  4297. /// <summary>
  4298. /// 生产模式读取版本信息
  4299. /// </summary>
  4300. /// <param name="sender"></param>
  4301. /// <param name="e"></param>
  4302. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  4303. {
  4304. textBox_Model.Text = "---";
  4305. textBox_SN.Text = "---";
  4306. textBox_HW.Text = "---";
  4307. textBox_FW.Text = "---";
  4308. textBox_SP.Text = "---";
  4309. textBox_OBC_ReadModel.Text = "---";
  4310. textBox_OBC_ReadSN.Text = "---";
  4311. textBox_OBC_ReadHW.Text = "---";
  4312. textBox_OBC_ReadFW.Text = "---";
  4313. textBox_OBC_ReadSP.Text = "---";
  4314. textBox_FacModeName.Text = "---";
  4315. textBox_FacModeNum.Text = "---";
  4316. textBox_FacModeHW.Text = "---";
  4317. textBox_FacModeFW.Text = "---";
  4318. textBox_FacModeSP.Text = "---";
  4319. textBox_FacModeGit.Text = "---";
  4320. Class_Motor_Ver.Mode = "---";
  4321. Class_Motor_Ver.SN = "---";
  4322. Class_Motor_Ver.HW = "---";
  4323. Class_Motor_Ver.FW = "---";
  4324. Class_Motor_Ver.Special = "---";
  4325. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  4326. }
  4327. /// <summary>
  4328. /// 生产模式写入生产信息
  4329. /// </summary>
  4330. /// <param name="sender"></param>
  4331. /// <param name="e"></param>
  4332. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  4333. {
  4334. var MACArray = new byte[32];
  4335. string MacDefaultInfo = "";
  4336. string MacAddDefaultInfo = "";
  4337. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  4338. string MacPPDefaultInfo = "";
  4339. do
  4340. {
  4341. //填入生产商
  4342. if (toolStripTextBox_MAC.Text == string.Empty)
  4343. {
  4344. break;
  4345. }
  4346. MacDefaultInfo = toolStripTextBox_MAC.Text;
  4347. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  4348. {
  4349. MACArray[i] = (byte)MacDefaultInfo[i];
  4350. }
  4351. if (MacDefaultInfo.Length < 8)
  4352. {
  4353. MACArray[MacDefaultInfo.Length] = (byte)'.';
  4354. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  4355. {
  4356. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  4357. }
  4358. }
  4359. //填入生产地
  4360. if (toolStripTextBoxMACAddr.Text == string.Empty)
  4361. {
  4362. break;
  4363. }
  4364. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  4365. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  4366. {
  4367. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  4368. }
  4369. if (MacAddDefaultInfo.Length < 8)
  4370. {
  4371. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  4372. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  4373. {
  4374. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  4375. }
  4376. }
  4377. //填入生产日期
  4378. if (toolStripTextBox_MACDate.Text == string.Empty)
  4379. {
  4380. break;
  4381. }
  4382. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  4383. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  4384. {
  4385. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  4386. }
  4387. if (MacDateDefaultInfo.Length < 8)
  4388. {
  4389. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  4390. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  4391. {
  4392. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  4393. }
  4394. }
  4395. //填入产品标识
  4396. if (toolStripTextBox_MACPD.Text == string.Empty)
  4397. {
  4398. break;
  4399. }
  4400. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  4401. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  4402. {
  4403. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  4404. }
  4405. if (MacPPDefaultInfo.Length < 8)
  4406. {
  4407. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  4408. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  4409. {
  4410. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  4411. }
  4412. }
  4413. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  4414. return;
  4415. } while (false);
  4416. timer_500ms.Enabled = false;
  4417. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4418. timer_500ms.Enabled = true;
  4419. }
  4420. /// <summary>
  4421. /// 生产模式保存测试页面
  4422. /// </summary>
  4423. /// <param name="sender"></param>
  4424. /// <param name="e"></param>
  4425. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  4426. {
  4427. Button_FacModeSaveResult.Text = "存储中…";
  4428. string[] AssistParams = new string[15];
  4429. do
  4430. {
  4431. //读取一次马达参数
  4432. richTextBox_MotorParam.Clear();
  4433. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  4434. Delay_ms(100);
  4435. //读取一次整车参数
  4436. richTextBox_BikeParam.Clear();
  4437. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  4438. Delay_ms(100);
  4439. //读取一次整车参数2
  4440. richTextBox_BikeParam2.Clear();
  4441. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  4442. Delay_ms(100);
  4443. //读取一次控制参数
  4444. richTextBox_ControlParam.Clear();
  4445. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  4446. Delay_ms(100);
  4447. //查询传感器
  4448. richTextBox_SensorParam.Clear();
  4449. textBox_FacModeSensorADC0.Text = "";
  4450. textBox_FacModeSensorADC1.Text = "";
  4451. textBox_FacModeSensorADC2.Text = "";
  4452. textBox_FacModeSensorADC3.Text = "";
  4453. textBox_FacModeSensorADC4.Text = "";
  4454. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  4455. Delay_ms(100);
  4456. //读取15次助力参数
  4457. for (int i = 1; i <= 15; i++)
  4458. {
  4459. var ConfigParam = new byte[4];
  4460. richTextBox_AssistParam.Clear();
  4461. ConfigParam[0] = (byte)(i & 0xFF);
  4462. ConfigParam[1] = (byte)(i >> 8);
  4463. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  4464. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  4465. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  4466. Delay_ms(200);
  4467. AssistParams[i - 1] = richTextBox_AssistParam.Text + "\r\n";
  4468. }
  4469. //读取一次用户骑行参数
  4470. richTextBox_UsrRidesParam.Clear();
  4471. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  4472. Delay_ms(100);
  4473. //读取一次调试信息
  4474. richTextBox_DebugParam.Clear();
  4475. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  4476. Delay_ms(100);
  4477. //读取一次历史信息
  4478. richTextBox_Record.Clear();
  4479. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  4480. Delay_ms(100);
  4481. //读取一次电机运行信息
  4482. var CtrlCode = new byte[2];
  4483. CtrlCode[0] = 0x00;
  4484. CtrlCode[1] = 0xF0;
  4485. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  4486. Delay_ms(100);
  4487. //读取一次版本信息
  4488. textBox_Model.Text = "---";
  4489. textBox_SN.Text = "---";
  4490. textBox_HW.Text = "---";
  4491. textBox_FW.Text = "---";
  4492. textBox_OBC_ReadModel.Text = "---";
  4493. textBox_OBC_ReadSN.Text = "---";
  4494. textBox_OBC_ReadHW.Text = "---";
  4495. textBox_OBC_ReadFW.Text = "---";
  4496. textBox_FacModeName.Text = "---";
  4497. textBox_FacModeNum.Text = "---";
  4498. textBox_FacModeHW.Text = "---";
  4499. textBox_FacModeFW.Text = "---";
  4500. Class_Motor_Ver.Mode = "---";
  4501. Class_Motor_Ver.SN = "---";
  4502. Class_Motor_Ver.HW = "---";
  4503. Class_Motor_Ver.FW = "---";
  4504. Class_Motor_Ver.Special = "---";
  4505. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  4506. Delay_ms(100);
  4507. //读取一次生产信息
  4508. textBox_MAC.Text = "";
  4509. textBox_MACAdd.Text = "";
  4510. textBox_MACDate.Text = "";
  4511. textBox_PP.Text = "";
  4512. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  4513. Delay_ms(100);
  4514. //读取一次自定义信息
  4515. textBox_User1.Text = "---";
  4516. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  4517. Delay_ms(100);
  4518. textBox_User2.Text = "---";
  4519. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4520. Delay_ms(100);
  4521. textBox_User3.Text = "---";
  4522. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4523. Delay_ms(100);
  4524. //读取一次密钥
  4525. textBox_Key.Text = "---";
  4526. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4527. Delay_ms(100);
  4528. //读取一次存储标志
  4529. radioButton_EE_SaveYes.Checked = false;
  4530. radioButton_EE_SaveNo.Checked = false;
  4531. radioButton_SIP_SaveYes.Checked = false;
  4532. radioButton_SIP_SaveNo.Checked = false;
  4533. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4534. Delay_ms(100);
  4535. //读取一次MOS内阻校准参数
  4536. foreach (Control c in groupBox21.Controls)
  4537. {
  4538. if (c is TextBox)
  4539. c.Text = "";
  4540. }
  4541. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  4542. Delay_ms(100);
  4543. //提示检查
  4544. #if false
  4545. timer_1s.Enabled = false;
  4546. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4547. {
  4548. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4549. timer_1s.Enabled = true;
  4550. return;
  4551. }
  4552. timer_1s.Enabled = true;
  4553. Delay_ms(200);
  4554. #endif
  4555. //判断数据是否有效
  4556. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "---"))
  4557. {
  4558. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4559. break;
  4560. }
  4561. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4562. {
  4563. MessageBox.Show("SN无效,保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4564. break;
  4565. }
  4566. //设置文件存储路径
  4567. string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  4568. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4569. Save_Path += PD_PathName;
  4570. if (!Directory.Exists(Save_Path))
  4571. Directory.CreateDirectory(Save_Path);
  4572. //保存页面
  4573. string PIC_SaveFileName = "";
  4574. Double scaleX = PrimaryScreen.ScaleX;
  4575. Double scaleY = PrimaryScreen.ScaleY;
  4576. //保存页面
  4577. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4578. Graphics g = Graphics.FromImage(bit);
  4579. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4580. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4581. bit.Save(PIC_SaveFileName);
  4582. //保存数据
  4583. string DataFileName = "";
  4584. string FileInfo = "";
  4585. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4586. FileInfo += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  4587. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4588. FileInfo += "\r\n";
  4589. FileInfo += "[电机信息]\r\n";
  4590. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4591. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4592. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4593. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4594. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4595. FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
  4596. FileInfo += "\r\n";
  4597. FileInfo += "[马达参数]\r\n";
  4598. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4599. FileInfo += "\r\n";
  4600. FileInfo += "[整车参数]\r\n";
  4601. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4602. FileInfo += "\r\n";
  4603. FileInfo += "[控制参数]\r\n";
  4604. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4605. FileInfo += "\r\n";
  4606. FileInfo += "[传感器参数]\r\n";
  4607. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4608. FileInfo += "\r\n";
  4609. FileInfo += "[助力参数]\r\n";
  4610. for(int i=0;i<15;i++)
  4611. {
  4612. FileInfo += AssistParams[i] + "\r\n";
  4613. }
  4614. FileInfo += "[调试参数]\r\n";
  4615. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4616. FileInfo += "\r\n";
  4617. FileInfo += "[历史信息]\r\n";
  4618. FileInfo += richTextBox_Record.Text + "\r\n";
  4619. FileInfo += "\r\n";
  4620. FileInfo += "[MOS内阻校准参数]\r\n";
  4621. FileInfo += textBox_MOS_K1.Text + ", ";
  4622. FileInfo += textBox_MOS_K2.Text + ", ";
  4623. FileInfo += textBox_MOS_K3.Text + ", ";
  4624. FileInfo += textBox_MOS_K4.Text + ", ";
  4625. FileInfo += textBox_MOS_K5.Text + ", ";
  4626. FileInfo += textBox_MOS_R1.Text + ", ";
  4627. FileInfo += textBox_MOS_R2.Text + ", ";
  4628. FileInfo += textBox_MOS_R3.Text + "\r\n";
  4629. FileInfo += "\r\n";
  4630. FileInfo += "[整车参数2]\r\n";
  4631. FileInfo += richTextBox_BikeParam2.Text + "\r\n";
  4632. FileInfo += "\r\n";
  4633. FileInfo += "[用户骑行参数]\r\n";
  4634. FileInfo += richTextBox_UsrRidesParam.Text + "\r\n";
  4635. FileInfo += "\r\n";
  4636. FileInfo += "[生产信息]\r\n";
  4637. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4638. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4639. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4640. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4641. FileInfo += "\r\n";
  4642. FileInfo += "[自定义信息]\r\n";
  4643. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4644. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4645. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4646. FileInfo += "\r\n";
  4647. FileInfo += "[校验密钥]\r\n";
  4648. FileInfo += textBox_Key.Text + "\r\n";
  4649. FileInfo += "\r\n";
  4650. FileInfo += "[存储标志]\r\n";
  4651. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4652. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4653. FileInfo += "\r\n";
  4654. FileInfo += Local_HdInformation;
  4655. FileInfo += "\r\n";
  4656. FileInfo += "文件格式: V2.0\r\n";
  4657. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4658. Delay_ms(1000);
  4659. timer_500ms.Enabled = false;
  4660. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4661. timer_500ms.Enabled = true;
  4662. //数据上传
  4663. if (myFtp.IsNetConnected == true)
  4664. {
  4665. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  4666. //检查路径
  4667. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4668. {
  4669. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4670. }
  4671. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, "Samples") == false)
  4672. {
  4673. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples");
  4674. }
  4675. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples", DataNow) == false)
  4676. {
  4677. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow);
  4678. }
  4679. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow, PD_PathName) == false)
  4680. {
  4681. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4682. }
  4683. //上传文件
  4684. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4685. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\Samples" + "\\" + DataNow + "\\" + PD_PathName);
  4686. if ((result1 & result2) == true)
  4687. {
  4688. timer_500ms.Enabled = false;
  4689. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  4690. timer_500ms.Enabled = true;
  4691. }
  4692. else
  4693. {
  4694. timer_500ms.Enabled = false;
  4695. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4696. timer_500ms.Enabled = true;
  4697. }
  4698. }
  4699. else
  4700. {
  4701. timer_500ms.Enabled = false;
  4702. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4703. timer_500ms.Enabled = true;
  4704. }
  4705. Button_FacModeSaveResult.Text = "保存数据";
  4706. return;
  4707. } while (false);
  4708. timer_500ms.Enabled = false;
  4709. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4710. timer_500ms.Enabled = true;
  4711. Button_FacModeSaveResult.Text = "保存数据";
  4712. }
  4713. /// <summary>
  4714. /// 工具箱页面保存
  4715. /// </summary>
  4716. /// <param name="sender"></param>
  4717. /// <param name="e"></param>
  4718. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4719. {
  4720. Double scaleX = PrimaryScreen.ScaleX;
  4721. Double scaleY = PrimaryScreen.ScaleY;
  4722. //保存页面
  4723. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  4724. Graphics g = Graphics.FromImage(bit);
  4725. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  4726. SaveFileDialog sf = new SaveFileDialog();
  4727. sf.Title = "页面保存";
  4728. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4729. sf.Filter = "图片|*.png";
  4730. timer_500ms.Enabled = false;
  4731. if (sf.ShowDialog() == DialogResult.OK)
  4732. {
  4733. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4734. }
  4735. timer_500ms.Enabled = true;
  4736. }
  4737. /// <summary>
  4738. /// 生产模式关机
  4739. /// </summary>
  4740. /// <param name="sender"></param>
  4741. /// <param name="e"></param>
  4742. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4743. {
  4744. var Code_Off = new byte[5];
  4745. var Code_Reset = new byte[5];
  4746. Code_Off[0] = (byte)'O';
  4747. Code_Off[1] = (byte)'F';
  4748. Code_Off[2] = (byte)'F';
  4749. Code_Off[3] = (byte)'.';
  4750. Code_Off[4] = (byte)'.';
  4751. Code_Reset[0] = (byte)'R';
  4752. Code_Reset[1] = (byte)'E';
  4753. Code_Reset[2] = (byte)'S';
  4754. Code_Reset[3] = (byte)'E';
  4755. Code_Reset[4] = (byte)'T';
  4756. timer_500ms.Enabled = false;
  4757. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4758. {
  4759. timer_500ms.Enabled = true;
  4760. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4761. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4762. PowerOffAckStatus = false;
  4763. Delay_ms(250);
  4764. int TryCnt = 3;
  4765. while ((TryCnt--) >= 0)
  4766. {
  4767. if (!PowerOffAckStatus)
  4768. {
  4769. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4770. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4771. PowerOffAckStatus = false;
  4772. Delay_ms(250);
  4773. }
  4774. else break;
  4775. }
  4776. if (PowerOffAckStatus)
  4777. {
  4778. timer_500ms.Enabled = false;
  4779. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4780. timer_500ms.Enabled = true;
  4781. }
  4782. else
  4783. {
  4784. timer_500ms.Enabled = false;
  4785. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4786. timer_500ms.Enabled = true;
  4787. }
  4788. }
  4789. timer_500ms.Enabled = true;
  4790. }
  4791. //仪表电源键按下
  4792. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4793. {
  4794. var Code = new byte[2];
  4795. Code[0] = 0;
  4796. Code[1] = 0b00100000;
  4797. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4798. }
  4799. /// <summary>
  4800. /// 仪表加键按下
  4801. /// </summary>
  4802. /// <param name="sender"></param>
  4803. /// <param name="e"></param>
  4804. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4805. {
  4806. var Code = new byte[2];
  4807. Code[0] = 0;
  4808. Code[1] = 0b00010000;
  4809. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4810. }
  4811. /// <summary>
  4812. /// 仪表减键按下
  4813. /// </summary>
  4814. /// <param name="sender"></param>
  4815. /// <param name="e"></param>
  4816. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4817. {
  4818. var Code = new byte[2];
  4819. Code[0] = 0;
  4820. Code[1] = 0b00001000;
  4821. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4822. }
  4823. /// <summary>
  4824. /// 仪表Walk键按下
  4825. /// </summary>
  4826. /// <param name="sender"></param>
  4827. /// <param name="e"></param>
  4828. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4829. {
  4830. var Code = new byte[2];
  4831. Code[0] = 0;
  4832. Code[1] = 0b00000100;
  4833. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4834. }
  4835. /// <summary>
  4836. /// 仪表Light键按下
  4837. /// </summary>
  4838. /// <param name="sender"></param>
  4839. /// <param name="e"></param>
  4840. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4841. {
  4842. var Code = new byte[2];
  4843. Code[0] = 0;
  4844. Code[1] = 0b00000010;
  4845. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4846. }
  4847. /// <summary>
  4848. /// 仪表Set键按下
  4849. /// </summary>
  4850. /// <param name="sender"></param>
  4851. /// <param name="e"></param>
  4852. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4853. {
  4854. var Code = new byte[2];
  4855. Code[0] = 0;
  4856. Code[1] = 0b00000001;
  4857. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4858. }
  4859. /// <summary>
  4860. /// 导出电机故障日志
  4861. /// </summary>
  4862. /// <param name="sender"></param>
  4863. /// <param name="e"></param>
  4864. private void button_ExportLog_Click(object sender, EventArgs e)
  4865. {
  4866. var Address = new byte[4];
  4867. UInt32 Address_Begin;
  4868. UInt32 Addres_End;
  4869. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4870. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4871. richTextBox_Record.Clear();
  4872. textBox_LogAddrBegin.ReadOnly = true;
  4873. textBox_LogAddrEnd.ReadOnly = true;
  4874. if (!mySerialProcess.mySerial.IsOpen)
  4875. {
  4876. timer_500ms.Enabled = false;
  4877. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4878. timer_500ms.Enabled = true;
  4879. return;
  4880. }
  4881. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4882. {
  4883. timer_500ms.Enabled = false;
  4884. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4885. timer_500ms.Enabled = true;
  4886. return;
  4887. }
  4888. else
  4889. {
  4890. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin, false);
  4891. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4892. Address = mySerialProcess.HexStringToBytes(textBox_Address_End, false);
  4893. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4894. if (Addres_End <= Address_Begin)
  4895. {
  4896. timer_500ms.Enabled = false;
  4897. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4898. timer_500ms.Enabled = true;
  4899. return;
  4900. }
  4901. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4902. {
  4903. timer_500ms.Enabled = false;
  4904. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4905. timer_500ms.Enabled = true;
  4906. return;
  4907. }
  4908. else
  4909. {
  4910. UInt32 ReadCount = 0;
  4911. button_ExportLog.Text = "导出中...";
  4912. button_ExportLog.Enabled = false;
  4913. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4914. for (ushort i = 0; i < ReadCount; i++)
  4915. {
  4916. var SendByte = new byte[8];
  4917. UInt32 Address_Temp_Begin;
  4918. UInt32 Address_Temp_End;
  4919. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4920. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4921. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4922. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4923. SendByte[3] = (byte)(Address_Temp_Begin);
  4924. Address_Temp_End = Address_Temp_Begin + 127;
  4925. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4926. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4927. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4928. SendByte[7] = (byte)(Address_Temp_End);
  4929. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4930. Delay_ms(200);//Thread.Sleep(200);
  4931. }
  4932. button_ExportLog.Text = "导出日志";
  4933. button_ExportLog.Enabled = true;
  4934. }
  4935. }
  4936. }
  4937. /// <summary>
  4938. /// 保存日志信息
  4939. /// </summary>
  4940. /// <param name="sender"></param>
  4941. /// <param name="e"></param>
  4942. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4943. {
  4944. string SaveInfo = "";
  4945. if (richTextBox_Record.Text == string.Empty)
  4946. {
  4947. timer_500ms.Enabled = false;
  4948. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4949. timer_500ms.Enabled = true;
  4950. return;
  4951. }
  4952. //获取保存信息
  4953. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4954. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4955. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4956. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4957. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4958. SaveInfo += "\r\n";
  4959. SaveInfo += richTextBox_Record.Text;
  4960. //设置保存路径和文件名
  4961. SaveFileDialog sf = new SaveFileDialog();
  4962. sf.Title = "数据保存";
  4963. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4964. sf.FileName.Replace(" ", "");
  4965. sf.Filter = "日志|*.ttlog";
  4966. if (sf.ShowDialog() == DialogResult.OK)
  4967. {
  4968. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4969. }
  4970. }
  4971. /// <summary>
  4972. /// 双击修改日志起始地址
  4973. /// </summary>
  4974. /// <param name="sender"></param>
  4975. /// <param name="e"></param>
  4976. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4977. {
  4978. textBox_LogAddrBegin.ReadOnly = false;
  4979. }
  4980. /// <summary>
  4981. /// 双击修改日志结束地址
  4982. /// </summary>
  4983. /// <param name="sender"></param>
  4984. /// <param name="e"></param>
  4985. private void label88_DoubleClick(object sender, EventArgs e)
  4986. {
  4987. textBox_LogAddrEnd.ReadOnly = false;
  4988. }
  4989. /// <summary>
  4990. /// 存储器自动读取选择
  4991. /// </summary>
  4992. /// <param name="sender"></param>
  4993. /// <param name="e"></param>
  4994. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4995. {
  4996. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4997. {
  4998. //检查串口是否打开
  4999. if (!mySerialProcess.mySerial.IsOpen)
  5000. {
  5001. timer_500ms.Enabled = false;
  5002. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5003. timer_500ms.Enabled = true;
  5004. checkBox_ReadRanFlash_AutoSW.Checked = false;
  5005. return;
  5006. }
  5007. }
  5008. }
  5009. /// <summary>
  5010. /// 系统开机按钮
  5011. /// </summary>
  5012. /// <param name="sender"></param>
  5013. /// <param name="e"></param>
  5014. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5015. {
  5016. byte[] Data = new byte[1];
  5017. Data[0] = 0xF1;
  5018. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5019. }
  5020. /// <summary>
  5021. /// 系统关机按钮
  5022. /// </summary>
  5023. /// <param name="sender"></param>
  5024. /// <param name="e"></param>
  5025. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5026. {
  5027. byte[] Data = new byte[1];
  5028. Data[0] = 0xF0;
  5029. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data);
  5030. }
  5031. /// <summary>
  5032. /// 连接开机选择
  5033. /// </summary>
  5034. /// <param name="sender"></param>
  5035. /// <param name="e"></param>
  5036. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  5037. {
  5038. //输入用户名
  5039. EnterForm1.ShowDialog();
  5040. try
  5041. {
  5042. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5043. {
  5044. if (EnterForm1.comboBox_User.Text == "管理员")
  5045. {
  5046. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  5047. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5048. }
  5049. else
  5050. {
  5051. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5052. }
  5053. }
  5054. else
  5055. {
  5056. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5057. }
  5058. }
  5059. catch (Exception)
  5060. {
  5061. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5062. }
  5063. }
  5064. /// <summary>
  5065. /// 断开关机选择
  5066. /// </summary>
  5067. /// <param name="sender"></param>
  5068. /// <param name="e"></param>
  5069. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  5070. {
  5071. //输入用户名
  5072. EnterForm1.ShowDialog();
  5073. try
  5074. {
  5075. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5076. {
  5077. if (EnterForm1.comboBox_User.Text == "管理员")
  5078. {
  5079. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  5080. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5081. }
  5082. else
  5083. {
  5084. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5085. }
  5086. }
  5087. else
  5088. {
  5089. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5090. }
  5091. }
  5092. catch (Exception)
  5093. {
  5094. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5095. }
  5096. }
  5097. /// <summary>
  5098. /// 识别通讯盒选择
  5099. /// </summary>
  5100. /// <param name="sender"></param>
  5101. /// <param name="e"></param>
  5102. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  5103. {
  5104. //输入用户名
  5105. EnterForm1.ShowDialog();
  5106. try
  5107. {
  5108. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  5109. {
  5110. if (EnterForm1.comboBox_User.Text == "管理员")
  5111. {
  5112. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  5113. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5114. }
  5115. else
  5116. {
  5117. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5118. }
  5119. }
  5120. else
  5121. {
  5122. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5123. }
  5124. }
  5125. catch (Exception)
  5126. {
  5127. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5128. }
  5129. }
  5130. /// <summary>
  5131. /// 将配置信息导出为cfg文件
  5132. /// </summary>
  5133. private void ConfigFileSave(bool DeleteFlag, string FileName)
  5134. {
  5135. if (DeleteFlag)
  5136. {
  5137. if (File.Exists(FileName))
  5138. File.Delete(FileName);
  5139. }
  5140. string CfgFileInfo = "";
  5141. CfgFileInfo += "[PortSet]" + "\r\n";
  5142. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  5143. CfgFileInfo += "PortBaudrate:" + "115200" + "\r\n";
  5144. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5145. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5146. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  5147. CfgFileInfo += "\r\n";
  5148. CfgFileInfo += "[Option]" + "\r\n";
  5149. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  5150. CfgFileInfo += "\r\n";
  5151. CfgFileInfo += "[ServerSet]" + "\r\n";
  5152. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  5153. CfgFileInfo += "\r\n";
  5154. CfgFileInfo += "[MacInfo]" + "\r\n";
  5155. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  5156. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  5157. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  5158. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  5159. CfgFileInfo += "\r\n";
  5160. CfgFileInfo += "[LogAddress]" + "\r\n";
  5161. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  5162. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  5163. CfgFileInfo += "\r\n";
  5164. CfgFileInfo += "[MotorType]" + "\r\n";
  5165. CfgFileInfo += "MidMotor:" + 中置电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5166. CfgFileInfo += "HubMotor:" + 轮毂电机ToolStripMenuItem.Checked.ToString() + "\r\n";
  5167. CfgFileInfo += "\r\n";
  5168. CfgFileInfo += "[CheckValue]" + "\r\n";
  5169. CfgFileInfo += "Voltage:" + toolStripTextBox_ThVol.Text + "\r\n";
  5170. CfgFileInfo += "Current:" + toolStripTextBox_ThCur.Text + "\r\n";
  5171. CfgFileInfo += "MotorSpeed:" + toolStripTextBox_ThSpeed.Text + "\r\n";
  5172. CfgFileInfo += "Torque:" + toolStripTextBox_ThTor.Text + "\r\n";
  5173. CfgFileInfo += "Cadence:" + toolStripTextBox_ThCad.Text + "\r\n";
  5174. CfgFileInfo += "BikeSpeed:" + toolStripTextBox_ThBikeSpeed.Text + "\r\n";
  5175. CfgFileInfo += "T_PCB:" + toolStripTextBox_ThT_PCB.Text + "\r\n";
  5176. CfgFileInfo += "T_MCU:" + toolStripTextBox_ThT_MCU.Text + "\r\n";
  5177. CfgFileInfo += "T_Motor:" + toolStripTextBox_ThT_Motor.Text + "\r\n";
  5178. CfgFileInfo += "\r\n";
  5179. CfgFileInfo += "[MosCalK]" + "\r\n";
  5180. CfgFileInfo += "K1-K5:" + toolStripTextBox_MosCalK.Text + "\r\n";
  5181. CfgFileInfo += "MOS1:" + toolStripTextBox_MOS1.Text + "\r\n";
  5182. CfgFileInfo += "MOS2:" + toolStripTextBox_MOS2.Text + "\r\n";
  5183. CfgFileInfo += "MOS3:" + toolStripTextBox_MOS3.Text + "\r\n";
  5184. CfgFileInfo += "\r\n";
  5185. CfgFileInfo += "[ProtocolType]" + "\r\n";
  5186. CfgFileInfo += "CAN:" + cANToolStripMenuItem.Checked.ToString() + "\r\n";
  5187. CfgFileInfo += "UART:" + uARTToolStripMenuItem.Checked.ToString() + "\r\n";
  5188. CfgFileInfo += "\r\n";
  5189. CfgFileInfo += "[AutoUpdate]" + "\r\n";
  5190. CfgFileInfo += "AutoUpdate:" + 打开ToolStripMenuItem.Checked.ToString() + "\r\n";
  5191. CfgFileInfo += "\r\n";
  5192. CfgFileInfo += "[AngleCal]" + "\r\n";
  5193. CfgFileInfo += "MaxDiffLimit:" + textBox_AngleDiffTh.Text + "\r\n";
  5194. CfgFileInfo += "ZeroDiffLimit:" + textBox_AngleZeroTh.Text + "\r\n";
  5195. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  5196. }
  5197. /// <summary>
  5198. /// 配置状态更新,点击时保存
  5199. /// </summary>
  5200. private void ConfigFileSave_Click(object sender, EventArgs e)
  5201. {
  5202. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5203. }
  5204. /// <summary>
  5205. /// 文本框修改结束,回车保存
  5206. /// </summary>
  5207. /// <param name="sender"></param>
  5208. /// <param name="e"></param>
  5209. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  5210. {
  5211. if (e.KeyCode == Keys.Enter)
  5212. {
  5213. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5214. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  5215. }
  5216. }
  5217. /// <summary>
  5218. /// 弹出扫码按钮
  5219. /// </summary>
  5220. /// <param name="sender"></param>
  5221. /// <param name="e"></param>
  5222. private void button_ScanCode_Click(object sender, EventArgs e)
  5223. {
  5224. Scan scan_form = new Scan();
  5225. scan_form.ShowDialog();
  5226. do
  5227. {
  5228. if (scan_form.textBox_Scan.Text == string.Empty)
  5229. {
  5230. timer_500ms.Enabled = false;
  5231. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5232. timer_500ms.Enabled = true;
  5233. break;
  5234. }
  5235. string ScanInfo = scan_form.textBox_Scan.Text;
  5236. string regexInfo = "";
  5237. string[] InfoList = { "" };
  5238. try
  5239. {
  5240. if (中置电机ToolStripMenuItem.Checked == true)
  5241. {
  5242. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  5243. InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  5244. }
  5245. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5246. {
  5247. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  5248. string Model = InfoList[0];
  5249. string Spec = InfoList[1];
  5250. string Sn = InfoList[2];
  5251. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  5252. InfoList[1] = Sn;
  5253. }
  5254. }
  5255. catch (Exception)
  5256. {
  5257. MessageBox.Show("格式错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  5258. return;
  5259. }
  5260. if (InfoList.Length >= 2)
  5261. {
  5262. //写入型号
  5263. textBox_FacModeName.Text = InfoList[0];
  5264. string Mode = textBox_FacModeName.Text;
  5265. var ModeArray = new byte[16];
  5266. for (ushort i = 0; i < Mode.Length; i++)
  5267. {
  5268. ModeArray[i] = (byte)Mode[i];
  5269. }
  5270. if (Mode.Length < 16)
  5271. {
  5272. ModeArray[Mode.Length] = (byte)'.';
  5273. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  5274. {
  5275. ModeArray[Mode.Length + 1 + i] = 0x20;
  5276. }
  5277. }
  5278. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  5279. //写入SN
  5280. textBox_FacModeNum.Text = InfoList[1];
  5281. string SN = textBox_FacModeNum.Text;
  5282. var SNArray = new byte[16];
  5283. for (ushort i = 0; i < SN.Length; i++)
  5284. {
  5285. SNArray[i] = (byte)SN[i];
  5286. }
  5287. if (SN.Length < 16)
  5288. {
  5289. SNArray[SN.Length] = (byte)'.';
  5290. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  5291. {
  5292. SNArray[SN.Length + 1 + i] = 0x20;
  5293. }
  5294. }
  5295. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  5296. }
  5297. else
  5298. {
  5299. timer_500ms.Enabled = false;
  5300. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5301. timer_500ms.Enabled = true;
  5302. break;
  5303. }
  5304. } while (false);
  5305. scan_form.Dispose();
  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 = true;
  5315. 轮毂电机ToolStripMenuItem.Checked = false;
  5316. toolStripTextBox_MACPD.Text = "MM_MC1";
  5317. toolStripTextBox_ServerPath.Text = "MIGIC_TEST";
  5318. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5319. }
  5320. /// <summary>
  5321. /// 切换电机类型
  5322. /// </summary>
  5323. /// <param name="sender"></param>
  5324. /// <param name="e"></param>
  5325. private void 轮毂电机ToolStripMenuItem_Click(object sender, EventArgs e)
  5326. {
  5327. 中置电机ToolStripMenuItem.Checked = false;
  5328. 轮毂电机ToolStripMenuItem.Checked = true;
  5329. toolStripTextBox_MACPD.Text = "GF_250_1";
  5330. toolStripTextBox_ServerPath.Text = "HUB_Control_TEST";
  5331. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  5332. }
  5333. /// <summary>
  5334. /// 获取配置文件日期
  5335. /// </summary>
  5336. /// <param name="DisAll"></param>
  5337. private void GetDateList(bool DisAll)
  5338. {
  5339. string[] DateList = { "" };
  5340. //从服务器更新日期列表
  5341. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5342. {
  5343. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  5344. }
  5345. //从本地更新日期列表
  5346. else
  5347. {
  5348. DateList = Directory.GetDirectories(localInfo.LocalPath + "\\" + localInfo.CfgPathName);
  5349. }
  5350. comboBox_FacModeCfgDate.Items.Clear();
  5351. comboBox_CheckModeCfgDate.Items.Clear();
  5352. //日期列表加载
  5353. if (DisAll == true)
  5354. {
  5355. comboBox_FacModeCfgDate.Items.Add("显示近期");
  5356. comboBox_CheckModeCfgDate.Items.Add("显示近期");
  5357. comboBox_FacModeCfgDate.Items.Add("---");
  5358. comboBox_CheckModeCfgDate.Items.Add("---");
  5359. foreach (var file in DateList)
  5360. {
  5361. comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5362. comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5363. }
  5364. }
  5365. else
  5366. {
  5367. if (DateList.Length > 10)
  5368. {
  5369. comboBox_FacModeCfgDate.Items.Add("显示全部");
  5370. comboBox_CheckModeCfgDate.Items.Add("显示全部");
  5371. comboBox_FacModeCfgDate.Items.Add("---");
  5372. comboBox_CheckModeCfgDate.Items.Add("---");
  5373. }
  5374. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  5375. {
  5376. comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5377. comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  5378. }
  5379. }
  5380. }
  5381. /// <summary>
  5382. /// 获取配置文件列表
  5383. /// </summary>
  5384. /// <param name="date"></param>
  5385. private void GetFileListFrom(string date)
  5386. {
  5387. string[] FileList = { "" };
  5388. //从服务器更新文件列表
  5389. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  5390. {
  5391. FileList = myFtp.GetFileNameList(toolStripTextBox_ServerPath.Text + "/cfg/" + date);
  5392. }
  5393. else
  5394. {
  5395. FileList = Directory.GetFiles(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + date);
  5396. }
  5397. comboBox_CheckModeCfgFile.Items.Clear();
  5398. comboBox_FacModeCfgFile.Items.Clear();
  5399. foreach (var file in FileList)
  5400. {
  5401. if (file.Contains(".ttcfg"))
  5402. {
  5403. comboBox_CheckModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5404. comboBox_FacModeCfgFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  5405. }
  5406. }
  5407. }
  5408. /// <summary>
  5409. /// 检验模式选择文件日期
  5410. /// </summary>
  5411. /// <param name="sender"></param>
  5412. /// <param name="e"></param>
  5413. private void comboBox_CheckModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5414. {
  5415. if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示全部")
  5416. {
  5417. GetDateList(true);
  5418. }
  5419. else if (comboBox_CheckModeCfgDate.SelectedItem.ToString() == "显示近期")
  5420. {
  5421. GetDateList(false);
  5422. }
  5423. else
  5424. {
  5425. comboBox_CheckModeCfgFile.Text = "";
  5426. GetFileListFrom(comboBox_CheckModeCfgDate.SelectedItem.ToString());
  5427. }
  5428. }
  5429. /// <summary>
  5430. /// 配置模式选择文件日期
  5431. /// </summary>
  5432. /// <param name="sender"></param>
  5433. /// <param name="e"></param>
  5434. private void comboBox_FacModeCfgDate_SelectionChangeCommitted(object sender, EventArgs e)
  5435. {
  5436. if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示全部")
  5437. {
  5438. GetDateList(true);
  5439. }
  5440. else if (comboBox_FacModeCfgDate.SelectedItem.ToString() == "显示近期")
  5441. {
  5442. GetDateList(false);
  5443. }
  5444. else
  5445. {
  5446. comboBox_FacModeCfgFile.Text = "";
  5447. GetFileListFrom(comboBox_FacModeCfgDate.SelectedItem.ToString());
  5448. }
  5449. }
  5450. /// <summary>
  5451. /// 选中量产模式
  5452. /// </summary>
  5453. /// <param name="sender"></param>
  5454. /// <param name="e"></param>
  5455. private void tabControl1_Selected(object sender, TabControlEventArgs e)
  5456. {
  5457. //更新生产配置文件目录
  5458. GetDateList(false);
  5459. }
  5460. /// <summary>
  5461. /// 量产测试结束
  5462. /// </summary>
  5463. /// <param name=""></param>
  5464. private void FacMode_Stop(bool OK_Flag)
  5465. {
  5466. //打开开始按钮
  5467. button__FacMode_Start.Enabled = true;
  5468. //系统关机
  5469. var Code = new byte[32];//发送的指令数据
  5470. Code[0] = 0xF0;
  5471. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5472. //关闭串口
  5473. //mySerialProcess.SerialClose(false);
  5474. //路径设置
  5475. string LocalSavePath = "";
  5476. string ServerSavePath = "";
  5477. if (OK_Flag)
  5478. {
  5479. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "OK\\";
  5480. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/OK/";
  5481. }
  5482. else
  5483. {
  5484. LocalSavePath = localInfo.LocalDataPath + localInfo.WalkLogPathName + "FAIL\\";
  5485. ServerSavePath = toolStripTextBox_ServerPath.Text + "/funcTest/FAIL/";
  5486. }
  5487. if (Directory.Exists(LocalSavePath) == false)
  5488. {
  5489. Directory.CreateDirectory(LocalSavePath);
  5490. }
  5491. //保存和上传
  5492. string LogSavePath = "";
  5493. string LogSaveFileName = "";
  5494. string ProductInfo = textBox_FacModeScan.Text.Replace(" ", "_");
  5495. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  5496. if (Directory.Exists(LogSavePath) == false)
  5497. {
  5498. Directory.CreateDirectory(LogSavePath);
  5499. }
  5500. //测试页面
  5501. Double scaleX = PrimaryScreen.ScaleX;
  5502. Double scaleY = PrimaryScreen.ScaleY;
  5503. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  5504. Graphics g = Graphics.FromImage(bit);
  5505. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  5506. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  5507. bit.Save(LogSaveFileName);
  5508. //上传测试页面到服务器
  5509. if (myFtp.IsNetConnected == true)
  5510. {
  5511. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5512. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5513. {
  5514. myFtp.MakeDir(ServerSavePath + DateNow);
  5515. }
  5516. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5517. {
  5518. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5519. }
  5520. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5521. if (result == true)
  5522. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  5523. }
  5524. else
  5525. {
  5526. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5527. }
  5528. //测试记录
  5529. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  5530. string file_str = "";
  5531. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  5532. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  5533. file_str += "检验记录:\r\n" + richTextBox_FacModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  5534. file_str += "检验结果:\r\n" + label_FacModeResult.Text + "\r\n\r\n";
  5535. file_str += Local_HdInformation;
  5536. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  5537. //上传测试记录到服务器
  5538. if (myFtp.IsNetConnected == true)
  5539. {
  5540. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  5541. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  5542. {
  5543. myFtp.MakeDir(ServerSavePath + DateNow);
  5544. }
  5545. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  5546. {
  5547. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  5548. }
  5549. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  5550. if (result == true)
  5551. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  5552. }
  5553. else
  5554. {
  5555. richTextBox_FacModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "服务器断开" + "\r\n";
  5556. }
  5557. //扫码框清空
  5558. textBox_FacModeScan.Text = "";
  5559. }
  5560. /// <summary>
  5561. /// 量产测试开始
  5562. /// </summary>
  5563. /// <param name="sender"></param>
  5564. /// <param name="e"></param>
  5565. private void button__FacMode_Start_Click(object sender, EventArgs e)
  5566. {
  5567. //关闭测试项目编辑
  5568. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  5569. foreach (Control c in groupBox2.Controls)
  5570. {
  5571. if (c is CheckBox)
  5572. c.Enabled = false;
  5573. }
  5574. WriteLockStatus = true;
  5575. //检查配置文件
  5576. if (comboBox_FacModeCfgFile.Text == "")
  5577. {
  5578. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5579. return;
  5580. }
  5581. //开始测试
  5582. TestStart();
  5583. }
  5584. /// <summary>
  5585. /// 测试子函数
  5586. /// </summary>
  5587. private void TestStart()
  5588. {
  5589. //初始化标签
  5590. FacModelLabelInit();
  5591. richTextBox_FacModeLog.Clear();
  5592. //按钮禁止操作
  5593. button__FacMode_Start.Enabled = false;
  5594. //记录配置文件
  5595. richTextBox_FacModeLog.AppendText("配置文件:" + comboBox_FacModeCfgDate.Text + " / " + comboBox_FacModeCfgFile.Text + "\r\n");
  5596. //检查打标信息格式
  5597. label_FacModeStatus.Text = "检查扫码信息";
  5598. Delay_ms(500);
  5599. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  5600. if (textBox_FacModeScan.Text == string.Empty)
  5601. {
  5602. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5603. button__FacMode_Start.Enabled = true;
  5604. return;
  5605. }
  5606. try
  5607. {
  5608. if (中置电机ToolStripMenuItem.Checked == true)
  5609. {
  5610. if (textBox_FacModeScan.Text.Split(' ').Length != 7)
  5611. {
  5612. label_FacModeStatus.Text = "存在故障!";
  5613. label_FacModeResult.BackColor = Color.Red;
  5614. label_FacModeResult.Text = "标签格式错误";
  5615. button__FacMode_Start.Enabled = true;
  5616. return;
  5617. }
  5618. }
  5619. else if (轮毂电机ToolStripMenuItem.Checked == true)
  5620. {
  5621. if (textBox_FacModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  5622. {
  5623. label_FacModeStatus.Text = "存在故障!";
  5624. label_FacModeResult.BackColor = Color.Red;
  5625. label_FacModeResult.Text = "标签格式错误";
  5626. button__FacMode_Start.Enabled = true;
  5627. return;
  5628. }
  5629. }
  5630. }
  5631. catch (System.Exception)
  5632. {
  5633. label_FacModeStatus.Text = "存在故障!";
  5634. label_FacModeResult.BackColor = Color.Red;
  5635. label_FacModeResult.Text = "标签格式错误";
  5636. button__FacMode_Start.Enabled = true;
  5637. return;
  5638. }
  5639. //打开串口
  5640. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  5641. if (!mySerialProcess.mySerial.IsOpen)
  5642. {
  5643. MessageBox.Show("请检查串口连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  5644. //按钮禁止操作
  5645. button__FacMode_Start.Enabled = true;
  5646. return;
  5647. }
  5648. //流水号计数
  5649. int serial = Convert.ToInt32(label_FacModeSerial.Text);
  5650. serial += 1;
  5651. label_FacModeSerial.Text = serial.ToString();
  5652. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, serial.ToString());
  5653. //创建线程,执行测试任务
  5654. Thread th = new Thread(FacModeTest_Task);
  5655. th.Start();
  5656. }
  5657. /// <summary>
  5658. /// 执行一次测试任务
  5659. /// </summary>
  5660. private void FacModeTest_Task()
  5661. {
  5662. //开始测试
  5663. richTextBox_FacModeLog.AppendText("产品标签:" + textBox_FacModeScan.Text + "\r\n");
  5664. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  5665. //变量定义
  5666. var Code = new byte[255];//发送的指令数据
  5667. label_FacModeStatus.Text = "开始测试";
  5668. BootInfo = "";
  5669. Delay_ms(500);
  5670. label_FacModeStatus.Text = "系统开机";
  5671. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5672. if (uARTToolStripMenuItem.Checked)
  5673. {
  5674. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5675. Code[0] = (byte)'R';
  5676. Code[1] = (byte)'E';
  5677. Code[2] = (byte)'S';
  5678. Code[3] = (byte)'E';
  5679. Code[4] = (byte)'T';
  5680. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5681. Delay_ms(500);
  5682. }
  5683. //发送开机指令
  5684. //确保测试前先关机,发送关机指令再发送开机指令
  5685. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  5686. Code[0] = 0xF0;
  5687. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5688. Delay_ms(1500);
  5689. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  5690. Code[0] = 0xF1;
  5691. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5692. ACK_WaitCnt = 0;
  5693. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5694. while (ACK_WaitCnt <= 20) ; //10s,等待开机成功,联动装置盒控制器接口波特率需等待5s接口自动切换为9600
  5695. //检查BOOT版本
  5696. if (BootInfo != string.Empty)
  5697. {
  5698. label_FacModeBootVer.BackColor = Color.Green;
  5699. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  5700. Delay_ms(500);
  5701. }
  5702. else
  5703. {
  5704. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  5705. label_FacModeStatus.Text = "存在故障!";
  5706. label_FacModeResult.BackColor = Color.Red;
  5707. label_FacModeResult.Text = "测试异常";
  5708. Delay_ms(500);
  5709. //存储异常并上传
  5710. FacMode_Stop(false);
  5711. return;
  5712. }
  5713. //系统清除
  5714. if (checkBox_FacModeSysClear.Checked)
  5715. {
  5716. do
  5717. {
  5718. #if false
  5719. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5720. {
  5721. Code[0] = 0x00;//5S协议
  5722. Code[1] = 0x00;
  5723. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5724. Delay_ms(500);
  5725. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5726. Delay_ms(500);
  5727. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5728. }
  5729. #endif
  5730. //发送系统清除指令
  5731. label_FacModeStatus.Text = "系统清除";
  5732. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
  5733. Code[0] = (byte)'C';
  5734. Code[1] = (byte)'L';
  5735. Code[2] = (byte)'E';
  5736. Code[3] = (byte)'A';
  5737. Code[4] = (byte)'R';
  5738. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5739. WriteACK = false;
  5740. WriteCnt = 0;
  5741. ACK_WaitCnt = 0;
  5742. while (ACK_WaitCnt <= 6); //3s
  5743. //等待系统清除完成指令
  5744. if (WriteACK == true)
  5745. {
  5746. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5747. label_FacModeSysClear.BackColor = Color.Green;
  5748. }
  5749. else
  5750. {
  5751. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第1次" + "\r\n");
  5752. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5753. ACK_WaitCnt = 0;
  5754. while (ACK_WaitCnt <= 6) ; //3s
  5755. //等待系统清除完成指令
  5756. if (WriteACK == true)
  5757. {
  5758. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5759. label_FacModeSysClear.BackColor = Color.Green;
  5760. }
  5761. else
  5762. {
  5763. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除,重发第2次" + "\r\n");
  5764. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  5765. ACK_WaitCnt = 0;
  5766. while (ACK_WaitCnt <= 6) ; //3s
  5767. //等待系统清除完成指令
  5768. if (WriteACK == true)
  5769. {
  5770. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
  5771. label_FacModeSysClear.BackColor = Color.Green;
  5772. }
  5773. else
  5774. {
  5775. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败" + "\r\n");
  5776. label_FacModeStatus.Text = "存在故障!";
  5777. label_FacModeResult.BackColor = Color.Red;
  5778. label_FacModeResult.Text = "测试异常";
  5779. Delay_ms(500);
  5780. //存储异常并上传
  5781. FacMode_Stop(false);
  5782. return;
  5783. }
  5784. }
  5785. }
  5786. BootInfo = "";
  5787. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  5788. if (uARTToolStripMenuItem.Checked)
  5789. {
  5790. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送复位指令,切换联动装置盒波特率" + "\r\n");
  5791. Code[0] = (byte)'R';
  5792. Code[1] = (byte)'E';
  5793. Code[2] = (byte)'S';
  5794. Code[3] = (byte)'E';
  5795. Code[4] = (byte)'T';
  5796. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  5797. Delay_ms(500);
  5798. }
  5799. //系统清除后需重新开机
  5800. label_FacModeStatus.Text = "重新开机";
  5801. //确保测试前先关机,发送关机指令再发送开机指令
  5802. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送关机指令" + "\r\n");
  5803. Code[0] = 0xF0;
  5804. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5805. Delay_ms(1500);
  5806. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新发送开机指令" + "\r\n");
  5807. Code[0] = 0xF1;
  5808. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  5809. ACK_WaitCnt = 0;
  5810. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  5811. while (ACK_WaitCnt <= 20); //10s
  5812. //获取Boot版本信息
  5813. if (BootInfo != string.Empty)
  5814. {
  5815. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  5816. Delay_ms(500);
  5817. }
  5818. else
  5819. {
  5820. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  5821. label_FacModeStatus.Text = "存在故障!";
  5822. label_FacModeResult.BackColor = Color.Red;
  5823. label_FacModeResult.Text = "测试异常";
  5824. Delay_ms(500);
  5825. //存储异常并上传
  5826. FacMode_Stop(false);
  5827. return;
  5828. }
  5829. } while (false);
  5830. }
  5831. else
  5832. {
  5833. label_FacModeSysClear.BackColor = Color.Yellow;
  5834. label_FacModeStatus.Text = "跳过系统清除!";
  5835. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过系统清除" + "\r\n");
  5836. Delay_ms(500);
  5837. }
  5838. #if false
  5839. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5840. {
  5841. Code[0] = 0x00;//5S协议
  5842. Code[1] = 0x00;
  5843. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5844. Delay_ms(500);
  5845. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5846. Delay_ms(500);
  5847. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5848. }
  5849. #endif
  5850. //检查是否有故障
  5851. if (textBox_ErrorCode.Text.Contains("H"))
  5852. {
  5853. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "故障码:" + textBox_ErrorCode.Text + "\r\n");
  5854. label_FacModeStatus.Text = "电机存在故障!";
  5855. label_FacModeResult.BackColor = Color.Red;
  5856. label_FacModeResult.Text = "测试异常";
  5857. Delay_ms(500);
  5858. //存储异常并上传
  5859. FacMode_Stop(false);
  5860. return;
  5861. }
  5862. //MOS内阻校准
  5863. if (checkBox_FacMode_MosCal.Checked)
  5864. {
  5865. label_FacModeStatus.Text = "MOS内阻校准";
  5866. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始MOS内阻校准" + "\r\n");
  5867. Delay_ms(500);
  5868. //提示进行负载切换
  5869. if (MessageBox.Show("电阻负载切换完成,开始校准?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  5870. {
  5871. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "取消MOS内阻校准" + "\r\n");
  5872. label_FacModeStatus.Text = "存在故障!";
  5873. label_FacModeResult.BackColor = Color.Red;
  5874. label_FacModeResult.Text = "测试异常";
  5875. Delay_ms(500);
  5876. //存储异常并上传
  5877. FacMode_Stop(false);
  5878. return;
  5879. }
  5880. //确认后发送校准指令
  5881. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令" + "\r\n");
  5882. string[] K = toolStripTextBox_MosCalK.Text.Split(',');
  5883. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  5884. ushort uwDataTemp = 0;
  5885. uwDataTemp = Convert.ToUInt16(K[0]);
  5886. Code[2] = (byte)(uwDataTemp & 0xFF);
  5887. Code[3] = (byte)(uwDataTemp >> 8);
  5888. uwDataTemp = Convert.ToUInt16(K[1]);
  5889. Code[4] = (byte)(uwDataTemp & 0xFF);
  5890. Code[5] = (byte)(uwDataTemp >> 8);
  5891. uwDataTemp = Convert.ToUInt16(K[2]);
  5892. Code[6] = (byte)(uwDataTemp & 0xFF);
  5893. Code[7] = (byte)(uwDataTemp >> 8);
  5894. uwDataTemp = Convert.ToUInt16(K[3]);
  5895. Code[8] = (byte)(uwDataTemp & 0xFF);
  5896. Code[9] = (byte)(uwDataTemp >> 8);
  5897. uwDataTemp = Convert.ToUInt16(K[4]);
  5898. Code[10] = (byte)(uwDataTemp & 0xFF);
  5899. Code[11] = (byte)(uwDataTemp >> 8);
  5900. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5901. WriteACK = false;
  5902. WriteCnt = 0;
  5903. ACK_WaitCnt = 0;
  5904. while (ACK_WaitCnt <= 6) ; //3s
  5905. if (WriteACK == true)
  5906. {
  5907. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5908. }
  5909. else
  5910. {
  5911. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第1次重发" + "\r\n");
  5912. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5913. ACK_WaitCnt = 0;
  5914. while (ACK_WaitCnt <= 6) ; //3s
  5915. if (WriteACK == true)
  5916. {
  5917. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5918. }
  5919. else
  5920. {
  5921. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送校准指令,第2次重发" + "\r\n");
  5922. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  5923. ACK_WaitCnt = 0;
  5924. while (ACK_WaitCnt <= 6) ; //3s
  5925. if (WriteACK == true)
  5926. {
  5927. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准完成" + "\r\n");
  5928. }
  5929. else
  5930. {
  5931. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准异常" + "\r\n");
  5932. label_FacModeStatus.Text = "存在故障!";
  5933. label_FacModeResult.BackColor = Color.Red;
  5934. label_FacModeResult.Text = "测试异常";
  5935. Delay_ms(500);
  5936. //存储异常并上传
  5937. FacMode_Stop(false);
  5938. return;
  5939. }
  5940. }
  5941. }
  5942. #if false
  5943. //因控制器复位需发送指令重新进入5S协议
  5944. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  5945. {
  5946. Code[0] = 0x00;//5S协议
  5947. Code[1] = 0x00;
  5948. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5949. Delay_ms(500);
  5950. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  5951. Delay_ms(500);
  5952. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  5953. }
  5954. #endif
  5955. //读取显示校准返回数据
  5956. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果" + "\r\n");
  5957. foreach (Control c in groupBox21.Controls)
  5958. {
  5959. if (c is TextBox)
  5960. c.Text = "";
  5961. }
  5962. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5963. ACK_WaitCnt = 0;
  5964. while (ACK_WaitCnt <= 2) ; //1s
  5965. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5966. {
  5967. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第1次重发" + "\r\n");
  5968. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5969. ACK_WaitCnt = 0;
  5970. while (ACK_WaitCnt <= 2) ; //1s
  5971. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5972. {
  5973. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果,第2次重发" + "\r\n");
  5974. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  5975. ACK_WaitCnt = 0;
  5976. while (ACK_WaitCnt <= 2) ; //1s
  5977. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  5978. {
  5979. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  5980. label_FacModeStatus.Text = "存在故障!";
  5981. label_FacModeResult.BackColor = Color.Red;
  5982. label_FacModeResult.Text = "测试异常";
  5983. Delay_ms(500);
  5984. //存储异常并上传
  5985. FacMode_Stop(false);
  5986. return;
  5987. }
  5988. }
  5989. }
  5990. else
  5991. {
  5992. 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");
  5993. }
  5994. //与校准返回数据对比
  5995. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  5996. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  5997. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  5998. 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])) &&
  5999. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  6000. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  6001. )
  6002. {
  6003. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  6004. label_FacModeMosCal.BackColor = Color.Green;
  6005. //提示切换负载
  6006. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6007. }
  6008. else
  6009. {
  6010. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  6011. label_FacModeStatus.Text = "存在故障!";
  6012. label_FacModeResult.BackColor = Color.Red;
  6013. label_FacModeResult.Text = "测试异常";
  6014. Delay_ms(500);
  6015. //存储异常并上传
  6016. FacMode_Stop(false);
  6017. //提示切换负载
  6018. MessageBox.Show("请将负载切换回电机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  6019. return;
  6020. }
  6021. }
  6022. else
  6023. {
  6024. label_FacModeMosCal.BackColor = Color.Yellow;
  6025. label_FacModeStatus.Text = "跳过MOS内阻校准!";
  6026. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准" + "\r\n");
  6027. Delay_ms(500);
  6028. }
  6029. //位置校准
  6030. if (checkBox_FacMode_AngleCal.Checked)
  6031. {
  6032. //校准前进行一次开关机保存初始化数据
  6033. BootInfo = "";
  6034. label_FacModeStatus.Text = "位置校准";
  6035. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始位置校准" + "\r\n");
  6036. //确保测试前先关机,发送关机指令再发送开机指令
  6037. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  6038. Code[0] = 0xF0;
  6039. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6040. Delay_ms(1500);
  6041. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  6042. Code[0] = 0xF1;
  6043. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  6044. ACK_WaitCnt = 0;
  6045. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  6046. while (ACK_WaitCnt <= 10) ; //5s
  6047. //获取Boot版本信息
  6048. if (BootInfo != string.Empty)
  6049. {
  6050. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机成功" + "\r\n");
  6051. Delay_ms(500);
  6052. }
  6053. else
  6054. {
  6055. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "重新开机失败" + "\r\n");
  6056. label_FacModeStatus.Text = "存在故障!";
  6057. label_FacModeResult.BackColor = Color.Red;
  6058. label_FacModeResult.Text = "测试异常";
  6059. Delay_ms(500);
  6060. //存储异常并上传
  6061. FacMode_Stop(false);
  6062. return;
  6063. }
  6064. //发送位置校准指令
  6065. for (int i = 0; i < 7; i++)
  6066. for (int j = 0; j < 6; j++)
  6067. {
  6068. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  6069. }
  6070. foreach (Control cr in tabPage_AngleCal.Controls)
  6071. {
  6072. if (cr is TextBox)
  6073. {
  6074. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  6075. cr.Text = "";
  6076. }
  6077. }
  6078. Code[0] = 0;
  6079. Code[1] = 0;
  6080. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Code);
  6081. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准中,请等待" + "\r\n");
  6082. ACK_WaitCnt = 0;
  6083. while (ACK_WaitCnt <= 50) ; //25s
  6084. //读取位置校准数据
  6085. if (textBox_AngleDiffAvg.Text == string.Empty)
  6086. {
  6087. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准失败" + "\r\n");
  6088. label_FacModeStatus.Text = "存在故障!";
  6089. label_FacModeResult.BackColor = Color.Red;
  6090. label_FacModeResult.Text = "测试异常";
  6091. Delay_ms(500);
  6092. //存储异常并上传
  6093. FacMode_Stop(false);
  6094. return;
  6095. }
  6096. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准数据:" + "\r\n");
  6097. for (int i = 0; i < 7; i++)
  6098. {
  6099. richTextBox_FacModeLog.AppendText("电周期" + (i + 1).ToString()+":");
  6100. for (int j = 0; j < 6; j++)
  6101. {
  6102. richTextBox_FacModeLog.AppendText(dataGridView_AngleCal.Rows[i].Cells[j + 1].Value.ToString() + ", ");
  6103. }
  6104. richTextBox_FacModeLog.AppendText("\r\n");
  6105. Delay_ms(200);
  6106. }
  6107. richTextBox_FacModeLog.AppendText("最小偏差:" + textBox_AngleDiffMin.Text+ ", " + "\r\n");
  6108. richTextBox_FacModeLog.AppendText("最大偏差:" + textBox_AngleDiffMax.Text + ", " + "\r\n");
  6109. richTextBox_FacModeLog.AppendText("平均偏差:" + textBox_AngleDiffAvg.Text + ", " + "\r\n");
  6110. richTextBox_FacModeLog.AppendText("历史零点:" + textBox_AngleZeroInit.Text + ", " + "\r\n");
  6111. richTextBox_FacModeLog.AppendText("当前零点:" + textBox_AngleZeroCur.Text + ", " + "\r\n");
  6112. richTextBox_FacModeLog.AppendText("零点偏差:" + textBox_AngleZeroDiff.Text + ", " + "\r\n");
  6113. //比较位置偏差
  6114. if ((Math.Abs(Convert.ToDouble(textBox_AngleDiffMin.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6115. (Math.Abs(Convert.ToDouble(textBox_AngleDiffMax.Text)) > Convert.ToDouble(textBox_AngleDiffTh.Text)) ||
  6116. (Math.Abs(Convert.ToDouble(textBox_AngleDiffAvg.Text)) > Convert.ToDouble(textBox_AngleZeroTh.Text))
  6117. )
  6118. {
  6119. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差过大,无法校准" + "\r\n");
  6120. label_FacModeStatus.Text = "存在故障!";
  6121. label_FacModeResult.BackColor = Color.Red;
  6122. label_FacModeResult.Text = "测试异常";
  6123. Delay_ms(500);
  6124. //存储异常并上传
  6125. FacMode_Stop(false);
  6126. return;
  6127. }
  6128. //写入校准偏差值
  6129. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差满足要求,写入校准数据" + "\r\n");
  6130. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  6131. if (data1 > 360)
  6132. {
  6133. data1 -= 360;
  6134. }
  6135. else if (data1 < -360)
  6136. {
  6137. data1 += 360;
  6138. }
  6139. Int16 data2 = (Int16)(data1 * 32768 / 360);
  6140. Code[0] = 0x01;
  6141. Code[1] = 0x00;
  6142. Code[2] = (byte)(data2);
  6143. Code[3] = (byte)(data2 >> 8);
  6144. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6145. WriteACK = false;
  6146. ACK_WaitCnt = 0;
  6147. while (ACK_WaitCnt <= 2) ; //1s
  6148. if (WriteACK == true)
  6149. {
  6150. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6151. }
  6152. else
  6153. {
  6154. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第1次重发" + "\r\n");
  6155. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6156. WriteACK = false;
  6157. ACK_WaitCnt = 0;
  6158. while (ACK_WaitCnt <= 2) ; //1s
  6159. if (WriteACK == true)
  6160. {
  6161. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6162. }
  6163. else
  6164. {
  6165. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入位置偏差,第2次重发" + "\r\n");
  6166. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, Code);
  6167. WriteACK = false;
  6168. ACK_WaitCnt = 0;
  6169. while (ACK_WaitCnt <= 2) ; //1s
  6170. if (WriteACK == true)
  6171. {
  6172. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入成功" + "\r\n");
  6173. }
  6174. else
  6175. {
  6176. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置偏差写入失败" + "\r\n");
  6177. label_FacModeStatus.Text = "存在故障!";
  6178. label_FacModeResult.BackColor = Color.Red;
  6179. label_FacModeResult.Text = "测试异常";
  6180. Delay_ms(500);
  6181. //存储异常并上传
  6182. FacMode_Stop(false);
  6183. return;
  6184. }
  6185. }
  6186. }
  6187. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "位置校准正常,位置偏差值:" + textBox_AngleDiffAvg.Text + "\r\n");
  6188. label_FacModeAngleCal.BackColor = Color.Green;
  6189. }
  6190. else
  6191. {
  6192. label_FacModeAngleCal.BackColor = Color.Yellow;
  6193. label_FacModeStatus.Text = "跳过位置校准!";
  6194. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过位置校准" + "\r\n");
  6195. Delay_ms(500);
  6196. }
  6197. //参数写入
  6198. if (checkBox_FacModeCfgWrite.Checked)
  6199. {
  6200. label_FacModeStatus.Text = "参数写入";
  6201. //写入产品型号和SN
  6202. do
  6203. {
  6204. //根据扫码信息获取型号和SN
  6205. string ScanInfo = textBox_FacModeScan.Text;
  6206. string regexInfo = "";
  6207. string[] InfoList = { "" };
  6208. try
  6209. {
  6210. if (中置电机ToolStripMenuItem.Checked == true)
  6211. {
  6212. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  6213. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  6214. }
  6215. else if (轮毂电机ToolStripMenuItem.Checked == true)
  6216. {
  6217. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  6218. string Model = InfoList[0];
  6219. string Spec = InfoList[1];
  6220. string Sn = InfoList[2];
  6221. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  6222. InfoList[1] = Sn;
  6223. }
  6224. }
  6225. catch
  6226. {
  6227. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  6228. label_FacModeStatus.Text = "存在故障!";
  6229. label_FacModeResult.BackColor = Color.Red;
  6230. label_FacModeResult.Text = "标签格式错误";
  6231. Delay_ms(500);
  6232. //存储异常并上传
  6233. FacMode_Stop(false);
  6234. return;
  6235. }
  6236. if (InfoList.Length >= 2)
  6237. {
  6238. //检查配置文件是否与打标信息一致
  6239. //...
  6240. //写入型号
  6241. label_FacModeStatus.Text = "写入型号";
  6242. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
  6243. textBox_FacModeName.Text = InfoList[0];
  6244. string Mode = textBox_FacModeName.Text;
  6245. var ModeArray = new byte[16];
  6246. for (ushort i = 0; i < Mode.Length; i++)
  6247. {
  6248. ModeArray[i] = (byte)Mode[i];
  6249. }
  6250. if (Mode.Length < 16)
  6251. {
  6252. ModeArray[Mode.Length] = (byte)'.';
  6253. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  6254. {
  6255. ModeArray[Mode.Length + 1 + i] = 0x20;
  6256. }
  6257. }
  6258. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6259. WriteACK = false;
  6260. WriteCnt = 0;
  6261. ACK_WaitCnt = 0;
  6262. while (ACK_WaitCnt <= 2); //1s
  6263. if (WriteACK == true)
  6264. {
  6265. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6266. }
  6267. else
  6268. {
  6269. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第1次重发" + "\r\n");
  6270. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6271. ACK_WaitCnt = 0;
  6272. while (ACK_WaitCnt <= 2) ; //1s
  6273. if (WriteACK == true)
  6274. {
  6275. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6276. }
  6277. else
  6278. {
  6279. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号,第2次重发" + "\r\n");
  6280. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  6281. ACK_WaitCnt = 0;
  6282. while (ACK_WaitCnt <= 2) ; //1s
  6283. if (WriteACK == true)
  6284. {
  6285. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
  6286. }
  6287. else
  6288. {
  6289. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入失败" + "\r\n");
  6290. label_FacModeStatus.Text = "存在故障!";
  6291. label_FacModeResult.BackColor = Color.Red;
  6292. label_FacModeResult.Text = "测试异常";
  6293. Delay_ms(500);
  6294. //存储异常并上传
  6295. FacMode_Stop(false);
  6296. return;
  6297. }
  6298. }
  6299. }
  6300. //写入SN
  6301. label_FacModeStatus.Text = "写入SN";
  6302. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
  6303. textBox_FacModeNum.Text = InfoList[1];
  6304. string SN = textBox_FacModeNum.Text;
  6305. var SNArray = new byte[16];
  6306. for (ushort i = 0; i < SN.Length; i++)
  6307. {
  6308. SNArray[i] = (byte)SN[i];
  6309. }
  6310. if (SN.Length < 16)
  6311. {
  6312. SNArray[SN.Length] = (byte)'.';
  6313. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  6314. {
  6315. SNArray[SN.Length + 1 + i] = 0x20;
  6316. }
  6317. }
  6318. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6319. WriteACK = false;
  6320. WriteCnt = 0;
  6321. ACK_WaitCnt = 0;
  6322. while (ACK_WaitCnt <= 2); //1s
  6323. if (WriteACK == true)
  6324. {
  6325. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6326. }
  6327. else
  6328. {
  6329. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第1次重发" + "\r\n");
  6330. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6331. ACK_WaitCnt = 0;
  6332. while (ACK_WaitCnt <= 2) ; //1s
  6333. if (WriteACK == true)
  6334. {
  6335. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6336. }
  6337. else
  6338. {
  6339. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN,第2次重发" + "\r\n");
  6340. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  6341. ACK_WaitCnt = 0;
  6342. while (ACK_WaitCnt <= 2) ; //1s
  6343. if (WriteACK == true)
  6344. {
  6345. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
  6346. }
  6347. else
  6348. {
  6349. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入失败" + "\r\n");
  6350. label_FacModeStatus.Text = "存在故障!";
  6351. label_FacModeResult.BackColor = Color.Red;
  6352. label_FacModeResult.Text = "测试异常";
  6353. Delay_ms(500);
  6354. //存储异常并上传
  6355. FacMode_Stop(false);
  6356. return;
  6357. }
  6358. }
  6359. }
  6360. }
  6361. else
  6362. {
  6363. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  6364. return;
  6365. }
  6366. } while (false);
  6367. //写入配置文件
  6368. do
  6369. {
  6370. label_FacModeStatus.Text = "写入配置文件";
  6371. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  6372. //配置文件
  6373. List<byte[]> CmdList = new List<byte[]>();
  6374. //从服务器下载文件
  6375. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  6376. {
  6377. string SelectFile = "";
  6378. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "/" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6379. if (File.Exists(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  6380. {
  6381. File.Delete(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6382. }
  6383. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  6384. //打开文件
  6385. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_FacModeCfgFile.SelectedItem.ToString());
  6386. CmdList.Clear();
  6387. while (streamReader.Peek() != -1)
  6388. {
  6389. string fileLineInfo = streamReader.ReadLine();
  6390. if (fileLineInfo.IndexOf("[") != -1)
  6391. {
  6392. continue;
  6393. }
  6394. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6395. }
  6396. streamReader.Close();
  6397. }
  6398. //加载本地文件
  6399. else
  6400. {
  6401. string SelectFile = "";
  6402. SelectFile = comboBox_FacModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_FacModeCfgFile.SelectedItem.ToString();
  6403. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  6404. CmdList.Clear();
  6405. while (streamReader.Peek() != -1)
  6406. {
  6407. string fileLineInfo = streamReader.ReadLine();
  6408. if (fileLineInfo.IndexOf("[") != -1)
  6409. {
  6410. continue;
  6411. }
  6412. CmdList.Add(mySerialProcess.HexStringToBytes(fileLineInfo, true));
  6413. }
  6414. streamReader.Close();
  6415. }
  6416. int CmdNum = CmdList.Count(); //指令个数
  6417. Delay_ms(500);
  6418. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "开始写入" + "\r\n");
  6419. Delay_ms(500);
  6420. //开始写入
  6421. WriteCnt = 0;
  6422. for (int i = 0; i < CmdList.Count; i++)
  6423. {
  6424. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令" + "\r\n");
  6425. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6426. WriteACK = false;
  6427. ACK_WaitCnt = 0;
  6428. while (ACK_WaitCnt <= 2) ; //1s
  6429. if (WriteACK == true)
  6430. {
  6431. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6432. }
  6433. else
  6434. {
  6435. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第1次重发" + "\r\n");
  6436. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6437. WriteACK = false;
  6438. ACK_WaitCnt = 0;
  6439. while (ACK_WaitCnt <= 2) ; //1s
  6440. if (WriteACK == true)
  6441. {
  6442. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6443. }
  6444. else
  6445. {
  6446. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入第" + (i + 1).ToString() + "条指令,第2次重发" + "\r\n");
  6447. mySerialProcess.mySerial.Write(CmdList[i], 0, CmdList[i].Length);
  6448. WriteACK = false;
  6449. ACK_WaitCnt = 0;
  6450. while (ACK_WaitCnt <= 2) ; //1s
  6451. if (WriteACK == true)
  6452. {
  6453. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "第" + (i + 1).ToString() + "条指令写入正常" + "\r\n");
  6454. }
  6455. else
  6456. {
  6457. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入失败," + "共" + CmdNum.ToString() + "条指令," + "写入成功" + i.ToString() + "条" + "\r\n");
  6458. label_FacModeStatus.Text = "存在故障!";
  6459. label_FacModeResult.BackColor = Color.Red;
  6460. label_FacModeResult.Text = "测试异常";
  6461. Delay_ms(500);
  6462. //存储异常并上传
  6463. FacMode_Stop(false);
  6464. return;
  6465. }
  6466. }
  6467. }
  6468. }
  6469. //写入完成
  6470. label_FacMode_CfgWrite.BackColor = Color.Green;
  6471. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数写入成功" + "\r\n");
  6472. Delay_ms(500);
  6473. } while (false);
  6474. }
  6475. else
  6476. {
  6477. label_FacMode_CfgWrite.BackColor = Color.Yellow;
  6478. label_FacModeStatus.Text = "跳过参数写入!";
  6479. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数写入" + "\r\n");
  6480. Delay_ms(500);
  6481. }
  6482. //BMS通讯
  6483. if (checkBox_FacModeBMS.Checked)
  6484. {
  6485. if (label_FacModeBMS.BackColor == Color.Red)
  6486. {
  6487. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "BMS通讯异常" + "\r\n");
  6488. label_FacModeStatus.Text = "存在故障!";
  6489. label_FacModeResult.BackColor = Color.Red;
  6490. label_FacModeResult.Text = "测试异常";
  6491. Delay_ms(500);
  6492. //存储异常并上传
  6493. FacMode_Stop(false);
  6494. return;
  6495. }
  6496. }
  6497. else
  6498. {
  6499. label_FacModeBMS.BackColor = Color.Yellow;
  6500. label_FacModeStatus.Text = "跳过BMS通讯检测!";
  6501. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过BMS通讯检测" + "\r\n");
  6502. Delay_ms(500);
  6503. }
  6504. //基础功能检测
  6505. if (checkBox_FacBaseFucTest.Checked)
  6506. {
  6507. label_FacModeStatus.Text = "基础功能检测";
  6508. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始基础功能检测" + "\r\n");
  6509. //确认负载位置
  6510. if (checkBox_FacMode_MosCal.Checked)
  6511. {
  6512. if (MessageBox.Show("请再次确认负载是否切换回电机?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  6513. {
  6514. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "负载已切换为电机,继续测试" + "\r\n");
  6515. }
  6516. else
  6517. {
  6518. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试取消" + "\r\n");
  6519. label_FacModeStatus.Text = "存在故障!";
  6520. label_FacModeResult.BackColor = Color.Red;
  6521. label_FacModeResult.Text = "测试异常";
  6522. Delay_ms(500);
  6523. //存储异常并上传
  6524. FacMode_Stop(false);
  6525. return;
  6526. }
  6527. }
  6528. //发送指令进入配置模式
  6529. do
  6530. {
  6531. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6532. Code[0] = 0x01;
  6533. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6534. WriteACK = false;
  6535. WriteCnt = 0;
  6536. ACK_WaitCnt = 0;
  6537. while (ACK_WaitCnt <= 2); //1s
  6538. if (textBox_RunInfo_Vol.Text != "---")
  6539. {
  6540. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6541. }
  6542. else
  6543. {
  6544. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6545. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6546. ACK_WaitCnt = 0;
  6547. while (ACK_WaitCnt <= 2) ; //1s
  6548. if (textBox_RunInfo_Vol.Text != "---")
  6549. {
  6550. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6551. }
  6552. else
  6553. {
  6554. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6555. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6556. ACK_WaitCnt = 0;
  6557. while (ACK_WaitCnt <= 2) ; //1s
  6558. if (textBox_RunInfo_Vol.Text != "---")
  6559. {
  6560. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6561. }
  6562. else
  6563. {
  6564. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6565. label_FacModeStatus.Text = "存在故障!";
  6566. label_FacModeResult.BackColor = Color.Red;
  6567. label_FacModeResult.Text = "测试异常";
  6568. Delay_ms(500);
  6569. //存储异常并上传
  6570. FacMode_Stop(false);
  6571. return;
  6572. }
  6573. }
  6574. }
  6575. } while (false);
  6576. //发送指令启动电机
  6577. do
  6578. {
  6579. #if false //通过运行模式3启动电机
  6580. //发送指令读取调试信息
  6581. richTextBox_DebugParam.Clear();
  6582. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  6583. WriteACK = false;
  6584. WriteCnt = 0;
  6585. ACK_WaitCnt = 0;
  6586. while (ACK_WaitCnt <= 2); //1s
  6587. //获取调试信息
  6588. string DebugDefaultInfo = "";
  6589. if (richTextBox_DebugParam.Text == string.Empty)
  6590. {
  6591. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6592. label_FacModeStatus.Text = "存在故障!";
  6593. label_FacModeResult.BackColor = Color.Red;
  6594. label_FacModeResult.Text = "测试异常";
  6595. Delay_ms(500);
  6596. //存储异常并上传
  6597. FacMode_Stop(false);
  6598. return;
  6599. }
  6600. else
  6601. {
  6602. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6603. }
  6604. //设置模式
  6605. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6606. strDataTemp[0] = "整体运行模式=3";
  6607. //发送数据
  6608. Code[0] = 0;
  6609. Code[1] = 0;
  6610. for (int i = 0; i < strDataTemp.Length; i++)
  6611. {
  6612. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6613. Code[2 * i + 2] = (byte)uwDataTemp;
  6614. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6615. }
  6616. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6617. label_FacModeStatus.Text = "启动电机";
  6618. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
  6619. #else //通过Walk模式启动电机
  6620. //设置转速100%
  6621. var Data = new byte[1];
  6622. Data[0] = (byte)100;
  6623. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6624. Delay_ms(500);
  6625. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6626. Delay_ms(500);
  6627. //启动电机进入WALK模式
  6628. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "基础功能检测,进入WALK" + "\r\n");
  6629. Code[0] = 0x22;
  6630. Code[1] = 0xF0;
  6631. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6632. WriteACK = false;
  6633. WriteCnt = 0;
  6634. ACK_WaitCnt = 0;
  6635. while (ACK_WaitCnt <= 2) ; //1s
  6636. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6637. {
  6638. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  6639. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6640. ACK_WaitCnt = 0;
  6641. while (ACK_WaitCnt <= 2) ; //1s
  6642. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6643. {
  6644. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  6645. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6646. ACK_WaitCnt = 0;
  6647. while (ACK_WaitCnt <= 2) ; //1s
  6648. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  6649. {
  6650. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  6651. label_FacModeStatus.Text = "存在故障!";
  6652. label_FacModeResult.BackColor = Color.Red;
  6653. label_FacModeResult.Text = "测试异常";
  6654. Delay_ms(500);
  6655. //存储异常并上传
  6656. FacMode_Stop(false);
  6657. return;
  6658. }
  6659. }
  6660. }
  6661. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入WALK,开始检测" + "\r\n");
  6662. #endif
  6663. Delay_ms(3000);
  6664. } while (false);
  6665. //判断车速
  6666. if ((Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) <= Convert.ToDouble( toolStripTextBox_ThBikeSpeed.Text.Split(',')[1])) &&
  6667. (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThBikeSpeed.Text.Split(',')[0])))
  6668. {
  6669. label_FacModeSpeed.BackColor = Color.Green;
  6670. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6671. }
  6672. else
  6673. {
  6674. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器异常" + " " + textBox_RunInfo_BikeSpeed.Text + "\r\n");
  6675. label_FacModeStatus.Text = "存在故障!";
  6676. label_FacModeResult.BackColor = Color.Red;
  6677. label_FacModeResult.Text = "测试异常";
  6678. Delay_ms(500);
  6679. //存储异常并上传
  6680. FacMode_Stop(false);
  6681. return;
  6682. }
  6683. //判断电压
  6684. if ((Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[1])) &&
  6685. (Convert.ToDouble(textBox_RunInfo_Vol.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThVol.Text.Split(',')[0])))
  6686. {
  6687. label_FacModeVolTest.BackColor = Color.Green;
  6688. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量正常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6689. }
  6690. else
  6691. {
  6692. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压测量异常" + " " + textBox_RunInfo_Vol.Text + "\r\n");
  6693. label_FacModeStatus.Text = "存在故障!";
  6694. label_FacModeResult.BackColor = Color.Red;
  6695. label_FacModeResult.Text = "测试异常";
  6696. Delay_ms(500);
  6697. //存储异常并上传
  6698. FacMode_Stop(false);
  6699. return;
  6700. }
  6701. //判断电流
  6702. if ((Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[1])) &&
  6703. (Convert.ToDouble(textBox_RunInfo_Current.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThCur.Text.Split(',')[0])))
  6704. {
  6705. label_FacModeCurrentTest.BackColor = Color.Green;
  6706. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量正常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6707. }
  6708. else
  6709. {
  6710. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电流测量异常" + " " + textBox_RunInfo_Current.Text + "\r\n");
  6711. label_FacModeStatus.Text = "存在故障!";
  6712. label_FacModeResult.BackColor = Color.Red;
  6713. label_FacModeResult.Text = "测试异常";
  6714. Delay_ms(500);
  6715. //存储异常并上传
  6716. FacMode_Stop(false);
  6717. return;
  6718. }
  6719. //判断温度
  6720. if ((Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[1])) &&
  6721. (Convert.ToDouble(textBox_RunInfo_T_PCB.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_PCB.Text.Split(',')[0])) &&
  6722. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[1])) &&
  6723. (Convert.ToDouble(textBox_RunInfo_T_MCU.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_MCU.Text.Split(',')[0])) &&
  6724. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[1])) &&
  6725. (Convert.ToDouble(textBox_RunInfo_T_Coil.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThT_Motor.Text.Split(',')[0])))
  6726. {
  6727. label_FacModeNTC.BackColor = Color.Green;
  6728. 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");
  6729. }
  6730. else
  6731. {
  6732. 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");
  6733. label_FacModeStatus.Text = "存在故障!";
  6734. label_FacModeResult.BackColor = Color.Red;
  6735. label_FacModeResult.Text = "测试异常";
  6736. Delay_ms(500);
  6737. //存储异常并上传
  6738. FacMode_Stop(false);
  6739. return;
  6740. }
  6741. //判断转速
  6742. if ((Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) <= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[1])) &&
  6743. (Convert.ToDouble(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) >= Convert.ToDouble(toolStripTextBox_ThSpeed.Text.Split(',')[0])))
  6744. {
  6745. label_FacModeMotorSpeed.BackColor = Color.Green;
  6746. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速正常" + " " + textBox_RunInfo_MotorSpeed.Text + "\r\n");
  6747. }
  6748. else
  6749. {
  6750. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机转速异常" + " " + textBox_RunInfo_MotorSpeed.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. do
  6761. {
  6762. //设置转速0%
  6763. var Data = new byte[1];
  6764. Data[0] = (byte)0;
  6765. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6766. Delay_ms(500);
  6767. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  6768. Delay_ms(500);
  6769. #if false //通过修改调试模式停止电机
  6770. //获取调试信息
  6771. string DebugDefaultInfo = "";
  6772. if (richTextBox_DebugParam.Text == string.Empty)
  6773. {
  6774. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "获取调试信息异常" + "\r\n");
  6775. label_FacModeStatus.Text = "存在故障!";
  6776. label_FacModeResult.BackColor = Color.Red;
  6777. label_FacModeResult.Text = "测试异常";
  6778. Delay_ms(500);
  6779. //存储异常并上传
  6780. FacMode_Stop(false);
  6781. return;
  6782. }
  6783. else
  6784. {
  6785. DebugDefaultInfo = richTextBox_DebugParam.Text;
  6786. }
  6787. //设置模式
  6788. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  6789. //发送数据
  6790. Code[0] = 0;
  6791. Code[1] = 0;
  6792. for (int i = 0; i < strDataTemp.Length; i++)
  6793. {
  6794. ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  6795. Code[2 * i + 2] = (byte)uwDataTemp;
  6796. Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
  6797. }
  6798. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
  6799. label_FacModeStatus.Text = "停止电机";
  6800. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
  6801. #else //通过调整档位停止电机
  6802. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK" + "\r\n");
  6803. Code[0] = 0x00;
  6804. Code[1] = 0xF0;
  6805. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6806. WriteACK = false;
  6807. WriteCnt = 0;
  6808. ACK_WaitCnt = 0;
  6809. while (ACK_WaitCnt <= 2) ; //1s
  6810. if (textBox_RunInfo_GearSt.Text != "OFF")
  6811. {
  6812. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第1次重发" + "\r\n");
  6813. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6814. ACK_WaitCnt = 0;
  6815. while (ACK_WaitCnt <= 2) ; //1s
  6816. if (textBox_RunInfo_GearSt.Text != "OFF")
  6817. {
  6818. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令退出WALK,第2次重发" + "\r\n");
  6819. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  6820. ACK_WaitCnt = 0;
  6821. while (ACK_WaitCnt <= 2) ; //1s
  6822. if (textBox_RunInfo_GearSt.Text != "OFF")
  6823. {
  6824. }
  6825. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  6826. label_FacModeStatus.Text = "存在故障!";
  6827. label_FacModeResult.BackColor = Color.Red;
  6828. label_FacModeResult.Text = "测试异常";
  6829. Delay_ms(500);
  6830. //存储异常并上传
  6831. FacMode_Stop(false);
  6832. return;
  6833. }
  6834. }
  6835. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已退出WALK,基础功能检测完成" + "\r\n");
  6836. #endif
  6837. Delay_ms(2000);
  6838. } while (false);
  6839. }
  6840. else
  6841. {
  6842. label_FacModeSpeed.BackColor = Color.Yellow;
  6843. label_FacModeVolTest.BackColor = Color.Yellow;
  6844. label_FacModeCurrentTest.BackColor = Color.Yellow;
  6845. label_FacModeNTC.BackColor = Color.Yellow;
  6846. label_FacModeMotorSpeed.BackColor = Color.Yellow;
  6847. label_FacModeStatus.Text = "跳过基础功能检测!";
  6848. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过基础功能检测" + "\r\n");
  6849. Delay_ms(500);
  6850. }
  6851. //力矩检测
  6852. if (checkBox_FacTor.Checked)
  6853. {
  6854. label_FacModeStatus.Text = "力矩传感器检测!";
  6855. //发送指令进入配置模式
  6856. do
  6857. {
  6858. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6859. {
  6860. break;
  6861. }
  6862. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6863. Code[0] = 0x01;
  6864. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6865. WriteACK = false;
  6866. WriteCnt = 0;
  6867. ACK_WaitCnt = 0;
  6868. while (ACK_WaitCnt <= 2) ; //1s
  6869. if (textBox_RunInfo_Vol.Text != "---")
  6870. {
  6871. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6872. Delay_ms(500);
  6873. }
  6874. else
  6875. {
  6876. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6877. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6878. ACK_WaitCnt = 0;
  6879. while (ACK_WaitCnt <= 2) ; //1s
  6880. if (textBox_RunInfo_Vol.Text != "---")
  6881. {
  6882. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6883. Delay_ms(500);
  6884. }
  6885. else
  6886. {
  6887. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6888. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6889. ACK_WaitCnt = 0;
  6890. while (ACK_WaitCnt <= 2) ; //1s
  6891. if (textBox_RunInfo_Vol.Text != "---")
  6892. {
  6893. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6894. Delay_ms(500);
  6895. }
  6896. else
  6897. {
  6898. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6899. label_FacModeStatus.Text = "存在故障!";
  6900. label_FacModeResult.BackColor = Color.Red;
  6901. label_FacModeResult.Text = "测试异常";
  6902. Delay_ms(500);
  6903. //存储异常并上传
  6904. FacMode_Stop(false);
  6905. return;
  6906. }
  6907. }
  6908. }
  6909. } while (false);
  6910. ushort Max = 0, Torque = 0;
  6911. //提示输入力矩信号
  6912. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟力矩信号输入" + "\r\n");
  6913. ACK_WaitCnt = 0;
  6914. while (ACK_WaitCnt <= 20) //10s
  6915. {
  6916. //获取力矩值
  6917. Torque = (ushort)Convert.ToInt16(textBox_RunInfo_Torque.Text.Split(' ')[0]);
  6918. if (Torque > Max)
  6919. Max = Torque;
  6920. if ((Max <= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[1])) &&
  6921. (Max >= Convert.ToDouble(toolStripTextBox_ThTor.Text.Split(',')[0])) &&
  6922. (ACK_WaitCnt >= 6))
  6923. {
  6924. label_FacModeTq.BackColor = Color.Green;
  6925. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器正常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6926. break;
  6927. }
  6928. }
  6929. if (ACK_WaitCnt >= 20)
  6930. {
  6931. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器异常" + " " + textBox_RunInfo_Torque.Text + "\r\n");
  6932. label_FacModeStatus.Text = "存在故障!";
  6933. label_FacModeResult.BackColor = Color.Red;
  6934. label_FacModeResult.Text = "测试异常";
  6935. Delay_ms(500);
  6936. //存储异常并上传
  6937. FacMode_Stop(false);
  6938. return;
  6939. }
  6940. }
  6941. else
  6942. {
  6943. label_FacModeTq.BackColor = Color.Yellow;
  6944. label_FacModeStatus.Text = "跳过力矩检测!";
  6945. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过力矩检测" + "\r\n");
  6946. Delay_ms(500);
  6947. }
  6948. //踏频检测
  6949. if (checkBox_FacCad.Checked)
  6950. {
  6951. label_FacModeStatus.Text = "踏频传感器检测!";
  6952. //发送指令进入配置模式
  6953. do
  6954. {
  6955. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  6956. {
  6957. break;
  6958. }
  6959. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  6960. Code[0] = 0x01;
  6961. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6962. WriteACK = false;
  6963. WriteCnt = 0;
  6964. ACK_WaitCnt = 0;
  6965. while (ACK_WaitCnt <= 2) ; //1s
  6966. if (textBox_RunInfo_Vol.Text != "---")
  6967. {
  6968. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6969. Delay_ms(500);
  6970. }
  6971. else
  6972. {
  6973. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  6974. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6975. ACK_WaitCnt = 0;
  6976. while (ACK_WaitCnt <= 2) ; //1s
  6977. if (textBox_RunInfo_Vol.Text != "---")
  6978. {
  6979. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6980. Delay_ms(500);
  6981. }
  6982. else
  6983. {
  6984. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  6985. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  6986. ACK_WaitCnt = 0;
  6987. while (ACK_WaitCnt <= 2) ; //1s
  6988. if (textBox_RunInfo_Vol.Text != "---")
  6989. {
  6990. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  6991. Delay_ms(500);
  6992. }
  6993. else
  6994. {
  6995. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  6996. label_FacModeStatus.Text = "存在故障!";
  6997. label_FacModeResult.BackColor = Color.Red;
  6998. label_FacModeResult.Text = "测试异常";
  6999. Delay_ms(500);
  7000. //存储异常并上传
  7001. FacMode_Stop(false);
  7002. return;
  7003. }
  7004. }
  7005. }
  7006. } while (false);
  7007. ushort Max = 0, Cadence = 0;
  7008. //提示输入踏频信号
  7009. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "10s内模拟踏频信号输入" + "\r\n");
  7010. ACK_WaitCnt = 0;
  7011. while (ACK_WaitCnt <= 20) //10s
  7012. {
  7013. //获取踏频
  7014. Cadence = (ushort)Convert.ToInt16(textBox_RunInfo_Cadence.Text.Split(' ')[0]);
  7015. if (Cadence > Max)
  7016. Max = Cadence;
  7017. if ((Max <= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[1])) &&
  7018. (Max >= Convert.ToDouble(toolStripTextBox_ThCad.Text.Split(',')[0])) &&
  7019. (ACK_WaitCnt >= 6))
  7020. {
  7021. label_FacModeCad.BackColor = Color.Green;
  7022. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器正常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7023. break;
  7024. }
  7025. }
  7026. if (ACK_WaitCnt >= 20)
  7027. {
  7028. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "踏频传感器异常" + " " + textBox_RunInfo_Cadence.Text + "\r\n");
  7029. label_FacModeStatus.Text = "存在故障!";
  7030. label_FacModeResult.BackColor = Color.Red;
  7031. label_FacModeResult.Text = "测试异常";
  7032. Delay_ms(500);
  7033. //存储异常并上传
  7034. FacMode_Stop(false);
  7035. return;
  7036. }
  7037. }
  7038. else
  7039. {
  7040. label_FacModeCad.BackColor = Color.Yellow;
  7041. label_FacModeStatus.Text = "跳过踏频检测!";
  7042. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过踏频检测" + "\r\n");
  7043. Delay_ms(500);
  7044. }
  7045. //转把检测
  7046. if (checkBox_FacThrrotleTest.Checked)
  7047. {
  7048. label_FacModeStatus.Text = "转把检测";
  7049. //发送指令进入配置模式
  7050. do
  7051. {
  7052. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7053. {
  7054. break;
  7055. }
  7056. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7057. Code[0] = 0x01;
  7058. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7059. WriteACK = false;
  7060. WriteCnt = 0;
  7061. ACK_WaitCnt = 0;
  7062. while (ACK_WaitCnt <= 2) ; //1s
  7063. if (textBox_RunInfo_Vol.Text != "---")
  7064. {
  7065. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7066. Delay_ms(500);
  7067. }
  7068. else
  7069. {
  7070. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7071. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7072. ACK_WaitCnt = 0;
  7073. while (ACK_WaitCnt <= 2) ; //1s
  7074. if (textBox_RunInfo_Vol.Text != "---")
  7075. {
  7076. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7077. Delay_ms(500);
  7078. }
  7079. else
  7080. {
  7081. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7082. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7083. ACK_WaitCnt = 0;
  7084. while (ACK_WaitCnt <= 2) ; //1s
  7085. if (textBox_RunInfo_Vol.Text != "---")
  7086. {
  7087. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7088. Delay_ms(500);
  7089. }
  7090. else
  7091. {
  7092. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7093. label_FacModeStatus.Text = "存在故障!";
  7094. label_FacModeResult.BackColor = Color.Red;
  7095. label_FacModeResult.Text = "测试异常";
  7096. Delay_ms(500);
  7097. //存储异常并上传
  7098. FacMode_Stop(false);
  7099. return;
  7100. }
  7101. }
  7102. }
  7103. } while (false);
  7104. //进入TURBO档
  7105. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把检测,发送指令进入TURBO" + "\r\n");
  7106. Code[0] = 0x04;
  7107. Code[1] = 0xF0;
  7108. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7109. WriteACK = false;
  7110. WriteCnt = 0;
  7111. ACK_WaitCnt = 0;
  7112. while (ACK_WaitCnt <= 2) ; //1s
  7113. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7114. {
  7115. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第1次重发" + "\r\n");
  7116. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7117. ACK_WaitCnt = 0;
  7118. while (ACK_WaitCnt <= 2) ; //1s
  7119. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7120. {
  7121. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO,第2次重发" + "\r\n");
  7122. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7123. ACK_WaitCnt = 0;
  7124. while (ACK_WaitCnt <= 2) ; //1s
  7125. if (textBox_RunInfo_GearSt.Text != "TURBO")
  7126. {
  7127. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入TURBO异常" + "\r\n");
  7128. label_FacModeStatus.Text = "存在故障!";
  7129. label_FacModeResult.BackColor = Color.Red;
  7130. label_FacModeResult.Text = "测试异常";
  7131. Delay_ms(500);
  7132. //存储异常并上传
  7133. FacMode_Stop(false);
  7134. return;
  7135. }
  7136. }
  7137. }
  7138. //进入TURBO后,如果电机直接启动,认为转把电压异常
  7139. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检,请等待" + "\r\n");
  7140. Delay_ms(2000);
  7141. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500)
  7142. {
  7143. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把电压异常" + "\r\n");
  7144. label_FacModeStatus.Text = "存在故障!";
  7145. label_FacModeResult.BackColor = Color.Red;
  7146. label_FacModeResult.Text = "测试异常";
  7147. Delay_ms(500);
  7148. //存储异常并上传
  7149. FacMode_Stop(false);
  7150. return;
  7151. }
  7152. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把自检正常" + "\r\n");
  7153. Delay_ms(500);
  7154. //提示转动转把
  7155. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入TURBO,10s内转动转把" + "\r\n");
  7156. ACK_WaitCnt = 0;
  7157. while (ACK_WaitCnt <= 20)
  7158. {
  7159. if ((Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) > 500) && (ACK_WaitCnt >= 10))
  7160. {
  7161. label_FacModeGas.BackColor = Color.Green;
  7162. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能正常,松开转把" + "\r\n");
  7163. break;
  7164. }
  7165. }
  7166. if (ACK_WaitCnt >= 20) //转把超时
  7167. {
  7168. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "转把功能异常,松开转把" + "\r\n");
  7169. label_FacModeStatus.Text = "存在故障!";
  7170. label_FacModeResult.BackColor = Color.Red;
  7171. label_FacModeResult.Text = "测试异常";
  7172. Delay_ms(500);
  7173. //存储异常并上传
  7174. FacMode_Stop(false);
  7175. return;
  7176. }
  7177. }
  7178. else
  7179. {
  7180. label_FacModeGas.BackColor = Color.Yellow;
  7181. label_FacModeStatus.Text = "跳过转把检测!";
  7182. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
  7183. Delay_ms(500);
  7184. }
  7185. //刹车检测
  7186. if (checkBox_FacBreakTest.Checked)
  7187. {
  7188. label_FacModeStatus.Text = "刹把检测";
  7189. //发送指令进入配置模式
  7190. do
  7191. {
  7192. if (textBox_RunInfo_Vol.Text != "---") //已进入配置模式,不重新发送
  7193. {
  7194. break;
  7195. }
  7196. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
  7197. Code[0] = 0x01;
  7198. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7199. WriteACK = false;
  7200. WriteCnt = 0;
  7201. ACK_WaitCnt = 0;
  7202. while (ACK_WaitCnt <= 2) ; //1s
  7203. if (textBox_RunInfo_Vol.Text != "---")
  7204. {
  7205. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7206. Delay_ms(500);
  7207. }
  7208. else
  7209. {
  7210. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第1次重发" + "\r\n");
  7211. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7212. ACK_WaitCnt = 0;
  7213. while (ACK_WaitCnt <= 2) ; //1s
  7214. if (textBox_RunInfo_Vol.Text != "---")
  7215. {
  7216. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7217. Delay_ms(500);
  7218. }
  7219. else
  7220. {
  7221. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式,第2次重发" + "\r\n");
  7222. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  7223. ACK_WaitCnt = 0;
  7224. while (ACK_WaitCnt <= 2) ; //1s
  7225. if (textBox_RunInfo_Vol.Text != "---")
  7226. {
  7227. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已进入配置模式" + "\r\n");
  7228. Delay_ms(500);
  7229. }
  7230. else
  7231. {
  7232. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式异常" + "\r\n");
  7233. label_FacModeStatus.Text = "存在故障!";
  7234. label_FacModeResult.BackColor = Color.Red;
  7235. label_FacModeResult.Text = "测试异常";
  7236. Delay_ms(500);
  7237. //存储异常并上传
  7238. FacMode_Stop(false);
  7239. return;
  7240. }
  7241. }
  7242. }
  7243. } while (false);
  7244. //设置转速100%
  7245. var Data = new byte[1];
  7246. Data[0] = (byte)100;
  7247. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7248. Delay_ms(500);
  7249. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  7250. Delay_ms(500);
  7251. //启动电机进入WALK模式
  7252. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把检测,进入WALK" + "\r\n");
  7253. Code[0] = 0x22;
  7254. Code[1] = 0xF0;
  7255. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7256. WriteACK = false;
  7257. WriteCnt = 0;
  7258. ACK_WaitCnt = 0;
  7259. while (ACK_WaitCnt <= 2) ; //1s
  7260. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7261. {
  7262. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第1次重发" + "\r\n");
  7263. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7264. ACK_WaitCnt = 0;
  7265. while (ACK_WaitCnt <= 2) ; //1s
  7266. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7267. {
  7268. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,第2次重发" + "\r\n");
  7269. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7270. ACK_WaitCnt = 0;
  7271. while (ACK_WaitCnt <= 2) ; //1s
  7272. if ((textBox_RunInfo_GearSt.Text != "WALK") || (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 200))
  7273. {
  7274. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK异常" + "\r\n");
  7275. label_FacModeStatus.Text = "存在故障!";
  7276. label_FacModeResult.BackColor = Color.Red;
  7277. label_FacModeResult.Text = "测试异常";
  7278. Delay_ms(500);
  7279. //存储异常并上传
  7280. FacMode_Stop(false);
  7281. return;
  7282. }
  7283. }
  7284. }
  7285. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入WALK,10s内操作剎把" + "\r\n");
  7286. ACK_WaitCnt = 0;
  7287. while (ACK_WaitCnt <= 20)
  7288. {
  7289. if (Convert.ToInt32(textBox_RunInfo_MotorSpeed.Text.Split(' ')[0]) < 100)
  7290. {
  7291. label_FacModeBreak.BackColor = Color.Green;
  7292. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能正常,松开剎把" + "\r\n");
  7293. break;
  7294. }
  7295. }
  7296. if (ACK_WaitCnt >= 20) //剎把超时
  7297. {
  7298. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "剎把功能异常,松开剎把" + "\r\n");
  7299. label_FacModeStatus.Text = "存在故障!";
  7300. label_FacModeResult.BackColor = Color.Red;
  7301. label_FacModeResult.Text = "测试异常";
  7302. Delay_ms(500);
  7303. //存储异常并上传
  7304. FacMode_Stop(false);
  7305. return;
  7306. }
  7307. //停止电机
  7308. Code[0] = 0x00;
  7309. Code[1] = 0xF0;
  7310. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7311. WriteACK = false;
  7312. WriteCnt = 0;
  7313. ACK_WaitCnt = 0;
  7314. while (ACK_WaitCnt <= 2) ; //1s
  7315. if (textBox_RunInfo_GearSt.Text != "OFF")
  7316. {
  7317. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第1次重发" + "\r\n");
  7318. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7319. ACK_WaitCnt = 0;
  7320. while (ACK_WaitCnt <= 2) ; //1s
  7321. if (textBox_RunInfo_GearSt.Text != "OFF")
  7322. {
  7323. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK,第2次重发" + "\r\n");
  7324. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7325. ACK_WaitCnt = 0;
  7326. while (ACK_WaitCnt <= 2) ; //1s
  7327. if (textBox_RunInfo_GearSt.Text != "OFF")
  7328. {
  7329. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK异常" + "\r\n");
  7330. label_FacModeStatus.Text = "存在故障!";
  7331. label_FacModeResult.BackColor = Color.Red;
  7332. label_FacModeResult.Text = "测试异常";
  7333. Delay_ms(500);
  7334. //存储异常并上传
  7335. FacMode_Stop(false);
  7336. return;
  7337. }
  7338. }
  7339. }
  7340. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "退出WALK" + "\r\n");
  7341. Delay_ms(500);
  7342. }
  7343. else
  7344. {
  7345. label_FacModeBreak.BackColor = Color.Yellow;
  7346. label_FacModeStatus.Text = "跳过刹车检测!";
  7347. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过刹车检测" + "\r\n");
  7348. Delay_ms(500);
  7349. }
  7350. //前后灯检测
  7351. if (checkBox_FacLightTest.Checked)
  7352. {
  7353. //前后灯检测
  7354. label_FacModeStatus.Text = "前后灯检测";
  7355. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令" + "\r\n");
  7356. //发送指令打开车灯
  7357. Code[0] = 0x00;
  7358. Code[1] = 0xF1;
  7359. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7360. WriteACK = false;
  7361. WriteCnt = 0;
  7362. ACK_WaitCnt = 0;
  7363. while (ACK_WaitCnt <= 2) ; //1s
  7364. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7365. {
  7366. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第1次重发" + "\r\n");
  7367. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7368. ACK_WaitCnt = 0;
  7369. while (ACK_WaitCnt <= 2); //1s
  7370. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7371. {
  7372. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令,第2次重发" + "\r\n");
  7373. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7374. ACK_WaitCnt = 0;
  7375. while (ACK_WaitCnt <= 2) ; //1s
  7376. if (textBox_RunInfo_LightSwitch.Text != "ON")
  7377. {
  7378. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开灯指令发送异常" + "\r\n");
  7379. label_FacModeStatus.Text = "存在故障!";
  7380. label_FacModeResult.BackColor = Color.Red;
  7381. label_FacModeResult.Text = "测试异常";
  7382. Delay_ms(500);
  7383. //存储异常并上传
  7384. FacMode_Stop(false);
  7385. return;
  7386. }
  7387. }
  7388. }
  7389. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已打开前后灯" + "\r\n");
  7390. Delay_ms(500);
  7391. //提示检查灯压是否正确
  7392. if (MessageBox.Show("前后灯是否正常开启?", "前后灯判断", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  7393. {
  7394. label_FacModeLightF.BackColor = Color.Green;
  7395. label_FacModeLightB.BackColor = Color.Green;
  7396. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯正常" + "\r\n");
  7397. Delay_ms(500);
  7398. }
  7399. else
  7400. {
  7401. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "前后灯异常" + "\r\n");
  7402. label_FacModeStatus.Text = "存在故障!";
  7403. label_FacModeResult.BackColor = Color.Red;
  7404. label_FacModeResult.Text = "测试异常";
  7405. Delay_ms(500);
  7406. //存储异常并上传
  7407. FacMode_Stop(false);
  7408. return;
  7409. }
  7410. //发送指令关闭车灯
  7411. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关灯指令" + "\r\n");
  7412. Code[0] = 0x00;
  7413. Code[1] = 0xF0;
  7414. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7415. WriteACK = false;
  7416. WriteCnt = 0;
  7417. ACK_WaitCnt = 0;
  7418. while (ACK_WaitCnt <= 2) ; //1s
  7419. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7420. {
  7421. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第1次重发" + "\r\n");
  7422. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7423. ACK_WaitCnt = 0;
  7424. while (ACK_WaitCnt <= 2) ; //1s
  7425. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7426. {
  7427. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令,第2次重发" + "\r\n");
  7428. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  7429. ACK_WaitCnt = 0;
  7430. while (ACK_WaitCnt <= 2) ; //1s
  7431. if (textBox_RunInfo_LightSwitch.Text != "OFF")
  7432. {
  7433. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "关灯指令发送异常" + "\r\n");
  7434. label_FacModeStatus.Text = "存在故障!";
  7435. label_FacModeResult.BackColor = Color.Red;
  7436. label_FacModeResult.Text = "测试异常";
  7437. Delay_ms(500);
  7438. //存储异常并上传
  7439. FacMode_Stop(false);
  7440. return;
  7441. }
  7442. }
  7443. }
  7444. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "已关闭前后灯" + "\r\n");
  7445. Delay_ms(500);
  7446. }
  7447. else
  7448. {
  7449. label_FacModeLightF.BackColor = Color.Yellow;
  7450. label_FacModeLightB.BackColor = Color.Yellow;
  7451. label_FacModeStatus.Text = "跳过前后灯检测!";
  7452. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过前后灯检测" + "\r\n");
  7453. Delay_ms(500);
  7454. }
  7455. //软件版本检测
  7456. do
  7457. {
  7458. label_FacModeStatus.Text = "软件版本确认";
  7459. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7460. //发送指令读取版本
  7461. Class_Motor_Ver.Mode = "---";
  7462. Class_Motor_Ver.SN = "---";
  7463. Class_Motor_Ver.HW = "---";
  7464. Class_Motor_Ver.FW = "---";
  7465. Class_Motor_Ver.Special = "---";
  7466. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7467. ACK_WaitCnt = 0;
  7468. while (ACK_WaitCnt <= 2) ; //1s
  7469. if (Class_Motor_Ver.Mode == "---")
  7470. {
  7471. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7472. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7473. ACK_WaitCnt = 0;
  7474. while (ACK_WaitCnt <= 2) ; //1s
  7475. if (Class_Motor_Ver.Mode == "---")
  7476. {
  7477. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7478. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7479. ACK_WaitCnt = 0;
  7480. while (ACK_WaitCnt <= 2) ; //1s
  7481. if (Class_Motor_Ver.Mode == "---")
  7482. {
  7483. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息失败" + "\r\n");
  7484. label_FacModeStatus.Text = "存在故障!";
  7485. label_FacModeResult.BackColor = Color.Red;
  7486. label_FacModeResult.Text = "测试异常";
  7487. Delay_ms(500);
  7488. //存储异常并上传
  7489. FacMode_Stop(false);
  7490. return;
  7491. }
  7492. }
  7493. }
  7494. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  7495. richTextBox_FacModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  7496. richTextBox_FacModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  7497. richTextBox_FacModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  7498. richTextBox_FacModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  7499. richTextBox_FacModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  7500. //判断版本是否正确
  7501. string VerCheck = comboBox_FacModeCfgFile.Text.Split('_')[3] + "_" + comboBox_FacModeCfgFile.Text.Split('_')[4];
  7502. string VerRead = "";
  7503. try
  7504. {
  7505. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  7506. }
  7507. catch (System.Exception)
  7508. {
  7509. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  7510. label_FacModeStatus.Text = "存在故障!";
  7511. label_FacModeResult.BackColor = Color.Red;
  7512. label_FacModeResult.Text = "测试异常";
  7513. Delay_ms(500);
  7514. //存储异常并上传
  7515. FacMode_Stop(false);
  7516. return;
  7517. }
  7518. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  7519. {
  7520. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  7521. label_FacModeStatus.Text = "存在故障!";
  7522. label_FacModeResult.BackColor = Color.Red;
  7523. label_FacModeResult.Text = "测试异常";
  7524. Delay_ms(500);
  7525. //存储异常并上传
  7526. FacMode_Stop(false);
  7527. return;
  7528. }
  7529. label_FacModeFWVersion.BackColor = Color.Green;
  7530. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  7531. Delay_ms(500);
  7532. } while (false);
  7533. //测试合格
  7534. richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  7535. label_FacModeStatus.Text = "测试结束!";
  7536. label_FacModeResult.BackColor = Color.Green;
  7537. label_FacModeResult.Text = "测试合格";
  7538. Delay_ms(500);
  7539. //存储并上传
  7540. FacMode_Stop(true);
  7541. return;
  7542. }
  7543. private void FacModelLabelInit()
  7544. {
  7545. //测试状态标签
  7546. label_FacModeResult.BackColor = Color.Yellow;
  7547. label_FacModeResult.Text = "测试中";
  7548. //测试过程标签
  7549. label_FacModeStatus.Text = "测试就绪";
  7550. //测试结果标签
  7551. foreach (Control c in groupBox28.Controls)
  7552. {
  7553. if (c is Label)
  7554. {
  7555. if (c.Text == string.Empty)
  7556. c.BackColor = Color.Red;
  7557. }
  7558. }
  7559. }
  7560. private void comboBox_CheckModeCfgDate_Click(object sender, EventArgs e)
  7561. {
  7562. //更新生产配置文件目录
  7563. GetDateList(false);
  7564. }
  7565. private void comboBox_FacModeCfgDate_Click(object sender, EventArgs e)
  7566. {
  7567. //更新生产配置文件目录
  7568. GetDateList(false);
  7569. }
  7570. private void richTextBox_FacModeLog_TextChanged(object sender, EventArgs e)
  7571. {
  7572. richTextBox_FacModeLog.SelectionStart = richTextBox_FacModeLog.Text.Length;
  7573. richTextBox_FacModeLog.ScrollToCaret();
  7574. }
  7575. /// <summary>
  7576. /// 参数检验测试停止
  7577. /// </summary>
  7578. /// <param name="OK_Flag"></param>
  7579. private void CheckMode_Stop(bool OK_Flag)
  7580. {
  7581. //打开开始按钮
  7582. button_CheckModeStart.Enabled = true;
  7583. //导出电机参数
  7584. string Params = "";
  7585. do
  7586. {
  7587. if (!OK_Flag)
  7588. {
  7589. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常,停止导出" + "\r\n");
  7590. break;
  7591. }
  7592. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "导出电机存储参数" + "\r\n");
  7593. //读取一次马达参数
  7594. richTextBox_MotorParam.Clear();
  7595. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  7596. Delay_ms(100);
  7597. Params += "[马达参数]" + "\r\n" + richTextBox_MotorParam.Text + "\r\n";
  7598. Params += "\r\n";
  7599. //读取一次整车参数
  7600. richTextBox_BikeParam.Clear();
  7601. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  7602. Delay_ms(100);
  7603. Params += "[整车参数]" + "\r\n" + richTextBox_BikeParam.Text + "\r\n";
  7604. Params += "\r\n";
  7605. //读取一次控制参数
  7606. richTextBox_ControlParam.Clear();
  7607. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  7608. Delay_ms(100);
  7609. Params += "[控制参数]" + "\r\n" + richTextBox_ControlParam.Text + "\r\n";
  7610. Params += "\r\n";
  7611. //查询传感器
  7612. richTextBox_SensorParam.Clear();
  7613. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  7614. Delay_ms(100);
  7615. Params += "[传感器参数]" + "\r\n" + richTextBox_SensorParam.Text + "\r\n";
  7616. Params += "\r\n";
  7617. //读取15次助力参数
  7618. Params += "[助力参数]" + "\r\n";
  7619. for (int i = 1; i <= 15; i++)
  7620. {
  7621. var ConfigParam = new byte[4];
  7622. richTextBox_AssistParam.Clear();
  7623. ConfigParam[0] = (byte)(i & 0xFF);
  7624. ConfigParam[1] = (byte)(i >> 8);
  7625. ConfigParam[2] = (byte)(((i >= 5) ? 5 : i) & 0xFF);
  7626. ConfigParam[3] = (byte)(((i >= 5) ? 5 : i) >> 8);
  7627. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  7628. Delay_ms(200);
  7629. Params += richTextBox_AssistParam.Text + "\r\n";
  7630. Params += "\r\n";
  7631. }
  7632. //读取一次调试信息
  7633. richTextBox_DebugParam.Clear();
  7634. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  7635. Delay_ms(100);
  7636. Params += "[调试参数]" + "\r\n" + richTextBox_DebugParam.Text + "\r\n";
  7637. Params += "\r\n";
  7638. //读取一次历史信息
  7639. richTextBox_Record.Clear();
  7640. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  7641. Delay_ms(100);
  7642. Params += "[历史信息]" + "\r\n" + richTextBox_Record.Text + "\r\n";
  7643. Params += "\r\n";
  7644. //读取一次MOS内阻校准参数
  7645. foreach (Control c in groupBox21.Controls)
  7646. {
  7647. if (c is TextBox)
  7648. c.Text = "";
  7649. }
  7650. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  7651. Delay_ms(100);
  7652. Params += "[MOS内阻校准参数]" + "\r\n";
  7653. Params += textBox_MOS_K1.Text + ", " + textBox_MOS_K2.Text + ", " + textBox_MOS_K3.Text + ", " + textBox_MOS_K4.Text + ", "
  7654. + textBox_MOS_K5.Text + ", " + textBox_MOS_R1.Text + ", " + textBox_MOS_R2.Text + ", " + textBox_MOS_R3.Text + ", " + "\r\n";
  7655. Params += "\r\n";
  7656. //读取一次整车参数2
  7657. richTextBox_BikeParam2.Clear();
  7658. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null)) break;
  7659. Delay_ms(100);
  7660. Params += "[整车参数2]" + "\r\n" + richTextBox_BikeParam2.Text + "\r\n";
  7661. Params += "\r\n";
  7662. //读取一次用户骑行参数
  7663. richTextBox_UsrRidesParam.Clear();
  7664. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  7665. Delay_ms(100);
  7666. Params += "[用户骑行参数]" + "\r\n" + richTextBox_UsrRidesParam.Text + "\r\n";
  7667. Params += "\r\n";
  7668. //读取一次生产信息
  7669. textBox_MAC.Text = "";
  7670. textBox_MACAdd.Text = "";
  7671. textBox_MACDate.Text = "";
  7672. textBox_PP.Text = "";
  7673. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  7674. Delay_ms(100);
  7675. Params += "[生产信息]" + "\r\n";
  7676. Params += "生产商: " + textBox_MAC.Text + "\r\n";
  7677. Params += "生产地: " + textBox_MACAdd.Text + "\r\n";
  7678. Params += "生产日期: " + textBox_MACDate.Text + "\r\n";
  7679. Params += "产品标识: " + textBox_PP.Text + "\r\n";
  7680. Params += "\r\n";
  7681. //读取一次自定义信息
  7682. textBox_User1.Text = "---";
  7683. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  7684. Delay_ms(100);
  7685. textBox_User2.Text = "---";
  7686. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  7687. Delay_ms(100);
  7688. textBox_User3.Text = "---";
  7689. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  7690. Delay_ms(100);
  7691. Params += "[自定义信息]" + "\r\n";
  7692. Params += "自定义1: " + textBox_User1.Text + "\r\n";
  7693. Params += "自定义2: " + textBox_User2.Text + "\r\n";
  7694. Params += "自定义3: " + textBox_User3.Text + "\r\n";
  7695. Params += "\r\n";
  7696. //读取一次密钥
  7697. textBox_Key.Text = "---";
  7698. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  7699. Delay_ms(100);
  7700. Params += "[校验密钥]" + "\r\n" + textBox_Key.Text + "\r\n";
  7701. Params += "\r\n";
  7702. //读取一次存储标志
  7703. radioButton_EE_SaveYes.Checked = false;
  7704. radioButton_EE_SaveNo.Checked = false;
  7705. radioButton_SIP_SaveYes.Checked = false;
  7706. radioButton_SIP_SaveNo.Checked = false;
  7707. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  7708. Delay_ms(100);
  7709. Params += "[存储标志]" + "\r\n";
  7710. Params += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7711. Params += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  7712. Params += "\r\n";
  7713. } while (false);
  7714. //系统关机
  7715. var Code = new byte[32];//发送的指令数据
  7716. Code[0] = 0xF0;
  7717. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7718. //关闭串口
  7719. //mySerialProcess.SerialClose(false);
  7720. //路径设置
  7721. string LocalSavePath = "";
  7722. string ServerSavePath = "";
  7723. if (OK_Flag)
  7724. {
  7725. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "OK\\";
  7726. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/OK/";
  7727. }
  7728. else
  7729. {
  7730. LocalSavePath = localInfo.LocalDataPath + localInfo.CheckPathName + "FAIL\\";
  7731. ServerSavePath = toolStripTextBox_ServerPath.Text + "/qcTest/FAIL/";
  7732. }
  7733. if (Directory.Exists(LocalSavePath) == false)
  7734. {
  7735. Directory.CreateDirectory(LocalSavePath);
  7736. }
  7737. //保存和上传
  7738. string LogSavePath = "";
  7739. string LogSaveFileName = "";
  7740. string ProductInfo = textBox_CheckModeScan.Text.Replace(" ", "_"); ;
  7741. LogSavePath = LocalSavePath + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ProductInfo;
  7742. if (Directory.Exists(LogSavePath) == false)
  7743. {
  7744. Directory.CreateDirectory(LogSavePath);
  7745. }
  7746. //测试页面
  7747. Double scaleX = PrimaryScreen.ScaleX;
  7748. Double scaleY = PrimaryScreen.ScaleY;
  7749. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  7750. Graphics g = Graphics.FromImage(bit);
  7751. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  7752. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试页面" + ".png";
  7753. bit.Save(LogSaveFileName);
  7754. //上传测试页面到服务器
  7755. if (myFtp.IsNetConnected == true)
  7756. {
  7757. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7758. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7759. {
  7760. myFtp.MakeDir(ServerSavePath + DateNow);
  7761. }
  7762. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7763. {
  7764. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7765. }
  7766. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7767. if (result == true)
  7768. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  7769. }
  7770. //测试记录
  7771. LogSaveFileName = LogSavePath + "\\" + ProductInfo + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_测试记录" + ".log";
  7772. string file_str = "";
  7773. file_str += "测试计算机:\r\n" + label_Computername.Text + "\r\n";
  7774. file_str += "测试时间:\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  7775. file_str += "检验记录:\r\n" + richTextBox_CheckModeLog.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  7776. file_str += "检验结果:\r\n" + label_CheckModeResult.Text + "\r\n\r\n";
  7777. file_str += Local_HdInformation;
  7778. file_str += "\r\n电机存储参数:\r\n" + Params + "\r\n";
  7779. System.IO.File.WriteAllText(LogSaveFileName, file_str);
  7780. //上传测试记录到服务器
  7781. if (myFtp.IsNetConnected == true)
  7782. {
  7783. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  7784. if (myFtp.DirectoryExist(ServerSavePath, DateNow) == false)
  7785. {
  7786. myFtp.MakeDir(ServerSavePath + DateNow);
  7787. }
  7788. if (myFtp.DirectoryExist(ServerSavePath + DateNow, ProductInfo) == false)
  7789. {
  7790. myFtp.MakeDir(ServerSavePath + DateNow + "/" + ProductInfo);
  7791. }
  7792. bool result = myFtp.UploadFile(LogSaveFileName, ServerSavePath + DateNow + "/" + ProductInfo);
  7793. if (result == true)
  7794. richTextBox_CheckModeLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  7795. }
  7796. //扫码框清空
  7797. textBox_CheckModeScan.Text = "";
  7798. }
  7799. /// <summary>
  7800. /// 参数检验开始
  7801. /// </summary>
  7802. /// <param name="sender"></param>
  7803. /// <param name="e"></param>
  7804. private void button_CheckModeStart_Click(object sender, EventArgs e)
  7805. {
  7806. //测试项目关闭编辑
  7807. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  7808. foreach (Control c in groupBox29.Controls)
  7809. {
  7810. if (c is CheckBox)
  7811. c.Enabled = false;
  7812. }
  7813. ReadLockStatus = true;
  7814. //检查配置文件
  7815. if (comboBox_CheckModeCfgFile.Text == "")
  7816. {
  7817. MessageBox.Show("请选择配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7818. return;
  7819. }
  7820. //开始测试
  7821. CheckTestStart();
  7822. }
  7823. /// <summary>
  7824. /// 参数检验测试子函数
  7825. /// </summary>
  7826. private void CheckTestStart()
  7827. {
  7828. //初始化标签
  7829. CheckModeLabelInit();
  7830. richTextBox_CheckModeLog.Clear();
  7831. //按钮禁止操作
  7832. button_CheckModeStart.Enabled = false;
  7833. //记录配置文件
  7834. richTextBox_CheckModeLog.AppendText("配置文件:" + comboBox_CheckModeCfgDate.Text + " / " + comboBox_CheckModeCfgFile.Text + "\r\n");
  7835. //检查打标信息
  7836. label_CheckModeStatus.Text = "检查扫码信息";
  7837. Delay_ms(500);
  7838. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
  7839. if (textBox_CheckModeScan.Text == string.Empty)
  7840. {
  7841. MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7842. button__FacMode_Start.Enabled = false;
  7843. return;
  7844. }
  7845. try
  7846. {
  7847. if (中置电机ToolStripMenuItem.Checked == true)
  7848. {
  7849. if (textBox_CheckModeScan.Text.Split(' ').Length != 7)
  7850. {
  7851. label_CheckModeStatus.Text = "存在故障!";
  7852. label_CheckModeResult.BackColor = Color.Red;
  7853. label_CheckModeResult.Text = "标签格式错误";
  7854. button_CheckModeStart.Enabled = true;
  7855. return;
  7856. }
  7857. }
  7858. else if (轮毂电机ToolStripMenuItem.Checked == true)
  7859. {
  7860. if (textBox_CheckModeScan.Text.Split(new string[] { " " }, StringSplitOptions.None).Length != 3)
  7861. {
  7862. label_CheckModeStatus.Text = "存在故障!";
  7863. label_CheckModeResult.BackColor = Color.Red;
  7864. label_CheckModeResult.Text = "标签格式错误";
  7865. button_CheckModeStart.Enabled = true;
  7866. return;
  7867. }
  7868. }
  7869. }
  7870. catch (System.Exception)
  7871. {
  7872. label_CheckModeStatus.Text = "存在故障!";
  7873. label_CheckModeResult.BackColor = Color.Red;
  7874. label_CheckModeResult.Text = "标签格式错误";
  7875. button_CheckModeStart.Enabled = true;
  7876. return;
  7877. }
  7878. //打开串口
  7879. mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, false, false);
  7880. if (!mySerialProcess.mySerial.IsOpen)
  7881. {
  7882. MessageBox.Show("请检查串口连接!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  7883. button__FacMode_Start.Enabled = false;
  7884. return;
  7885. }
  7886. //流水号计数
  7887. int serial = Convert.ToInt32(label_CheckModeSerial.Text);
  7888. serial += 1;
  7889. label_CheckModeSerial.Text = serial.ToString();
  7890. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, serial.ToString());
  7891. //创建线程,执行测试任务
  7892. Thread th = new Thread(CheckModeTest_Task);
  7893. th.Start();
  7894. }
  7895. /// <summary>
  7896. /// 执行一次测试任务
  7897. /// </summary>
  7898. private void CheckModeTest_Task()
  7899. {
  7900. //开始测试
  7901. richTextBox_CheckModeLog.AppendText("产品标签:" + textBox_CheckModeScan.Text + "\r\n");
  7902. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n");
  7903. //变量定义
  7904. var Code = new byte[255];//发送的指令数据
  7905. ushort DataTemp;
  7906. short DataTemp_Int16;
  7907. string ResultPathName = "";
  7908. label_CheckModeStatus.Text = "开始测试";
  7909. BootInfo = "";
  7910. Delay_ms(500);
  7911. label_CheckModeStatus.Text = "系统开机";
  7912. //UART控制器发送复位指令把联动装置盒控制器接口波特率改为57600
  7913. if (uARTToolStripMenuItem.Checked)
  7914. {
  7915. Code[0] = (byte)'R';
  7916. Code[1] = (byte)'E';
  7917. Code[2] = (byte)'S';
  7918. Code[3] = (byte)'E';
  7919. Code[4] = (byte)'T';
  7920. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  7921. Delay_ms(500);
  7922. }
  7923. //系统开机,确保测试前先关机,发送关机指令再发送开机指令
  7924. //确保测试前先关机,发送关机指令再发送开机指令
  7925. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送关机指令" + "\r\n");
  7926. Code[0] = 0xF0;
  7927. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7928. Delay_ms(1500);
  7929. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开机指令" + "\r\n");
  7930. Code[0] = 0xF1;
  7931. mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
  7932. ACK_WaitCnt = 0;
  7933. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "等待控制器返回Boot信息……" + "\r\n");
  7934. while (ACK_WaitCnt <= 20) ; //10s
  7935. //检查BOOT版本
  7936. if (BootInfo != string.Empty)
  7937. {
  7938. label_CheckModeBoot.BackColor = Color.Green;
  7939. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机成功,Boot版本:" + BootInfo + "\r\n");
  7940. Delay_ms(500);
  7941. }
  7942. else
  7943. {
  7944. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开机失败" + BootInfo + "\r\n");
  7945. label_CheckModeStatus.Text = "存在故障!";
  7946. label_CheckModeResult.BackColor = Color.Red;
  7947. label_CheckModeResult.Text = "测试异常";
  7948. Delay_ms(500);
  7949. //存储异常并上传
  7950. CheckMode_Stop(false);
  7951. return;
  7952. }
  7953. #if false
  7954. if (uARTToolStripMenuItem.Checked)//UART控制器默认按照5S协议收发数据
  7955. {
  7956. Code[0] = 0x00;//5S协议
  7957. Code[1] = 0x00;
  7958. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7959. Delay_ms(500);
  7960. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  7961. Delay_ms(500);
  7962. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令进入5S协议" + "\r\n");
  7963. }
  7964. #endif
  7965. //发送指令读取版本信息
  7966. do
  7967. {
  7968. label_CheckModeStatus.Text = "读取版本信息";
  7969. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令读取版本信息" + "\r\n");
  7970. //发送指令读取版本
  7971. Class_Motor_Ver.Mode = "---";
  7972. Class_Motor_Ver.SN = "---";
  7973. Class_Motor_Ver.HW = "---";
  7974. Class_Motor_Ver.FW = "---";
  7975. Class_Motor_Ver.Special = "---";
  7976. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7977. ACK_WaitCnt = 0;
  7978. while (ACK_WaitCnt <= 2) ; //1s
  7979. if (Class_Motor_Ver.Mode == "---")
  7980. {
  7981. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第1次重发" + "\r\n");
  7982. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7983. ACK_WaitCnt = 0;
  7984. while (ACK_WaitCnt <= 2) ; //1s
  7985. if (Class_Motor_Ver.Mode == "---")
  7986. {
  7987. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取版本信息,第2次重发" + "\r\n");
  7988. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  7989. ACK_WaitCnt = 0;
  7990. while (ACK_WaitCnt <= 2) ; //1s
  7991. if (Class_Motor_Ver.Mode == "---")
  7992. {
  7993. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取失败" + "\r\n");
  7994. label_CheckModeStatus.Text = "存在故障!";
  7995. label_CheckModeResult.BackColor = Color.Red;
  7996. label_CheckModeResult.Text = "测试异常";
  7997. Delay_ms(500);
  7998. //存储异常并上传
  7999. CheckMode_Stop(false);
  8000. return;
  8001. }
  8002. }
  8003. }
  8004. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息读取成功" + "\r\n");
  8005. Delay_ms(500);
  8006. } while (false);
  8007. //软件版本检查
  8008. if (checkBox_CheckModeFWVer.Checked)
  8009. {
  8010. richTextBox_CheckModeLog.AppendText("型号: " + Class_Motor_Ver.Mode + "\r\n");
  8011. richTextBox_CheckModeLog.AppendText("序列号: " + Class_Motor_Ver.SN + "\r\n");
  8012. richTextBox_CheckModeLog.AppendText("硬件版本: " + Class_Motor_Ver.HW + "\r\n");
  8013. richTextBox_CheckModeLog.AppendText("软件版本: " + Class_Motor_Ver.FW + "\r\n");
  8014. richTextBox_CheckModeLog.AppendText("软件标识: " + Class_Motor_Ver.Special + "\r\n");
  8015. //判断版本是否正确
  8016. string VerCheck = comboBox_CheckModeCfgFile.Text.Split('_')[3] + "_" + comboBox_CheckModeCfgFile.Text.Split('_')[4];
  8017. string VerRead = "";
  8018. try
  8019. {
  8020. VerRead = Class_Motor_Ver.FW.Split('_')[0] + Class_Motor_Ver.Special.Split('-')[2].Substring(0, 4).Replace('V', '.') + "_" + Class_Motor_Ver.FW.Split('_')[1];
  8021. }
  8022. catch (System.Exception)
  8023. {
  8024. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本信息不完整" + "\r\n");
  8025. label_CheckModeStatus.Text = "存在故障!";
  8026. label_CheckModeResult.BackColor = Color.Red;
  8027. label_CheckModeResult.Text = "测试异常";
  8028. Delay_ms(500);
  8029. //存储异常并上传
  8030. CheckMode_Stop(false);
  8031. return;
  8032. }
  8033. if (string.Equals(VerCheck, VerRead) == false) //版本错误,直接结束
  8034. {
  8035. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本错误" + "\r\n");
  8036. label_CheckModeStatus.Text = "存在故障!";
  8037. label_CheckModeResult.BackColor = Color.Red;
  8038. label_CheckModeResult.Text = "测试异常";
  8039. Delay_ms(500);
  8040. //存储异常并上传
  8041. CheckMode_Stop(false);
  8042. return;
  8043. }
  8044. label_CheckModeFWVer.BackColor = Color.Green;
  8045. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "软件版本正确" + "\r\n");
  8046. Delay_ms(500);
  8047. }
  8048. else
  8049. {
  8050. label_CheckModeFWVer.BackColor = Color.Yellow;
  8051. label_CheckModeStatus.Text = "跳过软件版本查询";
  8052. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过软件版本查询" + "\r\n");
  8053. Delay_ms(500);
  8054. }
  8055. //打标信息核对
  8056. if (checkBox_CheckModeSN.Checked)
  8057. {
  8058. label_CheckModeStatus.Text = "核对打标信息";
  8059. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "核对打标信息" + "\r\n");
  8060. //根据扫码信息获取型号和SN
  8061. string ScanInfo = textBox_CheckModeScan.Text;
  8062. string regexInfo = "";
  8063. string[] InfoList = { "" };
  8064. try
  8065. {
  8066. if (中置电机ToolStripMenuItem.Checked == true)
  8067. {
  8068. regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  8069. InfoList = Regex.Split(ScanInfo.Replace(" ", ""), regexInfo, RegexOptions.IgnoreCase);
  8070. }
  8071. else if (轮毂电机ToolStripMenuItem.Checked == true)
  8072. {
  8073. InfoList = ScanInfo.Split(new string[] { " " }, StringSplitOptions.None);
  8074. string Model = InfoList[0];
  8075. string Spec = InfoList[1];
  8076. string Sn = InfoList[2];
  8077. InfoList[0] = Model.Replace("-", "").Replace("Q12", "QA").Replace("Q15", "QB").Replace("Q18", "QC").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
  8078. InfoList[1] = Sn;
  8079. }
  8080. }
  8081. catch
  8082. {
  8083. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "标签格式错误" + "\r\n");
  8084. label_FacModeStatus.Text = "存在故障!";
  8085. label_FacModeResult.BackColor = Color.Red;
  8086. label_FacModeResult.Text = "标签格式错误";
  8087. Delay_ms(500);
  8088. //存储异常并上传
  8089. CheckMode_Stop(false);
  8090. return;
  8091. }
  8092. //核对型号
  8093. if (string.Equals(InfoList[0], Class_Motor_Ver.Mode) == false) //型号错误,直接结束
  8094. {
  8095. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号不一致" + "\r\n");
  8096. label_CheckModeStatus.Text = "存在故障!";
  8097. label_CheckModeResult.BackColor = Color.Red;
  8098. label_CheckModeResult.Text = "测试异常";
  8099. Delay_ms(500);
  8100. //存储异常并上传
  8101. CheckMode_Stop(false);
  8102. return;
  8103. }
  8104. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号一致" + "\r\n");
  8105. Delay_ms(500);
  8106. //核对SN
  8107. if (string.Equals(InfoList[1], Class_Motor_Ver.SN) == false) //型号错误,直接结束
  8108. {
  8109. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN不一致" + "\r\n");
  8110. label_CheckModeStatus.Text = "存在故障!";
  8111. label_CheckModeResult.BackColor = Color.Red;
  8112. label_CheckModeResult.Text = "测试异常";
  8113. Delay_ms(500);
  8114. //存储异常并上传
  8115. CheckMode_Stop(false);
  8116. return;
  8117. }
  8118. label_CheckModeSN.BackColor = Color.Green;
  8119. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN一致" + "\r\n");
  8120. Delay_ms(500);
  8121. }
  8122. else
  8123. {
  8124. label_CheckModeSN.BackColor = Color.Yellow;
  8125. label_CheckModeStatus.Text = "跳过打标信息确认";
  8126. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过打标信息确认" + "\r\n");
  8127. Delay_ms(500);
  8128. }
  8129. //参数检验
  8130. if (checkBox_CheckModeCfg.Checked)
  8131. {
  8132. //读取配置文件信息
  8133. label_CheckModeStatus.Text = "参数检查";
  8134. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取配置文件" + "\r\n");
  8135. //配置文件
  8136. List<byte[]> CmdList = new List<byte[]>();
  8137. Dictionary<string, string> ConfigCmd = new Dictionary<string, string>();//配置文件格式
  8138. //从服务器下载文件
  8139. if ((checkBox_OffLineFacMode.Checked == false) && (checkBox_OffLineCheckMode.Checked == false))
  8140. {
  8141. string SelectFile = "";
  8142. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "/" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8143. if (File.Exists(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString()))//本地存在选定文件,先删除本地
  8144. {
  8145. File.Delete(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8146. }
  8147. myFtp.DownloadFile(toolStripTextBox_ServerPath.Text + "/" + localInfo.CfgPathName + SelectFile, localInfo.LocalPath);
  8148. //打开文件
  8149. StreamReader streamReader = new StreamReader(localInfo.LocalPath + comboBox_CheckModeCfgFile.SelectedItem.ToString());
  8150. ConfigCmd.Clear();
  8151. while (streamReader.Peek() != -1)
  8152. {
  8153. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8154. if (fileLineInfo.Contains("["))
  8155. {
  8156. if (fileLineInfo.Contains("助力参数"))
  8157. {
  8158. fileLineInfo = streamReader.ReadLine();
  8159. }
  8160. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8161. }
  8162. }
  8163. streamReader.Close();
  8164. }
  8165. //从本地加载文件
  8166. else
  8167. {
  8168. string SelectFile = "";
  8169. SelectFile = comboBox_CheckModeCfgDate.SelectedItem.ToString() + "\\" + comboBox_CheckModeCfgFile.SelectedItem.ToString();
  8170. //打开文件
  8171. StreamReader streamReader = new StreamReader(localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + SelectFile);
  8172. ConfigCmd.Clear();
  8173. while (streamReader.Peek() != -1)
  8174. {
  8175. string fileLineInfo = streamReader.ReadLine(); //读指令名称
  8176. if (fileLineInfo.Contains("["))
  8177. {
  8178. if (fileLineInfo.Contains("助力参数"))
  8179. {
  8180. fileLineInfo = streamReader.ReadLine();
  8181. }
  8182. ConfigCmd.Add(fileLineInfo, streamReader.ReadLine()); //指令名称和指令内容加入字典
  8183. }
  8184. }
  8185. streamReader.Close();
  8186. }
  8187. int CmdNum = ConfigCmd.Count(); //指令个数
  8188. Delay_ms(500);
  8189. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取完成," + "共" + CmdNum.ToString() + "条指令," + "\r\n");
  8190. Delay_ms(500);
  8191. //逐条读取比较
  8192. try
  8193. {
  8194. foreach (string key in ConfigCmd.Keys)
  8195. {
  8196. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令:" + "\r\n");
  8197. CmdRevStrTemp = "";
  8198. if (key.Contains("曲线"))
  8199. {
  8200. byte LineNum = 0;
  8201. var code = new byte[4];
  8202. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8203. if (LineNum <= 5)
  8204. {
  8205. code[0] = (byte)(LineNum & 0xFF);
  8206. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8207. code[2] = (byte)(LineNum & 0xFF);
  8208. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8209. }
  8210. else
  8211. {
  8212. code[0] = (byte)(LineNum & 0xFF);
  8213. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8214. code[2] = (byte)(5 & 0xFF);
  8215. code[3] = (byte)((5 >> 8) & 0xFF);
  8216. }
  8217. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8218. }
  8219. else
  8220. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8221. Delay_ms(500);
  8222. if (CmdRevStrTemp == string.Empty)
  8223. {
  8224. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第1次重发" + "\r\n");
  8225. if (key.Contains("曲线"))
  8226. {
  8227. byte LineNum = 0;
  8228. var code = new byte[4];
  8229. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8230. if (LineNum <= 5)
  8231. {
  8232. code[0] = (byte)(LineNum & 0xFF);
  8233. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8234. code[2] = (byte)(LineNum & 0xFF);
  8235. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8236. }
  8237. else
  8238. {
  8239. code[0] = (byte)(LineNum & 0xFF);
  8240. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8241. code[2] = (byte)(5 & 0xFF);
  8242. code[3] = (byte)((5 >> 8) & 0xFF);
  8243. }
  8244. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8245. }
  8246. else
  8247. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8248. Delay_ms(500);
  8249. if (CmdRevStrTemp == string.Empty)
  8250. {
  8251. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送读" + key + "指令,第2次重发" + "\r\n");
  8252. if (key.Contains("曲线"))
  8253. {
  8254. byte LineNum = 0;
  8255. var code = new byte[4];
  8256. LineNum = Convert.ToByte(key.Substring(3, key.Length - 4));
  8257. if (LineNum <= 5)
  8258. {
  8259. code[0] = (byte)(LineNum & 0xFF);
  8260. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8261. code[2] = (byte)(LineNum & 0xFF);
  8262. code[3] = (byte)((LineNum >> 8) & 0xFF);
  8263. }
  8264. else
  8265. {
  8266. code[0] = (byte)(LineNum & 0xFF);
  8267. code[1] = (byte)((LineNum >> 8) & 0xFF);
  8268. code[2] = (byte)(5 & 0xFF);
  8269. code[3] = (byte)((5 >> 8) & 0xFF);
  8270. }
  8271. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd["[助力参数]"], code);
  8272. }
  8273. else
  8274. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)myParams.ConfigCheckReadCmd[key], null);
  8275. Delay_ms(500);
  8276. if (CmdRevStrTemp == string.Empty)
  8277. {
  8278. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "指令读取失败" + "\r\n");
  8279. label_CheckModeStatus.Text = "存在故障!";
  8280. label_CheckModeResult.BackColor = Color.Red;
  8281. label_CheckModeResult.Text = "测试异常";
  8282. Delay_ms(500);
  8283. //存储异常并上传
  8284. CheckMode_Stop(false);
  8285. return;
  8286. }
  8287. }
  8288. }
  8289. //比较当前指令,读取的配置文件和返回数据比较
  8290. string ParamWrite = ConfigCmd[key].Substring(24, ConfigCmd[key].Length - 40).Trim();
  8291. string ParamRead = "";
  8292. if (string.Compare(key, "[其它传感器参数]") == 0)
  8293. ParamRead = CmdRevStrTemp.Substring(90, CmdRevStrTemp.Length - 90).Trim(); //去掉去掉命令字、力矩传感器参数
  8294. else if (string.Compare(key, "[控制参数]") == 0)
  8295. ParamRead = CmdRevStrTemp.Substring(18, CmdRevStrTemp.Length - 18).Trim(); //去掉去掉命令字、位置零点
  8296. else
  8297. ParamRead = CmdRevStrTemp.Substring(6, CmdRevStrTemp.Length - 6).Trim(); //去掉命令字
  8298. if (ParamWrite.Contains(ParamRead))
  8299. {
  8300. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "一致" + "\r\n");
  8301. continue;
  8302. }
  8303. else
  8304. {
  8305. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + key + "不一致" + "\r\n");
  8306. richTextBox_CheckModeLog.AppendText("写入参数:" + ParamWrite + "\r\n");
  8307. richTextBox_CheckModeLog.AppendText("读出参数:" + ParamRead + "\r\n");
  8308. label_CheckModeStatus.Text = "存在故障!";
  8309. label_CheckModeResult.BackColor = Color.Red;
  8310. label_CheckModeResult.Text = "测试异常";
  8311. Delay_ms(500);
  8312. //存储异常并上传
  8313. CheckMode_Stop(false);
  8314. return;
  8315. }
  8316. }
  8317. }
  8318. catch (System.Exception)
  8319. {
  8320. timer_500ms.Enabled = false;
  8321. MessageBox.Show("参数检验失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  8322. timer_500ms.Enabled = true;
  8323. ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
  8324. }
  8325. }
  8326. else
  8327. {
  8328. label_CheckModeCfg.BackColor = Color.Yellow;
  8329. label_CheckModeStatus.Text = "跳过参数检验";
  8330. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过参数检验" + "\r\n");
  8331. Delay_ms(500);
  8332. }
  8333. label_CheckModeCfg.BackColor = Color.Green;
  8334. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "参数检验正确" + "\r\n");
  8335. Delay_ms(500);
  8336. //读取力矩传感器
  8337. do
  8338. {
  8339. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据" + "\r\n");
  8340. //发送指令读取力矩传感器标定数据
  8341. CmdRevStrTemp = "";
  8342. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8343. ACK_WaitCnt = 0;
  8344. while (ACK_WaitCnt <= 2) ; //1s
  8345. if (CmdRevStrTemp == "---")
  8346. {
  8347. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第1次重发" + "\r\n");
  8348. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8349. ACK_WaitCnt = 0;
  8350. while (ACK_WaitCnt <= 2) ; //1s
  8351. if (CmdRevStrTemp == "---")
  8352. {
  8353. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取力矩传感器标定数据,第2次重发" + "\r\n");
  8354. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, 0x4000, null);
  8355. ACK_WaitCnt = 0;
  8356. while (ACK_WaitCnt <= 2) ; //1s
  8357. if (CmdRevStrTemp == "---")
  8358. {
  8359. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取失败" + "\r\n");
  8360. label_CheckModeStatus.Text = "存在故障!";
  8361. label_CheckModeResult.BackColor = Color.Red;
  8362. label_CheckModeResult.Text = "测试异常";
  8363. Delay_ms(500);
  8364. //存储异常并上传
  8365. CheckMode_Stop(false);
  8366. return;
  8367. }
  8368. }
  8369. }
  8370. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器读取成功" + "\r\n");
  8371. //取力矩传感器数据
  8372. ushort ZeroInit, Zero1, Zero2, Zero3, ZeroNew;
  8373. ushort MaxTorque;
  8374. ushort K1_T, K1, K2_T, K2, K3_T, K3, K4_T, K4;
  8375. byte[] DataArray = mySerialProcess.HexStringToBytes(CmdRevStrTemp, true);
  8376. ZeroInit = (ushort)((DataArray[3] << 8) + DataArray[2]);
  8377. Zero1 = (ushort)((DataArray[5] << 8) + DataArray[4]);
  8378. Zero2 = (ushort)((DataArray[7] << 8) + DataArray[6]);
  8379. Zero3 = (ushort)((DataArray[9] << 8) + DataArray[8]);
  8380. ZeroNew = (ushort)((DataArray[11] << 8) + DataArray[10]);
  8381. MaxTorque = (ushort)((DataArray[13] << 8) + DataArray[12]);
  8382. K1_T = (ushort)((DataArray[15] << 8) + DataArray[14]);
  8383. K1 = (ushort)((DataArray[17] << 8) + DataArray[16]);
  8384. K2_T = (ushort)((DataArray[19] << 8) + DataArray[18]);
  8385. K2 = (ushort)((DataArray[21] << 8) + DataArray[20]);
  8386. K3_T = (ushort)((DataArray[23] << 8) + DataArray[22]);
  8387. K3 = (ushort)((DataArray[25] << 8) + DataArray[24]);
  8388. K4_T = (ushort)((DataArray[27] << 8) + DataArray[26]);
  8389. K4 = (ushort)((DataArray[29] << 8) + DataArray[28]);
  8390. richTextBox_CheckModeLog.AppendText("力矩传感器零点: " + ZeroInit.ToString() + "," + Zero1.ToString() + "," +
  8391. Zero2.ToString() + "," + Zero3.ToString() + "," + ZeroNew.ToString() + "\r\n");
  8392. richTextBox_CheckModeLog.AppendText("最大力矩: " + MaxTorque.ToString() + "\r\n");
  8393. richTextBox_CheckModeLog.AppendText("力矩传感器标定: " + "[" + K1_T.ToString() + "," + K1.ToString() + "]" + "," +
  8394. "[" + K2_T.ToString() + "," + K2.ToString() + "]" + "," + "[" + K3_T.ToString() + "," + K3.ToString() + "]" + "," +
  8395. "[" + K4_T.ToString() + "," + K4.ToString() + "]" + "\r\n");
  8396. //传感器标定检验
  8397. if (checkBox_CheckModeTorque.Checked)
  8398. {
  8399. richTextBox_CheckModeLog.AppendText("力矩零点范围: " + TorqueParamsForm.Zero.Min.ToString() + " - " + TorqueParamsForm.Zero.Max.ToString() + "\r\n");
  8400. richTextBox_CheckModeLog.AppendText("K1范围: " + TorqueParamsForm.K1.T.ToString() + "," + TorqueParamsForm.K1.Min.ToString() + " - " + TorqueParamsForm.K1.Max.ToString() + "\r\n");
  8401. richTextBox_CheckModeLog.AppendText("K2范围: " + TorqueParamsForm.K2.T.ToString() + "," + TorqueParamsForm.K2.Min.ToString() + " - " + TorqueParamsForm.K2.Max.ToString() + "\r\n");
  8402. richTextBox_CheckModeLog.AppendText("K3范围: " + TorqueParamsForm.K3.T.ToString() + "," + TorqueParamsForm.K3.Min.ToString() + " - " + TorqueParamsForm.K3.Max.ToString() + "\r\n");
  8403. richTextBox_CheckModeLog.AppendText("K4范围: " + TorqueParamsForm.K4.T.ToString() + "," + TorqueParamsForm.K4.Min.ToString() + " - " + TorqueParamsForm.K4.Max.ToString() + "\r\n");
  8404. //与设置值比较
  8405. if ((ZeroInit <= TorqueParamsForm.Zero.Max) && (ZeroInit >= TorqueParamsForm.Zero.Min)
  8406. && (K1_T == TorqueParamsForm.K1.T) && (K1 <= TorqueParamsForm.K1.Max) && (K1 >= TorqueParamsForm.K1.Min)
  8407. && (K2_T == TorqueParamsForm.K2.T) && (K2 <= TorqueParamsForm.K2.Max) && (K2 >= TorqueParamsForm.K2.Min)
  8408. && (K3_T == TorqueParamsForm.K3.T) && (K3 <= TorqueParamsForm.K3.Max) && (K3 >= TorqueParamsForm.K3.Min)
  8409. && (K4_T == TorqueParamsForm.K4.T) && (K4 <= TorqueParamsForm.K4.Max) && (K4 >= TorqueParamsForm.K4.Min)
  8410. )
  8411. {
  8412. label_CheckModeTorque.BackColor = Color.Green;
  8413. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定正常" + "\r\n");
  8414. Delay_ms(500);
  8415. }
  8416. else
  8417. {
  8418. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器标定超范围" + "\r\n");
  8419. label_CheckModeStatus.Text = "存在故障!";
  8420. label_CheckModeResult.BackColor = Color.Red;
  8421. label_CheckModeResult.Text = "测试异常";
  8422. Delay_ms(500);
  8423. //存储异常并上传
  8424. CheckMode_Stop(false);
  8425. return;
  8426. }
  8427. }
  8428. else
  8429. {
  8430. label_CheckModeTorque.BackColor = Color.Yellow;
  8431. label_CheckModeStatus.Text = "跳过传感器标定检验";
  8432. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过传感器标定检验" + "\r\n");
  8433. Delay_ms(500);
  8434. }
  8435. } while (false);
  8436. //读取MOS内阻校准参数
  8437. do
  8438. {
  8439. if (checkBox_CheckModeMos.Checked)
  8440. {
  8441. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据" + "\r\n");
  8442. //读取显示校准返回数据
  8443. foreach (Control c in groupBox21.Controls)
  8444. {
  8445. if (c is TextBox)
  8446. c.Text = "";
  8447. }
  8448. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8449. ACK_WaitCnt = 0;
  8450. while (ACK_WaitCnt <= 2) ; //1s
  8451. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8452. {
  8453. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第1次重发" + "\r\n");
  8454. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8455. ACK_WaitCnt = 0;
  8456. while (ACK_WaitCnt <= 2) ; //1s
  8457. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8458. {
  8459. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准数据,第2次重发" + "\r\n");
  8460. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8461. ACK_WaitCnt = 0;
  8462. while (ACK_WaitCnt <= 2) ; //1s
  8463. if ((textBox_MOS_R1.Text == string.Empty) || (textBox_MOS_R2.Text == string.Empty) || (textBox_MOS_R3.Text == string.Empty))
  8464. {
  8465. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取MOS内阻校准结果异常" + "\r\n");
  8466. label_CheckModeStatus.Text = "存在故障!";
  8467. label_CheckModeResult.BackColor = Color.Red;
  8468. label_CheckModeResult.Text = "测试异常";
  8469. Delay_ms(500);
  8470. //存储异常并上传
  8471. CheckMode_Stop(false);
  8472. return;
  8473. }
  8474. }
  8475. }
  8476. else
  8477. {
  8478. 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");
  8479. }
  8480. //与校准返回数据对比
  8481. string[] MOS_R1_Th = toolStripTextBox_MOS1.Text.Split(',');
  8482. string[] MOS_R2_Th = toolStripTextBox_MOS2.Text.Split(',');
  8483. string[] MOS_R3_Th = toolStripTextBox_MOS3.Text.Split(',');
  8484. 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])) &&
  8485. (Convert.ToUInt16(textBox_MOS_R2.Text) >= Convert.ToUInt16(MOS_R2_Th[0])) && (Convert.ToUInt16(textBox_MOS_R2.Text) <= Convert.ToUInt16(MOS_R2_Th[1])) &&
  8486. (Convert.ToUInt16(textBox_MOS_R3.Text) >= Convert.ToUInt16(MOS_R3_Th[0])) && (Convert.ToUInt16(textBox_MOS_R3.Text) <= Convert.ToUInt16(MOS_R3_Th[1]))
  8487. )
  8488. {
  8489. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准合格" + "\r\n");
  8490. label_CheckModeMos.BackColor = Color.Green;
  8491. }
  8492. else
  8493. {
  8494. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "MOS内阻校准超范围" + "\r\n");
  8495. label_CheckModeStatus.Text = "存在故障!";
  8496. label_CheckModeResult.BackColor = Color.Red;
  8497. label_CheckModeResult.Text = "测试异常";
  8498. Delay_ms(500);
  8499. //存储异常并上传
  8500. CheckMode_Stop(false);
  8501. return;
  8502. }
  8503. }
  8504. else
  8505. {
  8506. label_CheckModeMos.BackColor = Color.Yellow;
  8507. label_CheckModeStatus.Text = "跳过MOS内阻校准检验";
  8508. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过MOS内阻校准检验" + "\r\n");
  8509. Delay_ms(500);
  8510. }
  8511. } while (false);
  8512. //测试合格
  8513. richTextBox_CheckModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n");
  8514. label_CheckModeStatus.Text = "测试结束!";
  8515. label_CheckModeResult.BackColor = Color.Green;
  8516. label_CheckModeResult.Text = "测试合格";
  8517. Delay_ms(500);
  8518. //存储并上传
  8519. CheckMode_Stop(true);
  8520. return;
  8521. }
  8522. private void CheckModeLabelInit()
  8523. {
  8524. //测试状态标签
  8525. label_CheckModeResult.BackColor = Color.Yellow;
  8526. label_CheckModeResult.Text = "测试中";
  8527. //测试过程标签
  8528. label_CheckModeStatus.Text = "测试就绪";
  8529. //测试结果标签
  8530. foreach (Control c in groupBox31.Controls)
  8531. {
  8532. if (c is Label)
  8533. {
  8534. if (c.Text == string.Empty)
  8535. c.BackColor = Color.Red;
  8536. }
  8537. }
  8538. }
  8539. private void 调试记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8540. {
  8541. System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
  8542. }
  8543. private void 生产记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  8544. {
  8545. System.Diagnostics.Process.Start("explorer.exe", localInfo.LocalDataPath);
  8546. }
  8547. private void 累计运行时间ToolStripMenuItem_MouseHover(object sender, EventArgs e)
  8548. {
  8549. UInt32 Time = (UInt32)stopwatch.ElapsedMilliseconds / 1000;
  8550. UInt32 hour = Time / 3600;
  8551. UInt32 min = (Time % 3600) / 60;
  8552. UInt32 s = (Time % 60);
  8553. toolStripMenuItem_RunTime.Text = hour.ToString() + ":" + min.ToString("00") + ":" + s.ToString("00");
  8554. }
  8555. private void richTextBox_CheckModeLog_TextChanged(object sender, EventArgs e)
  8556. {
  8557. richTextBox_CheckModeLog.SelectionStart = richTextBox_CheckModeLog.Text.Length;
  8558. richTextBox_CheckModeLog.ScrollToCaret();
  8559. }
  8560. private void 力矩传感器检验ToolStripMenuItem_Click(object sender, EventArgs e)
  8561. {
  8562. TorqueParamsForm.ShowDialog();
  8563. }
  8564. private void textBox_CheckModeScan_KeyUp(object sender, KeyEventArgs e)
  8565. {
  8566. if (e.KeyCode == Keys.Enter)
  8567. CheckTestStart();
  8568. }
  8569. private void textBox_FacModeScan_KeyUp(object sender, KeyEventArgs e)
  8570. {
  8571. if (e.KeyCode == Keys.Enter)
  8572. TestStart();
  8573. }
  8574. private void button_SpeedDec10_Click(object sender, EventArgs e)
  8575. {
  8576. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8577. if (Percent <= 10)
  8578. Percent = 0;
  8579. else
  8580. Percent -= 10;
  8581. //生产模式转速设置值更新
  8582. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8583. //设置转速百分比
  8584. var Data = new byte[1];
  8585. Data[0] = (byte)Percent;
  8586. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8587. }
  8588. private void button_SpeedAdd10_Click(object sender, EventArgs e)
  8589. {
  8590. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8591. if (Percent >= 90)
  8592. Percent = 100;
  8593. else
  8594. Percent += 10;
  8595. //生产模式转速设置值更新
  8596. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8597. //设置转速百分比
  8598. var Data = new byte[1];
  8599. Data[0] = (byte)Percent;
  8600. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8601. }
  8602. private void button_SpeedDec1_Click(object sender, EventArgs e)
  8603. {
  8604. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8605. if (Percent <= 1)
  8606. Percent = 0;
  8607. else
  8608. Percent -= 1;
  8609. //生产模式转速设置值更新
  8610. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8611. //设置转速百分比
  8612. var Data = new byte[1];
  8613. Data[0] = (byte)Percent;
  8614. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8615. }
  8616. private void button_SpeedAdd1_Click(object sender, EventArgs e)
  8617. {
  8618. short Percent = Convert.ToInt16(textBox_MotorSpeedPercent.Text);
  8619. if (Percent >= 99)
  8620. Percent = 100;
  8621. else
  8622. Percent += 1;
  8623. //生产模式转速设置值更新
  8624. textBox_MotorSpeedPercent.Text = Percent.ToString();
  8625. //设置转速百分比
  8626. var Data = new byte[1];
  8627. Data[0] = (byte)Percent;
  8628. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  8629. }
  8630. bool WriteLockStatus = true;
  8631. private void pictureBox_WriteLock_Click(object sender, EventArgs e)
  8632. {
  8633. if (WriteLockStatus == true)
  8634. {
  8635. EnterForm1.ShowDialog();
  8636. try
  8637. {
  8638. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8639. {
  8640. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8641. {
  8642. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8643. foreach (Control c in groupBox2.Controls)
  8644. {
  8645. if (c is CheckBox)
  8646. c.Enabled = true;
  8647. }
  8648. WriteLockStatus = !WriteLockStatus;
  8649. }
  8650. else
  8651. {
  8652. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8653. }
  8654. }
  8655. else
  8656. {
  8657. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8658. }
  8659. }
  8660. catch (Exception)
  8661. {
  8662. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8663. }
  8664. }
  8665. else
  8666. {
  8667. pictureBox_WriteLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8668. foreach (Control c in groupBox2.Controls)
  8669. {
  8670. if (c is CheckBox)
  8671. c.Enabled = false;
  8672. }
  8673. WriteLockStatus = !WriteLockStatus;
  8674. }
  8675. }
  8676. bool ReadLockStatus = true;
  8677. private void pictureBox_ReadLock_Click(object sender, EventArgs e)
  8678. {
  8679. if (ReadLockStatus == true)
  8680. {
  8681. EnterForm1.ShowDialog();
  8682. try
  8683. {
  8684. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8685. {
  8686. if (EnterForm1.comboBox_User.Text == "工程参数配置")
  8687. {
  8688. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  8689. foreach (Control c in groupBox29.Controls)
  8690. {
  8691. if (c is CheckBox)
  8692. c.Enabled = true;
  8693. }
  8694. ReadLockStatus = !ReadLockStatus;
  8695. }
  8696. else
  8697. {
  8698. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8699. }
  8700. }
  8701. else
  8702. {
  8703. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8704. }
  8705. }
  8706. catch (Exception)
  8707. {
  8708. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8709. }
  8710. }
  8711. else
  8712. {
  8713. pictureBox_ReadLock.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  8714. foreach (Control c in groupBox29.Controls)
  8715. {
  8716. if (c is CheckBox)
  8717. c.Enabled = false;
  8718. }
  8719. ReadLockStatus = !ReadLockStatus;
  8720. }
  8721. }
  8722. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  8723. {
  8724. System.Diagnostics.Process.Start("osk.exe");
  8725. }
  8726. private void checkBox_OffLineCheckMode_CheckedChanged(object sender, EventArgs e)
  8727. {
  8728. comboBox_CheckModeCfgDate.SelectedIndex = -1;
  8729. comboBox_CheckModeCfgFile.SelectedIndex = -1;
  8730. checkBox_OffLineFacMode.Checked = checkBox_OffLineCheckMode.Checked;
  8731. }
  8732. private void checkBox_OffLineFacMode_CheckedChanged(object sender, EventArgs e)
  8733. {
  8734. comboBox_FacModeCfgDate.SelectedIndex = -1;
  8735. comboBox_FacModeCfgFile.SelectedIndex = -1;
  8736. checkBox_OffLineCheckMode.Checked = checkBox_OffLineFacMode.Checked;
  8737. }
  8738. private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
  8739. {
  8740. VersionForm.ShowDialog();
  8741. }
  8742. private void button_MOS_Cal_Click(object sender, EventArgs e)
  8743. {
  8744. textBox_MOS_R1.Text = "";
  8745. textBox_MOS_R2.Text = "";
  8746. textBox_MOS_R3.Text = "";
  8747. try
  8748. {
  8749. var Code = new byte[18];
  8750. for (int i = 0; i < 18; i++)
  8751. Code[i] = 0;
  8752. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8753. ushort uwDataTemp = 0;
  8754. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8755. Code[2] = (byte)(uwDataTemp & 0xFF);
  8756. Code[3] = (byte)(uwDataTemp >> 8);
  8757. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8758. Code[4] = (byte)(uwDataTemp & 0xFF);
  8759. Code[5] = (byte)(uwDataTemp >> 8);
  8760. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8761. Code[6] = (byte)(uwDataTemp & 0xFF);
  8762. Code[7] = (byte)(uwDataTemp >> 8);
  8763. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8764. Code[8] = (byte)(uwDataTemp & 0xFF);
  8765. Code[9] = (byte)(uwDataTemp >> 8);
  8766. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8767. Code[10] = (byte)(uwDataTemp & 0xFF);
  8768. Code[11] = (byte)(uwDataTemp >> 8);
  8769. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4A12, Code);
  8770. }
  8771. catch (Exception)
  8772. {
  8773. MessageBox.Show("系数填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8774. }
  8775. }
  8776. private void button_MOS_Read_Click(object sender, EventArgs e)
  8777. {
  8778. foreach (Control c in groupBox21.Controls)
  8779. {
  8780. if (c is TextBox)
  8781. c.Text = "";
  8782. }
  8783. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4B00, null);
  8784. }
  8785. private void button_MOS_Write_Click(object sender, EventArgs e)
  8786. {
  8787. try
  8788. {
  8789. var Code = new byte[34];
  8790. for (int i = 0; i < 34; i++)
  8791. Code[i] = 0;
  8792. Code[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8793. ushort uwDataTemp = 0;
  8794. uwDataTemp = Convert.ToUInt16(textBox_MOS_R1.Text);
  8795. Code[2] = (byte)(uwDataTemp & 0xFF);
  8796. Code[3] = (byte)(uwDataTemp >> 8);
  8797. uwDataTemp = Convert.ToUInt16(textBox_MOS_R2.Text);
  8798. Code[4] = (byte)(uwDataTemp & 0xFF);
  8799. Code[5] = (byte)(uwDataTemp >> 8);
  8800. uwDataTemp = Convert.ToUInt16(textBox_MOS_R3.Text);
  8801. Code[6] = (byte)(uwDataTemp & 0xFF);
  8802. Code[7] = (byte)(uwDataTemp >> 8);
  8803. uwDataTemp = Convert.ToUInt16(textBox_MOS_K1.Text);
  8804. Code[8] = (byte)(uwDataTemp & 0xFF);
  8805. Code[9] = (byte)(uwDataTemp >> 8);
  8806. uwDataTemp = Convert.ToUInt16(textBox_MOS_K2.Text);
  8807. Code[10] = (byte)(uwDataTemp & 0xFF);
  8808. Code[11] = (byte)(uwDataTemp >> 8);
  8809. uwDataTemp = Convert.ToUInt16(textBox_MOS_K3.Text);
  8810. Code[12] = (byte)(uwDataTemp & 0xFF);
  8811. Code[13] = (byte)(uwDataTemp >> 8);
  8812. uwDataTemp = Convert.ToUInt16(textBox_MOS_K4.Text);
  8813. Code[14] = (byte)(uwDataTemp & 0xFF);
  8814. Code[15] = (byte)(uwDataTemp >> 8);
  8815. uwDataTemp = Convert.ToUInt16(textBox_MOS_K5.Text);
  8816. Code[16] = (byte)(uwDataTemp & 0xFF);
  8817. Code[17] = (byte)(uwDataTemp >> 8);
  8818. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4C22, Code);
  8819. }
  8820. catch (Exception)
  8821. {
  8822. MessageBox.Show("数据填写不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8823. }
  8824. }
  8825. /// <summary>
  8826. /// 测试模式点击文本框自动全选
  8827. /// </summary>
  8828. /// <param name="sender"></param>
  8829. /// <param name="e"></param>
  8830. private void textBox_FacModeScan_MouseClick(object sender, MouseEventArgs e)
  8831. {
  8832. textBox_FacModeScan.SelectAll();
  8833. }
  8834. /// <summary>
  8835. /// 检验模式点击文本框自动全选
  8836. /// </summary>
  8837. /// <param name="sender"></param>
  8838. /// <param name="e"></param>
  8839. private void textBox_CheckModeScan_MouseClick(object sender, MouseEventArgs e)
  8840. {
  8841. textBox_CheckModeScan.SelectAll();
  8842. }
  8843. /// <summary>
  8844. /// 鼠标放置显示连接服务器信息
  8845. /// </summary>
  8846. /// <param name="sender"></param>
  8847. /// <param name="e"></param>
  8848. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  8849. {
  8850. // 创建the ToolTip
  8851. ToolTip toolTip1 = new ToolTip();
  8852. // 设置显示样式
  8853. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  8854. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  8855. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  8856. toolTip1.ShowAlways = true;//是否显示提示框
  8857. if (myFtp.IsNetConnected)
  8858. {
  8859. toolTip1.SetToolTip(this.label_ServerStatus, "IP: " + ServerIP);//设置故障内容显示
  8860. }
  8861. else
  8862. {
  8863. toolTip1.SetToolTip(this.label_ServerStatus, "网络断开");//设置故障内容显示
  8864. }
  8865. }
  8866. /// <summary>
  8867. /// UART协议类型修改
  8868. /// </summary>
  8869. /// <param name="sender"></param>
  8870. /// <param name="e"></param>
  8871. private void 协议类型ToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
  8872. {
  8873. var Code = new byte[2];
  8874. Code[0] = (byte)协议类型ToolStripMenuItem.SelectedIndex;
  8875. Code[1] = 0x00;
  8876. mySerialProcess.SendCmd((ushort)0x7FF, (byte)0x16, (ushort)0x7702, Code);
  8877. }
  8878. /// <summary>
  8879. /// 显示本机信息
  8880. /// </summary>
  8881. /// <param name="sender"></param>
  8882. /// <param name="e"></param>
  8883. private void 本机信息ToolStripMenuItem_Click(object sender, EventArgs e)
  8884. {
  8885. MessageBox.Show(Local_HdInformation, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
  8886. }
  8887. /// <summary>
  8888. /// 量产模式删除当前选中文件
  8889. /// </summary>
  8890. /// <param name="sender"></param>
  8891. /// <param name="e"></param>
  8892. private void label112_DoubleClick(object sender, EventArgs e)
  8893. {
  8894. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8895. {
  8896. EnterForm1.ShowDialog();
  8897. try
  8898. {
  8899. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8900. {
  8901. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8902. {
  8903. try
  8904. {
  8905. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + comboBox_FacModeCfgFile.Text);
  8906. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".src");
  8907. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_FacModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_FacModeCfgFile.Text) + ".png");
  8908. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8909. }
  8910. catch (Exception)
  8911. {
  8912. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8913. }
  8914. }
  8915. else
  8916. {
  8917. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8918. }
  8919. }
  8920. }
  8921. catch (Exception)
  8922. {
  8923. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8924. }
  8925. }
  8926. }
  8927. /// <summary>
  8928. /// 检验模式删除当前选中文件
  8929. /// </summary>
  8930. /// <param name="sender"></param>
  8931. /// <param name="e"></param>
  8932. private void label138_DoubleClick(object sender, EventArgs e)
  8933. {
  8934. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  8935. {
  8936. EnterForm1.ShowDialog();
  8937. try
  8938. {
  8939. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  8940. {
  8941. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  8942. {
  8943. try
  8944. {
  8945. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + comboBox_CheckModeCfgFile.Text);
  8946. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".src");
  8947. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + comboBox_CheckModeCfgDate.Text + "\\" + Path.GetFileNameWithoutExtension(comboBox_CheckModeCfgFile.Text) + ".png");
  8948. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  8949. }
  8950. catch (Exception)
  8951. {
  8952. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8953. }
  8954. }
  8955. else
  8956. {
  8957. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8958. }
  8959. }
  8960. }
  8961. catch (Exception)
  8962. {
  8963. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  8964. }
  8965. }
  8966. }
  8967. /// <summary>
  8968. /// 读取整车信息2
  8969. /// </summary>
  8970. /// <param name="sender"></param>
  8971. /// <param name="e"></param>
  8972. private void button_ReadBikeParam2_Click(object sender, EventArgs e)
  8973. {
  8974. richTextBox_BikeParam2.Clear();
  8975. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4C00, null);
  8976. }
  8977. /// <summary>
  8978. /// 写入整车信息2
  8979. /// </summary>
  8980. /// <param name="sender"></param>
  8981. /// <param name="e"></param>
  8982. private void button_WriteBikeParam2_Click(object sender, EventArgs e)
  8983. {
  8984. var ConfigParam = new byte[34];
  8985. for (int i = 0; i < 34; i++)
  8986. ConfigParam[i] = 0;
  8987. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  8988. string[] strDataTemp = richTextBox_BikeParam2.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  8989. try
  8990. {
  8991. for (int i = 0; i < strDataTemp.Length; i++)
  8992. {
  8993. short wDataTemp = 0;
  8994. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8995. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  8996. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  8997. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  8998. }
  8999. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4D22, ConfigParam);
  9000. }
  9001. catch (Exception)
  9002. {
  9003. timer_500ms.Enabled = false;
  9004. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9005. timer_500ms.Enabled = true;
  9006. }
  9007. }
  9008. /// <summary>
  9009. /// 读取用户骑行参数
  9010. /// </summary>
  9011. /// <param name="sender"></param>
  9012. /// <param name="e"></param>
  9013. private void button_ReadUsrRideParam_Click(object sender, EventArgs e)
  9014. {
  9015. richTextBox_UsrRidesParam.Clear();
  9016. if (checkBox_UserRideParam_OBC.Checked)
  9017. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x4300, null);
  9018. else
  9019. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4A00, null);
  9020. }
  9021. /// <summary>
  9022. /// 写入用户骑行参数
  9023. /// </summary>
  9024. /// <param name="sender"></param>
  9025. /// <param name="e"></param>
  9026. private void button_WriteUsrRidetParam_Click(object sender, EventArgs e)
  9027. {
  9028. var ConfigParam = new byte[34];
  9029. for (int i = 0; i < 34; i++)
  9030. ConfigParam[i] = 0;
  9031. if (checkBox_UserRideParam_OBC.Checked)
  9032. {
  9033. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  9034. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9035. try
  9036. {
  9037. for (int i = 0; i < strDataTemp.Length; i++)
  9038. {
  9039. ConfigParam[i + 2] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9040. }
  9041. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4B22, ConfigParam);
  9042. }
  9043. catch (Exception)
  9044. {
  9045. timer_500ms.Enabled = false;
  9046. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9047. timer_500ms.Enabled = true;
  9048. }
  9049. }
  9050. else
  9051. {
  9052. string[] strDataTemp = richTextBox_UsrRidesParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  9053. try
  9054. {
  9055. for (int i = 0; i < strDataTemp.Length; i++)
  9056. {
  9057. ConfigParam[i] = Convert.ToByte(strDataTemp[i].Split('=')[1]);
  9058. }
  9059. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x4420, ConfigParam);
  9060. }
  9061. catch (Exception)
  9062. {
  9063. timer_500ms.Enabled = false;
  9064. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9065. timer_500ms.Enabled = true;
  9066. }
  9067. }
  9068. }
  9069. /// <summary>
  9070. /// 读取产品标签
  9071. /// </summary>
  9072. /// <param name="sender"></param>
  9073. /// <param name="e"></param>
  9074. private void button_ReadTag_Click(object sender, EventArgs e)
  9075. {
  9076. textBox_TagInfo.Text = "---";
  9077. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4E00, null);
  9078. }
  9079. /// <summary>
  9080. /// 写入产品标签
  9081. /// </summary>
  9082. /// <param name="sender"></param>
  9083. /// <param name="e"></param>
  9084. private void button_WriteTag_Click(object sender, EventArgs e)
  9085. {
  9086. string User = textBox_TagInfo.Text;
  9087. var UserArray = new byte[32];
  9088. for (ushort i = 0; i < User.Length; i++)
  9089. {
  9090. UserArray[i] = (byte)User[i];
  9091. }
  9092. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D20, UserArray);
  9093. }
  9094. /// <summary>
  9095. /// 上位机读取骑行历史
  9096. /// </summary>
  9097. /// <param name="sender"></param>
  9098. /// <param name="e"></param>
  9099. private void button_ReadRideLog_Click(object sender, EventArgs e)
  9100. {
  9101. textBox_ODO_KM.Text = "---";
  9102. textBox_ODO_TIME.Text = "---";
  9103. textBox_TRIP_KM.Text = "---";
  9104. textBox_TRIP_TIME.Text = "---";
  9105. textBox_OBC_TRIP_KM.Text = "";
  9106. textBox_OBC_TRIP_TIME.Text = "";
  9107. textBox_OBC_ODO_KM.Text = "";
  9108. textBox_OBC_ODO_TIME.Text = "";
  9109. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  9110. }
  9111. /// <summary>
  9112. /// 上位机写入骑行历史
  9113. /// </summary>
  9114. /// <param name="sender"></param>
  9115. /// <param name="e"></param>
  9116. private void button_WriteRideLog_Click(object sender, EventArgs e)
  9117. {
  9118. UInt32 Data;
  9119. var UserArray = new byte[16];
  9120. try
  9121. {
  9122. Data = Convert.ToUInt32(textBox_ODO_KM.Text);
  9123. UserArray[0] = (byte)(Data & 0xFF);
  9124. UserArray[1] = (byte)(Data >> 8);
  9125. UserArray[2] = (byte)(Data >> 16);
  9126. UserArray[3] = (byte)(Data >> 24);
  9127. Data = Convert.ToUInt32(textBox_ODO_TIME.Text);
  9128. UserArray[4] = (byte)(Data & 0xFF);
  9129. UserArray[5] = (byte)(Data >> 8);
  9130. UserArray[6] = (byte)(Data >> 16);
  9131. UserArray[7] = (byte)(Data >> 24);
  9132. Data = Convert.ToUInt32(textBox_TRIP_KM.Text);
  9133. UserArray[8] = (byte)(Data & 0xFF);
  9134. UserArray[9] = (byte)(Data >> 8);
  9135. UserArray[10] = (byte)(Data >> 16);
  9136. UserArray[11] = (byte)(Data >> 24);
  9137. Data = Convert.ToUInt32(textBox_TRIP_TIME.Text);
  9138. UserArray[12] = (byte)(Data & 0xFF);
  9139. UserArray[13] = (byte)(Data >> 8);
  9140. UserArray[14] = (byte)(Data >> 16);
  9141. UserArray[15] = (byte)(Data >> 24);
  9142. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B10, UserArray);
  9143. }
  9144. catch (Exception ex)
  9145. {
  9146. MessageBox.Show("数据格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9147. }
  9148. }
  9149. /// <summary>
  9150. /// 获取删除配置文件日期列表
  9151. /// </summary>
  9152. /// <param name="sender"></param>
  9153. /// <param name="e"></param>
  9154. private void toolStripTextBox_DelCfgFile_Click(object sender, EventArgs e)
  9155. {
  9156. string[] DateList = { "" };
  9157. //网络断开时直接退出
  9158. if (!myFtp.IsNetConnected)
  9159. return;
  9160. //从服务器更新日期列表
  9161. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName);
  9162. toolStripTextBox_DelCfgFile.Items.Clear();
  9163. //日期列表加载,显示最近30条
  9164. if (DateList.Length > 30)
  9165. {
  9166. toolStripTextBox_DelCfgFile.Items.Add("支持最近30条");
  9167. toolStripTextBox_DelCfgFile.Items.Add("-----");
  9168. }
  9169. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9170. {
  9171. toolStripTextBox_DelCfgFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9172. }
  9173. }
  9174. /// <summary>
  9175. /// 删除指定配置文件
  9176. /// </summary>
  9177. /// <param name="sender"></param>
  9178. /// <param name="e"></param>
  9179. private void toolStripTextBox_DelCfgFile_SelectedIndexChanged(object sender, EventArgs e)
  9180. {
  9181. //提示输入文件名
  9182. Scan scan_form = new Scan();
  9183. scan_form.ShowDialog();
  9184. do
  9185. {
  9186. if (scan_form.textBox_Scan.Text == string.Empty)
  9187. {
  9188. timer_500ms.Enabled = false;
  9189. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9190. timer_500ms.Enabled = true;
  9191. break;
  9192. }
  9193. string DelFile = scan_form.textBox_Scan.Text;
  9194. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9195. {
  9196. EnterForm1.ShowDialog();
  9197. try
  9198. {
  9199. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9200. {
  9201. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9202. {
  9203. try
  9204. {
  9205. if (DelFile.Contains("."))
  9206. DelFile = Path.GetFileNameWithoutExtension(DelFile);
  9207. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".ttcfg");
  9208. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".src");
  9209. myFtp.DeleteFile(toolStripTextBox_ServerPath.Text + "\\" + localInfo.CfgPathName + "\\" + toolStripTextBox_DelCfgFile.Text + "\\" + DelFile + ".png");
  9210. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9211. }
  9212. catch (Exception)
  9213. {
  9214. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9215. }
  9216. }
  9217. else
  9218. {
  9219. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9220. }
  9221. }
  9222. }
  9223. catch (Exception)
  9224. {
  9225. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9226. }
  9227. }
  9228. } while (false);
  9229. }
  9230. /// <summary>
  9231. /// 获取删除样机测试记录日期列表
  9232. /// </summary>
  9233. /// <param name="sender"></param>
  9234. /// <param name="e"></param>
  9235. private void toolStripTextBox_DelLogFile_Click(object sender, EventArgs e)
  9236. {
  9237. string[] DateList = { "" };
  9238. //网络断开时直接退出
  9239. if (!myFtp.IsNetConnected)
  9240. return;
  9241. //从服务器更新日期列表
  9242. DateList = myFtp.GetDirectoryList(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName);
  9243. toolStripTextBox_DelLogFile.Items.Clear();
  9244. //日期列表加载,显示最近30天
  9245. if (DateList.Length > 30)
  9246. {
  9247. toolStripTextBox_DelLogFile.Items.Add("支持最近30条");
  9248. toolStripTextBox_DelLogFile.Items.Add("-----");
  9249. }
  9250. for (int i = (DateList.Length > 30) ? (DateList.Length - 30) : 0; i < DateList.Length; i++)//显示最近30个日期
  9251. {
  9252. toolStripTextBox_DelLogFile.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  9253. }
  9254. }
  9255. /// <summary>
  9256. /// 删除指定的样机测试记录
  9257. /// </summary>
  9258. /// <param name="sender"></param>
  9259. /// <param name="e"></param>
  9260. private void toolStripTextBox_DelLogFile_SelectedIndexChanged(object sender, EventArgs e)
  9261. {
  9262. //提示输入文件名
  9263. Scan scan_form = new Scan();
  9264. scan_form.ShowDialog();
  9265. do
  9266. {
  9267. if (scan_form.textBox_Scan.Text == string.Empty)
  9268. {
  9269. timer_500ms.Enabled = false;
  9270. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9271. timer_500ms.Enabled = true;
  9272. break;
  9273. }
  9274. string DelFile = scan_form.textBox_Scan.Text;
  9275. if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9276. {
  9277. EnterForm1.ShowDialog();
  9278. try
  9279. {
  9280. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  9281. {
  9282. if (EnterForm1.comboBox_User.Text.Contains("工程"))
  9283. {
  9284. try
  9285. {
  9286. //删除指定目录下面所有文件和文件夹
  9287. myFtp.DelDirectoryWithAll(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9288. myFtp.RemoveDirectory(toolStripTextBox_ServerPath.Text + "\\" + localInfo.SampleFileName + "\\" + toolStripTextBox_DelLogFile.Text + "\\" + DelFile);
  9289. MessageBoxTimeOut.Show("删除成功", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9290. }
  9291. catch (Exception)
  9292. {
  9293. MessageBoxTimeOut.Show("删除异常", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9294. }
  9295. }
  9296. else
  9297. {
  9298. MessageBoxTimeOut.Show("权限不支持!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9299. }
  9300. }
  9301. }
  9302. catch (Exception)
  9303. {
  9304. MessageBoxTimeOut.Show("用户不存在或密码错误!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Error);
  9305. }
  9306. }
  9307. } while (false);
  9308. }
  9309. /// <summary>
  9310. /// CAN协议选择
  9311. /// </summary>
  9312. /// <param name="sender"></param>
  9313. /// <param name="e"></param>
  9314. private void cANToolStripMenuItem_Click(object sender, EventArgs e)
  9315. {
  9316. cANToolStripMenuItem.Checked= true;
  9317. uARTToolStripMenuItem.Checked = false;
  9318. UART协议ToolStripMenuItem.Visible = false;
  9319. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9320. }
  9321. /// <summary>
  9322. /// UART协议选择
  9323. /// </summary>
  9324. /// <param name="sender"></param>
  9325. /// <param name="e"></param>
  9326. private void uARTToolStripMenuItem_Click(object sender, EventArgs e)
  9327. {
  9328. cANToolStripMenuItem.Checked = false;
  9329. uARTToolStripMenuItem.Checked = true;
  9330. UART协议ToolStripMenuItem.Visible = true;
  9331. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9332. }
  9333. /// <summary>
  9334. /// 清除流水号
  9335. /// </summary>
  9336. /// <param name="sender"></param>
  9337. /// <param name="e"></param>
  9338. private void label131_DoubleClick(object sender, EventArgs e)
  9339. {
  9340. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9341. {
  9342. label_FacModeSerial.Text = "0";
  9343. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, label_FacModeSerial.Text);
  9344. }
  9345. }
  9346. /// <summary>
  9347. /// 清除流水号
  9348. /// </summary>
  9349. /// <param name="sender"></param>
  9350. /// <param name="e"></param>
  9351. private void label135_DoubleClick(object sender, EventArgs e)
  9352. {
  9353. if (MessageBox.Show("确认清零流水号?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9354. {
  9355. label_CheckModeSerial.Text = "0";
  9356. File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, label_CheckModeSerial.Text);
  9357. }
  9358. }
  9359. /// <summary>
  9360. /// 打开自动更新
  9361. /// </summary>
  9362. /// <param name="sender"></param>
  9363. /// <param name="e"></param>
  9364. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  9365. {
  9366. 打开ToolStripMenuItem.Checked = true;
  9367. 关闭ToolStripMenuItem.Checked = false;
  9368. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9369. }
  9370. /// <summary>
  9371. /// 关闭自动更新
  9372. /// </summary>
  9373. /// <param name="sender"></param>
  9374. /// <param name="e"></param>
  9375. private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
  9376. {
  9377. 打开ToolStripMenuItem.Checked = false;
  9378. 关闭ToolStripMenuItem.Checked = true;
  9379. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9380. }
  9381. /// <summary>
  9382. /// 显示完整配置文件
  9383. /// </summary>
  9384. /// <param name="sender"></param>
  9385. /// <param name="e"></param>
  9386. private void comboBox_FacModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9387. {
  9388. // 创建the ToolTip
  9389. ToolTip toolTip1 = new ToolTip();
  9390. // 设置显示样式
  9391. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9392. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9393. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9394. toolTip1.ShowAlways = true;//是否显示提示框
  9395. // 设置伴随的对象.
  9396. toolTip1.SetToolTip(this.comboBox_FacModeCfgFile, comboBox_FacModeCfgFile.Text);//设置故障内容显示
  9397. }
  9398. /// <summary>
  9399. /// 显示完整配置文件
  9400. /// </summary>
  9401. /// <param name="sender"></param>
  9402. /// <param name="e"></param>
  9403. private void comboBox_CheckModeCfgFile_MouseHover_1(object sender, EventArgs e)
  9404. {
  9405. // 创建the ToolTip
  9406. ToolTip toolTip1 = new ToolTip();
  9407. // 设置显示样式
  9408. toolTip1.AutoPopDelay = 3000;//提示信息的可见时间
  9409. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  9410. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  9411. toolTip1.ShowAlways = true;//是否显示提示框
  9412. // 设置伴随的对象.
  9413. toolTip1.SetToolTip(this.comboBox_CheckModeCfgFile, comboBox_CheckModeCfgFile.Text);//设置故障内容显示
  9414. }
  9415. /// <summary>
  9416. /// 手动发送指令
  9417. /// </summary>
  9418. /// <param name="sender"></param>
  9419. /// <param name="e"></param>
  9420. private void 发送指令ToolStripMenuItem_Click(object sender, EventArgs e)
  9421. {
  9422. //提示
  9423. Scan scan_form = new Scan();
  9424. scan_form.label1.Text = "按照16进制填写,相邻字节用空格隔开,依次填写ID、Mode、Cmd、Data\r\n例如:07 31 16 22 05 01 02 03 04 05";
  9425. scan_form.ShowDialog();
  9426. //发送写入的指令,填写ID、类型、命令字、数据
  9427. do
  9428. {
  9429. if (scan_form.textBox_Scan.Text == string.Empty)
  9430. {
  9431. timer_500ms.Enabled = false;
  9432. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  9433. timer_500ms.Enabled = true;
  9434. break;
  9435. }
  9436. //输入文本转换为字节流
  9437. var InputData = new byte[256];
  9438. InputData = mySerialProcess.HexStringToBytes(scan_form.textBox_Scan.Text, true);
  9439. //ID
  9440. ushort ID;
  9441. ID = (ushort)((InputData[0] << 8) + InputData[1]);
  9442. //Mode
  9443. byte Mode;
  9444. Mode = InputData[2];
  9445. //Cmd
  9446. ushort Cmd;
  9447. Cmd = (ushort)((InputData[3] << 8) + InputData[4]);
  9448. //Data
  9449. var Data = new byte[Cmd & 0x00FF];
  9450. for (int i = 0; i < (Cmd & 0x00FF); i++)
  9451. Data[i] = InputData[5 + i];
  9452. //发送数据
  9453. mySerialProcess.SendCmdWithoutNotice(ID, Mode, Cmd, Data);
  9454. } while (false);
  9455. }
  9456. /// <summary>
  9457. /// 启动位置传感器校准
  9458. /// </summary>
  9459. /// <param name="sender"></param>
  9460. /// <param name="e"></param>
  9461. private void button_AngleCalStart_Click(object sender, EventArgs e)
  9462. {
  9463. for (int i = 0; i < 7; i++)
  9464. for (int j = 0; j < 6; j++)
  9465. {
  9466. dataGridView_AngleCal.Rows[i].Cells[j + 1].Value = "";
  9467. }
  9468. foreach (Control cr in tabPage_AngleCal.Controls)
  9469. {
  9470. if (cr is TextBox)
  9471. {
  9472. if ((cr != textBox_AngleDiffTh) && (cr != textBox_AngleZeroTh))
  9473. cr.Text = "";
  9474. }
  9475. }
  9476. var Data = new byte[2];
  9477. mySerialProcess.SendCmd((ushort)0x751, (byte)0x0C, (ushort)0x5002, Data);
  9478. }
  9479. /// <summary>
  9480. /// 导出位置传感器校准数据
  9481. /// </summary>
  9482. /// <param name="sender"></param>
  9483. /// <param name="e"></param>
  9484. private void button_AngleExportData_Click(object sender, EventArgs e)
  9485. {
  9486. //读出产品信息
  9487. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  9488. Delay_ms(200);
  9489. SaveFileDialog sfd = new SaveFileDialog
  9490. {
  9491. FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + "位置传感器角度数据_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt",
  9492. Filter = "文本文档(*.txt)|*.txt",
  9493. Title = "Save"
  9494. };
  9495. if (sfd.ShowDialog() != DialogResult.OK)
  9496. {
  9497. return;
  9498. }
  9499. string filepath = sfd.FileName;
  9500. FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
  9501. using (StreamWriter sw = new StreamWriter(fs))
  9502. {
  9503. sw.Write("标准值 ");
  9504. sw.Write("60.00 ");
  9505. sw.Write("120.00 ");
  9506. sw.Write("180.00 ");
  9507. sw.Write("240.00 ");
  9508. sw.Write("300.00 ");
  9509. sw.Write("360.00 ");
  9510. for (int i = 0; i < 42; i++)
  9511. {
  9512. if ((i % 6 == 0))
  9513. {
  9514. sw.Write("\r\n" + "采集值" + (i / 6 + 1).ToString() + " ");
  9515. }
  9516. sw.Write(AngledataRecord[i] + " ");
  9517. }
  9518. sw.Write("\r\n" + "历史零点位置 " + textBox_AngleZeroInit.Text);
  9519. sw.Write("\r\n" + "当前零点位置 " + textBox_AngleZeroCur.Text);
  9520. sw.Write("\r\n" + "零点误差 " + textBox_AngleZeroDiff.Text);
  9521. sw.Write("\r\n" + "最小偏差值 " + textBox_AngleDiffMin.Text);
  9522. sw.Write("\r\n" + "最大偏差值 " + textBox_AngleDiffMax.Text);
  9523. sw.Write("\r\n" + "平均偏差值 " + textBox_AngleDiffAvg.Text);
  9524. sw.Flush();
  9525. }
  9526. fs.Close();
  9527. }
  9528. /// <summary>
  9529. /// 写入校准数据
  9530. /// </summary>
  9531. /// <param name="sender"></param>
  9532. /// <param name="e"></param>
  9533. private void button_AngleWrite_Click(object sender, EventArgs e)
  9534. {
  9535. if ((textBox_AngleDiffAvg.Text == "") || (textBox_AngleZeroInit.Text == ""))
  9536. {
  9537. timer_500ms.Enabled = false;
  9538. MessageBox.Show("请先启动校准,以确认校准数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  9539. timer_500ms.Enabled = true;
  9540. return;
  9541. }
  9542. timer_500ms.Enabled = false;
  9543. string str1 = "确认校准数据,历史零点: " + textBox_AngleZeroInit.Text + ", 偏差平均值: " + textBox_AngleDiffAvg.Text;
  9544. if (MessageBox.Show(str1, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9545. {
  9546. var SaveFlag = new byte[4];
  9547. for (int i = 0; i < 4; i++)
  9548. SaveFlag[i] = 0;
  9549. SaveFlag[0] = (byte)(1);
  9550. double data1 = Convert.ToDouble(textBox_AngleZeroInit.Text) - Convert.ToDouble(textBox_AngleDiffAvg.Text);
  9551. if (data1 > 360)
  9552. {
  9553. data1 -= 360;
  9554. }
  9555. else if (data1 < -360)
  9556. {
  9557. data1 += 360;
  9558. }
  9559. Int16 data2 = (Int16)(data1 * 32768 / 360);
  9560. SaveFlag[2] = (byte)(data2);
  9561. SaveFlag[3] = (byte)(data2 >> 8);
  9562. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x5104, SaveFlag);
  9563. }
  9564. else
  9565. MessageBoxTimeOut.Show("写入取消", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  9566. timer_500ms.Enabled = true;
  9567. }
  9568. /// <summary>
  9569. /// 存储允许偏差
  9570. /// </summary>
  9571. /// <param name="sender"></param>
  9572. /// <param name="e"></param>
  9573. private void textBox_AngleDiffTh_KeyDown(object sender, KeyEventArgs e)
  9574. {
  9575. if (e.KeyCode == Keys.Enter)
  9576. {
  9577. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9578. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9579. }
  9580. }
  9581. /// <summary>
  9582. /// 存储零点允许偏差
  9583. /// </summary>
  9584. /// <param name="sender"></param>
  9585. /// <param name="e"></param>
  9586. private void textBox_AngleZeroTh_KeyDown(object sender, KeyEventArgs e)
  9587. {
  9588. if (e.KeyCode == Keys.Enter)
  9589. {
  9590. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9591. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9592. }
  9593. }
  9594. /// <summary>
  9595. /// 删除服务器配置文件
  9596. /// </summary>
  9597. /// <param name="sender"></param>
  9598. /// <param name="e"></param>
  9599. private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
  9600. {
  9601. if (MessageBox.Show("重置后软件自动关闭,确认重置?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  9602. {
  9603. if(File.Exists(localInfo.LocalPath + localInfo.ServerCfgFileName))
  9604. File.Delete(localInfo.LocalPath + localInfo.ServerCfgFileName);
  9605. if(File.Exists(localInfo.LocalPath + localInfo.ConfigFileName))
  9606. File.Delete(localInfo.LocalPath + localInfo.ConfigFileName);
  9607. System.Environment.Exit(0);
  9608. }
  9609. }
  9610. /// <summary>
  9611. /// 按下Enter保存数据
  9612. /// </summary>
  9613. /// <param name="sender"></param>
  9614. /// <param name="e"></param>
  9615. private void toolStripTextBox_AngleAvgMax_KeyDown(object sender, KeyEventArgs e)
  9616. {
  9617. textBox_AngleDiffTh.Text = toolStripTextBox_AngleAvgMax.Text;
  9618. if (e.KeyCode == Keys.Enter)
  9619. {
  9620. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9621. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9622. }
  9623. }
  9624. /// <summary>
  9625. /// 按下Enter保存数据
  9626. /// </summary>
  9627. /// <param name="sender"></param>
  9628. /// <param name="e"></param>
  9629. private void toolStripTextBox_AngleZeroMax_KeyDown(object sender, KeyEventArgs e)
  9630. {
  9631. textBox_AngleZeroTh.Text = toolStripTextBox_AngleZeroMax.Text;
  9632. if (e.KeyCode == Keys.Enter)
  9633. {
  9634. ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
  9635. MessageBox.Show("数据已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  9636. }
  9637. }
  9638. /// <summary>
  9639. /// 打开或关闭指令窗口
  9640. /// </summary>
  9641. /// <param name="sender"></param>
  9642. /// <param name="e"></param>
  9643. private void 指令调试ToolStripMenuItem_Click(object sender, EventArgs e)
  9644. {
  9645. if (指令调试ToolStripMenuItem.Checked == false)
  9646. {
  9647. if (DebugForm.debug1 == null || DebugForm.debug1.IsDisposed)
  9648. {
  9649. DebugForm.debug1 = new DebugForm();
  9650. DebugForm.debug1.Show();
  9651. this.DebugWindowIsOpen = true;
  9652. }
  9653. else
  9654. {
  9655. DebugForm.debug1.Activate();
  9656. this.DebugWindowIsOpen = true;
  9657. }
  9658. 指令调试ToolStripMenuItem.Checked = true;
  9659. }
  9660. else
  9661. {
  9662. if (this.DebugWindowIsOpen == true)
  9663. {
  9664. DebugForm.debug1.Close();
  9665. this.DebugWindowIsOpen = false;
  9666. this.DebugDataDisplayEnable = false;
  9667. }
  9668. 指令调试ToolStripMenuItem.Checked = false;
  9669. }
  9670. }
  9671. }
  9672. }