mainForm.cs 362 KB

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