1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Windows.Forms;
- namespace Welling_Motor_Debug_Tool
- {
- public partial class mainForm : Form
- {
- #region 变量定义
- //串口实例
- Serial_Process mySerialProcess = new Serial_Process();
- string PortNumSave = "";
- string PortBaudrateSave = "";
- //本地信息定义
- LocalInfo localInfo = new LocalInfo();
- //FTP实例
- ftp myFtp = new ftp();
- //MC运行信息超时计数
- bool MC_RunInfo_Refresh = false;
- ushort MC_RunInfo_Refresh_Cnt = 0;
- //MC调试信息超时计数
- bool MC_DebugInfo_Refresh = false;
- ushort MC_DebugInfo_Refresh_Cnt = 0;
- //MC故障码超时计数
- bool MC_ErrorCode_Refresh = false;
- ushort MC_ErrorCode_Refresh_Cnt = 0;
- //配置参数实例
- Params myParams = new Params();
- //记录文件名称
- string RunInfoSaveFilename = "";
- //BMS运行信息超时计数
- bool BMS_RunInfo_Refresh = false;
- ushort BMS_RunInfo_Refresh_Cnt = 0;
- //生产模式关机指令反馈状态
- bool PowerOffAckStatus = false;
- //登录窗口
- public static Login EnterForm1 = new Login();
- #endregion
- #region 故障日志结构体定义
- //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
- [StructLayout(LayoutKind.Sequential)]
- public struct MC_ErrorLogSaveInfo_Struct_t
- {
- public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
- public UInt16 NotesInfo1; //备注信息1,地址偏移 2
- public UInt16 NotesInfo2; //备注信息2,地址偏移 4
- public UInt16 NotesInfo3; //备注信息3,地址偏移 6
- public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
- public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
- //电机运行信息,占用空间32bytes
- [StructLayout(LayoutKind.Sequential)]
- public struct MC_RunInfo_Struct_t
- {
- public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
- public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
- public ushort Power; //电功率 1W,地址偏移4
- public ushort BusVoltage; //母线电压 1mV,地址偏移6
- public ushort BusCurrent; //母线电流 1mA,地址偏移8
- public byte Cadence; //踏频 1rpm,地址偏移10
- public byte Torque; //踩踏力矩 1Nm,地址偏移11
- public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
- public byte GearSt; //助力档位,地址偏移13
- public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
- public byte SOC; //剩余电量 1%,地址偏移15
- public ushort RemainDistance; //续航里程 1km,地址偏移16
- public ushort Torque_AD; //力矩寄存器,地址偏移18
- public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
- public byte T_PCB; //PCB温度 +40℃,地址偏移21
- public byte T_Coil; //绕组温度 +40℃,地址偏移22
- public byte T_MCU; //MCU温度 +40℃,地址偏移23
- public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
- public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
- public UInt32 RS; //预留 4bytes
- };
- [MarshalAs(UnmanagedType.Struct)]
- public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
- //控制变量
- public Int16 IqCurrent; //Pu, 地址偏移 48
- public Int16 IqVoltage; //Pu, 地址偏移 50
- public Int16 IdCurrent; //Pu, 地址偏移 52
- public Int16 IdVoltage; //Pu, 地址偏移 54
- //状态机
- public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
- //预留
- public UInt16 RS1;
- public UInt16 RS2;
- public UInt16 RS3;
- };
- #endregion
- public mainForm()
- {
- InitializeComponent();
- //系统登录
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if ((EnterForm1.comboBox_User.Text == "武汉Wuhan") || (EnterForm1.comboBox_User.Text == "越南Vietnam"))
- {
- 其它配置项ToolStripMenuItem.Visible = false;
- 配置ToolStripMenuItem.Visible = false;
- tabPage_MotorParam.Parent = null;
- tabPage_BikeParam.Parent = null;
- tabPage_ControlParam.Parent = null;
- tabPage_SensorParam.Parent = null;
- tabPage_AssistParam.Parent = null;
- tabPage_DebugParam.Parent = null;
- tabPage_RecordInfo.Parent = null;
- tabPage_OtherInfo.Parent = null;
- tabPage_OBC.Parent = null;
- tabPage_RAMorFLASH.Parent = null;
- tabPage_FactoryMode.Parent = null;
- tabPage_ProductMode_Write.Parent = tabControl1;
- tabPage_RunInfo.Parent = tabControl2;
- tabPage_DebugInfo.Parent = null;
- }
- else if (EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 其它配置项ToolStripMenuItem.Visible = true;
- 配置ToolStripMenuItem.Visible = true;
- tabPage_MotorParam.Parent = tabControl1;
- tabPage_BikeParam.Parent = tabControl1;
- tabPage_ControlParam.Parent = tabControl1;
- tabPage_SensorParam.Parent = tabControl1;
- tabPage_AssistParam.Parent = tabControl1;
- tabPage_DebugParam.Parent = tabControl1;
- tabPage_RecordInfo.Parent = tabControl1;
- tabPage_OtherInfo.Parent = tabControl1;
- tabPage_OBC.Parent = tabControl1;
- tabPage_RAMorFLASH.Parent = null;
- tabPage_FactoryMode.Parent = tabControl1;
- tabPage_ProductMode_Write.Parent = tabControl1;
- tabPage_RunInfo.Parent = tabControl2;
- tabPage_DebugInfo.Parent = null;
- }
- else if (EnterForm1.comboBox_User.Text == "研发RD")
- {
- 其它配置项ToolStripMenuItem.Visible = true;
- 配置ToolStripMenuItem.Visible = true;
- tabPage_MotorParam.Parent = tabControl1;
- tabPage_BikeParam.Parent = tabControl1;
- tabPage_ControlParam.Parent = tabControl1;
- tabPage_SensorParam.Parent = tabControl1;
- tabPage_AssistParam.Parent = tabControl1;
- tabPage_DebugParam.Parent = tabControl1;
- tabPage_RecordInfo.Parent = tabControl1;
- tabPage_OtherInfo.Parent = tabControl1;
- tabPage_OBC.Parent = tabControl1;
- tabPage_RAMorFLASH.Parent = tabControl1;
- tabPage_FactoryMode.Parent = tabControl1;
- tabPage_ProductMode_Write.Parent = tabControl1;
- tabPage_RunInfo.Parent = tabControl2;
- tabPage_DebugInfo.Parent = tabControl2;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- System.Environment.Exit(0);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- System.Environment.Exit(0);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- System.Environment.Exit(0);
- }
- //检查配置文件
- if (!Directory.Exists(localInfo.LocalPath))
- {
- Directory.CreateDirectory(localInfo.LocalPath);
- }
- if (File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
- {
- //打开文件
- StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
- string sLine = "";
- ArrayList array_CfgInfo = new ArrayList();
- array_CfgInfo.Clear();
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- array_CfgInfo.Add(sLine);
- }
- objReader.Close();
- //解析配置文件
- try
- {
- //Port Set
- PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
- PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
- 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
- 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
- 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
- //Option
- 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
- 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
- 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
- //Server Set
- toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
- toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
- toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
- toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
- toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
- //MacInfo
- toolStripTextBox_MAC.Text= array_CfgInfo[19].ToString().Split(':')[1];
- toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
- toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
- toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
- //Log Address
- textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
- textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
- }
- catch (System.Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
-
- }
- else //不存在配置文件,生成文件写入默认值
- {
- ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- //配置网络FTP服务器
- myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text);
- //创建线程,定时检测网络连接状态
- Thread th = new Thread(NetworkCheck);
- th.IsBackground = true;
- th.Start();
- }
- /// <summary>
- /// 检查网络状态线程
- /// </summary>
- private void NetworkCheck()
- {
- //初始化第一次连接FTP服务器
- bool Result = myFtp.CheckFtp();
- this.Invoke((EventHandler)(delegate
- {
- if (Result == true)//服务器连接成功
- {
- label_Server_ComStatus.Text = "网络已连接";
- label_ServerStatus.BackColor = Color.Green;
- myFtp.IsNetConnected = true;
- }
- else//服务器连接失败
- {
- label_Server_ComStatus.Text = "网络断开";
- label_ServerStatus.BackColor = Color.Red;
- myFtp.IsNetConnected = false;
- if (允许ToolStripMenuItem.Checked == false) ///不允许离线使用,自动关闭
- {
- timer_1s.Enabled = false;
- MessageBox.Show("网络断开,将自动关闭!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- this.Close();
- }
- else //离线使用
- {
- timer_1s.Enabled = false;
- MessageBox.Show("网络断开,离线使用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- }
- }));
- //创建定时器,定时30s检查网络
- System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
- timer_CheckNet.Enabled = true;
- timer_CheckNet.Interval = 30000;
- timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
- timer_CheckNet.Start();
- while (true)
- {
- Thread.Sleep(1);
- }
- }
- /// <summary>
- /// 线程中定时任务,检查网络状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_CheckNet_Tick(object sender, EventArgs e)
- {
- //连接FTP服务器
- bool Result = myFtp.CheckFtp();
- this.Invoke((EventHandler)(delegate
- {
- if (Result == true)//服务器连接成功
- {
- label_Server_ComStatus.Text = "网络已连接";
- label_ServerStatus.BackColor = Color.Green;
- myFtp.IsNetConnected = true;
- }
- else//服务器连接失败
- {
- label_Server_ComStatus.Text = "网络断开";
- label_ServerStatus.BackColor = Color.Red;
- myFtp.IsNetConnected = false;
- }
- }));
- }
- #region 非独占性延时函数
- public static void Delay_ms(int milliSecond)
- {
- int start = Environment.TickCount;
- while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
- {
- Application.DoEvents();
- }
- }
- #endregion
- private void Form1_Load(object sender, System.EventArgs e)
- {
- //页面初始化
- label_BuildTime.Text= "编译时间:"+ System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
- label_Computername.Text = "用户名:" + System.Environment.UserName;
- //下拉控件初始值设定
- comboBox_WorkMode.SelectedIndex = 0;
- comboBox_GearSt.SelectedIndex = 0;
- comboBox_LightSwitch.SelectedIndex = 1;
- comboBox_OBC_SetGearST.SelectedIndex = 0;
- comboBox_OBC_LightSw.SelectedIndex = 1;
- comboBox_AssistTorque.SelectedIndex = 0;
- comboBox_AssistCadence.SelectedIndex = 0;
- //combobox事件定义
- this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
- this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
- this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
- this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
- this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
- //端口设置
- mySerialProcess.Init();
- toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
- if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
- {
- try
- {
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
- toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
- PortConnect();
- }
- catch (System.Exception)
- {
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
- toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
- timer_1s.Enabled = false;
- MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- }
- }
- else //否则采用默认值
- {
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
- toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
- }
-
- //创建线程,定时解析数据
- Thread th = new Thread(Task_SerialProcess);
- th.IsBackground = true;
- th.Start();
- }
- #region 结构体与字节流相互转换
- public static class MyConverter
- {
- /// <summary>
- /// 由结构体转换为byte数组
- /// </summary>
- public static byte[] StructureToByte<T>(T structure)
- {
- int size = Marshal.SizeOf(typeof(T));
- byte[] buffer = new byte[size];
- IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
- try
- {
- Marshal.StructureToPtr(structure, bufferIntPtr, true);
- Marshal.Copy(bufferIntPtr, buffer, 0, size);
- }
- finally
- {
- Marshal.FreeHGlobal(bufferIntPtr);
- }
- return buffer;
- }
- /// <summary>
- /// 由byte数组转换为结构体
- /// </summary>
- public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
- {
- object structure = null;
- int size = Marshal.SizeOf(typeof(T));
- IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
- try
- {
- Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
- structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
- }
- finally
- {
- Marshal.FreeHGlobal(allocIntPtr);
- }
- return (T)structure;
- }
- }
- #endregion
- #region 故障日志解析显示
- private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
- {
- string SaveData = "";
- //Log1
- if (Log1.Error_Index != 0xFFFF)
- {
- SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
- SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
- SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
- SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
- SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
- SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
- SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
- SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
- SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
- SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
- SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
- SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
- SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
- SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
- SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
- SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
- SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
- if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
- {
- SaveData += "续航:" + "---km" + ", ";
- }
- else
- {
- SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
- }
- SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
- SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
- SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
- SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
- SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
- SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
- SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
- SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
- SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
- SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
- SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
- SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
- SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
- SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
- SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
- SaveData += "\r\n\r\n";
- richTextBox_Record.AppendText(SaveData);
- SaveData = "";
- }
- //Log2
- if (Log2.Error_Index != 0xFFFF)
- {
- SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
- SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
- SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
- SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
- SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
- SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
- SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
- SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
- SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
- SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
- SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
- SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
- SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
- SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
- SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
- SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
- SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
- if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
- {
- SaveData += "续航:" + "---km" + ", ";
- }
- else
- {
- SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
- }
- SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
- SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
- SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
- SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
- SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
- SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
- SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
- SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
- SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
- SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
- SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
- SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
- SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
- SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
- SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
- SaveData += "\r\n\r\n";
- richTextBox_Record.AppendText(SaveData);
- SaveData = "";
- }
- }
- #endregion
- #region 串口数据解析线程
- /// <summary>
- /// 串口数据解析线程
- /// </summary>
- private void Task_SerialProcess()
- {
- //创建定时器,定时读取串口数据
- System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
- timer_ReadSerial.Enabled = true;
- timer_ReadSerial.Interval = 20;
- timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
- timer_ReadSerial.Start();
- while (true)
- {
- Thread.Sleep(1);
- };
- }
- /// <summary>
- /// 串口解析定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_ReadSerial_Tick(object sender, EventArgs e)
- {
- //串口解析
- Serial_process(mySerialProcess.buffer);
- }
- #endregion
- #region 数据解析
- public void Serial_process(List<byte> buffer)
- {
- byte DataNum = 0; //记录每条命令数据段的长度
- ushort PackageID, Cmd;
- byte[] Data = new byte[1024];
- while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
- {
- if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
- {
- PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
- if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
- {
- int CmdLen = buffer[5];
- if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
- buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
- while (CmdLen > 0) //读取命令段
- {
- Cmd = (ushort)(buffer[0] * 256 + buffer[1]);
- DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
- if (DataNum <= (CmdLen - 2))
- {
- for (int i = 0; i < DataNum; i++)
- {
- Data[i] = buffer[i + 2];
- }
- DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
- buffer.RemoveRange(0, DataNum);//移除处理过的数据段
- CmdLen -= (DataNum + 2);
- if (CmdLen < 2)
- {
- buffer.RemoveRange(0, CmdLen + 2);
- return;
- }
- }
- else
- {
- buffer.RemoveRange(0, CmdLen + 11);
- }
- }
- }
- else
- {
- buffer.RemoveAt(0);//ID不对
- }
- }
- else
- {
- buffer.RemoveAt(0);//帧头不对,删除帧头高字节
- }
- }
- }
- private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
- {
- int DataTemp;
- ushort uData16;
- unchecked
- {
- this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
- }
- #region 解析发送给CDL的指令
- if (ID == 0x7FF)
- {
- switch (CmdTemp)
- {
- case 0x1100://
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //CDL连接成功
- mySerialProcess.CDL_Online_Flag = true;
- MessageBox.Show("连接成功!", "提示");
- groupBox1.Visible = true;
- groupBox3.Visible = true;
- tabControl2.Visible = true;
- label_StarInfo.Visible = false;
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析电机的命令
- else if ((ID == 0x715) || (ID == 0x710))
- {
- switch (CmdTemp)
- {
- case 0x1020://电机运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_RunInfo_Refresh = true;
- //车速
- DataTemp = (int)(Data[1] * 256 + Data[0]);
- textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
- //输出转速
- DataTemp = (ushort)(Data[3] * 256 + Data[2]);
- textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
- Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
- Class_MotorSpeed.Data = DataTemp;
- //电功率
- DataTemp = (ushort)(Data[5] * 256 + Data[4]);
- textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
- //母线电压
- DataTemp = (ushort)(Data[7] * 256 + Data[6]);
- textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
- //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
- //母线电流
- DataTemp = (short)(Data[9] * 256 + Data[8]);
- textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
- //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
- Class_CurrentData.String = textBox_RunInfo_Current.Text;
- Class_CurrentData.Data = DataTemp;
- //踏频
- DataTemp = (ushort)(Data[10]);
- textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
- Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
- Class_CadenceData.Data = DataTemp;
- //踩踏力矩
- DataTemp = (ushort)(Data[11]);
- textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
- Class_TorqueData.String = textBox_RunInfo_Torque.Text;
- Class_TorqueData.Data = DataTemp;
- //踩踏方向
- DataTemp = (ushort)(Data[12]);
- if (DataTemp == 0)
- {
- textBox_RunInfo_Dir.Text = "正向";
- }
- else if (DataTemp == 1)
- {
- textBox_RunInfo_Dir.Text = "反向";
- }
- else if (DataTemp == 2)
- {
- textBox_RunInfo_Dir.Text = "停止";
- }
- //助力档位
- DataTemp = (ushort)(Data[13]);
- if (DataTemp == 0x33)
- {
- textBox_RunInfo_GearSt.Text = "SMART";
- //comboBox_GearSt.SelectedIndex = 5;
- //comboBox_OBC_SetGearST.SelectedIndex = 5;
- }
- else if (DataTemp == 0x22)
- {
- textBox_RunInfo_GearSt.Text = "WALK";
- //comboBox_GearSt.SelectedIndex = 6;
- //comboBox_OBC_SetGearST.SelectedIndex = 6;
- }
- else
- {
- string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
- textBox_RunInfo_GearSt.Text = Gears[DataTemp];
- //comboBox_GearSt.SelectedIndex = DataTemp;
- //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
- }
- //大灯状态
- DataTemp = (ushort)(Data[14]);
- if (DataTemp == 0xF0)
- {
- textBox_RunInfo_LightSwitch.Text = "OFF";
- //comboBox_LightSwitch.SelectedIndex = 1;
- //comboBox_OBC_LightSw.SelectedIndex = 1;
- }
- else if (DataTemp == 0xF1)
- {
- textBox_RunInfo_LightSwitch.Text = "ON";
- //comboBox_LightSwitch.SelectedIndex = 0;
- //comboBox_OBC_LightSw.SelectedIndex = 0;
- }
- //剩余电量
- DataTemp = (ushort)(Data[15]);
- textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
- //剩余续航里程
- DataTemp = (ushort)(Data[17] * 256 + Data[16]);
- if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
- {
- textBox_RunInfo_Range.Text = "---";
- }
- else
- {
- textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
- }
- //预留(显示力矩Reg),空2bytes
- DataTemp = (ushort)(Data[19] * 256 + Data[18]);
- textBox_TorqueReg.Text = Convert.ToString(DataTemp);
- //平均功耗
- DataTemp = (ushort)(Data[20]);
- textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
- //PCB温度
- DataTemp = (ushort)(Data[21]);
- textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40))+" ℃";
- Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
- Class_MotorTemp.Data = DataTemp - 40;
- //绕组温度
- DataTemp = (ushort)(Data[22]);
- textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
- //MCU温度
- DataTemp = (ushort)(Data[23]);
- textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
- //单次里程
- DataTemp = (ushort)(Data[25] * 256 + Data[24]);
- textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
- //单次时间
- DataTemp = (ushort)(Data[27] * 256 + Data[26]);
- textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
- //数据保存
- RunInfoAutoSave();
- }));
- }
- break;
- }
- case 0x1104://故障码
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_ErrorCode_Refresh = true;
- textBox_ErrorCode.Text =
- Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
- "H";
- }));
- }
- break;
- }
- case 0xA903://反馈指令
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- timer_1s.Enabled = false;
- MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- //关机反馈
- PowerOffAckStatus = true;
- }));
- }
- break;
- }
- case 0xB226://马达参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_MotorParam.Clear();
- for (int i = 0; i < myParams.MotorParma.Count; i++)
- {
- richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB31A://整车信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_BikeParam.Clear();
- for (int i = 0; i < myParams.BikeParma.Count; i++)
- {
- richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- if (i == 8) //更新前后灯参数
- {
- comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
- comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
- comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
- }
- else if (i == 11) //更新开关机参数
- {
- textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
- textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
- textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
- }
- }
- richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
- //更新生产模式中整车参数
- textBox_FacModeWheelSize.Text = (Data[1] * 256 + Data[0]).ToString();//周长
- textBox_FacModeSpeedLimit.Text= (Data[5] * 256 + Data[4]).ToString();//限速
- DataTemp = (int)(Data[13] * 256 + Data[12]);//助力方案1
- if (DataTemp == 0) comboBox_FacModeAssist1.SelectedIndex = 0;
- else if (DataTemp == 341) comboBox_FacModeAssist1.SelectedIndex = 1;
- else if (DataTemp == 682) comboBox_FacModeAssist1.SelectedIndex = 2;
- else comboBox_FacModeAssist1.SelectedIndex = 3;
- DataTemp = (int)(Data[15] * 256 + Data[14]);//助力方案2
- if (DataTemp == 0) comboBox_FacModeAssist2.SelectedIndex = 0;
- else if (DataTemp == 341) comboBox_FacModeAssist2.SelectedIndex = 1;
- else if (DataTemp == 682) comboBox_FacModeAssist2.SelectedIndex = 2;
- else comboBox_FacModeAssist2.SelectedIndex = 3;
- DataTemp = (int)(Data[17] * 256 + Data[16]);//灯压
- if (DataTemp == 6) comboBox_FacModeLightVol.SelectedIndex = 0;
- else if (DataTemp == 12) comboBox_FacModeLightVol.SelectedIndex = 1;
- else comboBox_FacModeLightVol.SelectedIndex = 2;
- DataTemp = (int)(Data[21] * 256 + Data[20]);//启动模式
- if (DataTemp == 1) comboBox_FacModeStartMode.SelectedIndex = 0;
- else if (DataTemp == 3) comboBox_FacModeStartMode.SelectedIndex = 2;
- else comboBox_FacModeStartMode.SelectedIndex = 1;
- }));
- }
- break;
- }
- case 0xB420://控制器参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_ControlParam.Clear();
- for (int i = 0; i < myParams.ControlParma.Count; i++)
- {
- richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB528://传感器参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_SensorParam.Clear();
- for (int i = 0; i < myParams.SensorParam.Count; i++)
- {
- richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
- //更新生产模式页面传感器零点和标定值
- textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
- textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
- textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
- textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
- textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
- }));
- }
- break;
- }
- case 0xB64C://助力参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_AssistParam.Clear();
- int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
- int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
- int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
- int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
- for (int i = 0; i < myParams.AssistParam.Count; i++)
- {
- if (i < index_1) //数据占用2bytes
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- else if (i <= index_2) //数据占用4bytes
- {
- 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])) + ", ");
- }
- else if (i < index_3) //数据占用2bytes,无符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- else if (i <= index_4) //数据占用2bytes,有符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- else //数据占用2bytes,无符号
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
- }
- }
- richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
- //更新生产模式中助力参数
- textBox_FacModeStartGain.Text = (Data[1] * 256 + Data[0]).ToString();//零速增益
- textBox_FacModeCircuitK.Text = (Data[45] * 256 + Data[44]).ToString();//电流阶梯
- textBox_FacModeFltCounter.Text = (Data[49] * 256 + Data[48]).ToString();//滤波脉冲
- textBox_FacModeSpeedLimitTh.Text = (Data[55] * 256 + Data[54]).ToString();//限速启动
- textBox_FacModeSpeedLimitEnd.Text = (Data[57] * 256 + Data[56]).ToString();//限速停止
- textBox_FacModeCadencePer.Text = (Data[59] * 256 + Data[58]).ToString();//踏频占比
- }));
- }
- break;
- }
- case 0xB74C://历史记录
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Record.Clear();
- for (int i = 0; i < myParams.Record.Count; i++)
- {
- richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB83A://调试参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_DebugParam.Clear();
- for (int i = 0; i < myParams.DebugParam.Count; i++)
- {
- richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
- }
- richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB904://存储标志
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- ushort Flag = 0;
- Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
- if (Flag == 0)
- {
- radioButton_EE_SaveNo.Checked = true;
- radioButton_EE_SaveYes.Checked = false;
- }
- else
- {
- radioButton_EE_SaveNo.Checked = false;
- radioButton_EE_SaveYes.Checked = true;
- }
- Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
- if (Flag == 0)
- {
- radioButton_SIP_SaveNo.Checked = true;
- radioButton_SIP_SaveYes.Checked = false;
- }
- else
- {
- radioButton_SIP_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = true;
- }
- }));
- }
- break;
- }
- case 0x1240://电机版本信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //电机型号
- textBox_Model.Text = "";
- textBox_OBC_ReadModel.Text = "";
- textBox_FacModeName.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_Model.Text += ((char)Data[i]).ToString();
- textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
- textBox_FacModeName.Text += ((char)Data[i]).ToString();
- }
- Class_Motor_Ver.Mode = textBox_Model.Text;
- //电机SN
- textBox_SN.Text = "";
- textBox_OBC_ReadSN.Text = "";
- textBox_FacModeNum.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[16 + i] == 0x2E)
- {
- break;
- }
- textBox_SN.Text += ((char)Data[16 + i]).ToString();
- textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
- textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
- }
- Class_Motor_Ver.SN = textBox_SN.Text;
- //电机HW
- textBox_HW.Text = "";
- textBox_OBC_ReadHW.Text = "";
- textBox_FacModeHW.Text = "";
- for (ushort i = 0; i < 8; i++)//前8位:硬件板号
- {
- if (Data[32 + i] == 0x2E)
- {
- break;
- }
- else if (Data[32 + i] == 'r')
- {
- Data[32 + i] = (byte)'.';
- break;
- }
- string strTemp = "";
- strTemp = ((char)Data[32 + i]).ToString();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
- {
- if (Data[40 + i] == 0x2E)
- {
- break;
- }
- else if (Data[40 + i] == 'r')
- {
- Data[40 + i] = (byte)'.';
- break;
- }
- string strTemp = "";
- strTemp = ((char)Data[40 + i]).ToString();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
- {
- string strTemp = "";
- strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
- textBox_HW.Text += strTemp;
- textBox_OBC_ReadHW.Text += strTemp;
- textBox_FacModeHW.Text += strTemp;
- }
- Class_Motor_Ver.HW = textBox_HW.Text;
- //电机FW
- textBox_FW.Text = "";
- textBox_OBC_ReadFW.Text = "";
- textBox_FacModeFW.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[48 + i] == 0x2E)
- {
- break;
- }
- if (Data[48 + i] == 'r')
- {
- Data[48 + i] = (byte)'.';
- }
- textBox_FW.Text += ((char)Data[48 + i]).ToString();
- textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
- textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
- }
- Class_Motor_Ver.FW = textBox_FW.Text;
- }));
- }
- break;
- }
- case 0xA610://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User1.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User1.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA710://自定义2
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User2.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User2.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA810://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User3.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User3.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA520://生产信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //生产商
- textBox_MAC.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_MAC.Text += ((char)Data[i]).ToString();
- }
- //生产地
- textBox_MACAdd.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[8 + i] == 0x2E)
- {
- break;
- }
- textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
- }
- //生产日期
- textBox_MACDate.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[16 + i] == 0x2E)
- {
- break;
- }
- textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
- }
- //品牌信息
- textBox_PP.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[24 + i] == 0x2E)
- {
- break;
- }
- textBox_PP.Text += ((char)Data[24 + i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA408://密钥
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_Key.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- textBox_Key.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xAB09://存储器数据
- case 0xAB0A:
- case 0xAB0B:
- case 0xAB0C:
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- long ByteNum = 0;
- ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
- if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
- {
- for (int i = 0; i < ByteNum; i++)
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
- }
- }
- else //根据设置自动转换10进制显示
- {
- if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
- {
- switch (ByteNum)
- {
- case 1:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
- break;
- }
- case 2:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
- break;
- }
- case 3:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
- break;
- }
- case 4:
- {
- richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
- break;
- }
- default:
- {
- richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
- break;
- }
- }
- }
- else //16进制显示
- {
- switch (ByteNum)
- {
- case 1:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
- break;
- }
- case 2:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
- break;
- }
- case 3:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
- break;
- }
- case 4:
- {
- richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
- break;
- }
- default:
- {
- richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
- break;
- }
- }
- }
- }
- }));
- }
- break;
- }
- case 0xAB88://故障日志
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //电机存储的故障日志,一包128字节包含2条故障日志
- var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
- var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
- ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
- ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
- //数据显示
- ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
- }));
- }
- break;
- }
- case 0x1401://在线检测结果
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
- }));
- }
- break;
- }
- case 0x1510://骑行历史信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- long DataTemp32;
- //ODO里程
- DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
- textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
- //ODO时间
- DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
- if (DataTemp32 >= 60 * 100000)
- textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
- else
- textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
- //TRIP里程
- DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
- textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
- //TRIP时间
- DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
- if (DataTemp32 >= 60 * 100000)
- textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
- else
- textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
- }));
- }
- break;
- }
- case 0x1720://客户信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //程序特性
- textBox_SP.Text = "";
- textBox_OBC_ReadSP.Text = "";
- textBox_FacModeSP.Text = "";
- for (ushort i = 0; i < 32; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- if (Data[i] == 'r')
- {
- Data[i] = (byte)'.';
- }
- textBox_SP.Text += ((char)Data[i]).ToString();
- textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
- textBox_FacModeSP.Text += ((char)Data[i]).ToString(); ;
- }
- //Git提交版本信息
- textBox_FacModeGit.Text = "";
- for (ushort i = 0; i < 9; i++)
- {
- textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
- }
- Class_Motor_Ver.Special = textBox_SP.Text;
- }));
- }
- break;
- }
- case 0xBA20: //调试信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_DebugInfo_Refresh = true;
- //系统状态机
- DataTemp = (short)(Data[0]);
- textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
- //二层状态机
- DataTemp = (short)(Data[1]);
- textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
- //电机状态机
- DataTemp = (short)(Data[2]);
- textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
- //助力状态机
- DataTemp = (short)(Data[3]);
- textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
- //IdRef
- DataTemp = (short)(Data[5] * 256 + Data[4]);
- textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
- //IqRef
- DataTemp = (short)(Data[7] * 256 + Data[6]);
- textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
- //UdRef
- DataTemp = (short)(Data[9] * 256 + Data[8]);
- textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
- //UqRef
- DataTemp = (short)(Data[11] * 256 + Data[10]);
- textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
- //瞬时力矩
- DataTemp = (short)(Data[13] * 256 + Data[12]);
- textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
- //时间滤波力矩
- DataTemp = (short)(Data[15] * 256 + Data[14]);
- textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
- //踏频滤波力矩
- DataTemp = (short)(Data[17] * 256 + Data[16]);
- textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
- //IdFdb
- DataTemp = (short)(Data[19] * 256 + Data[18]);
- textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
- //IqFdb
- DataTemp = (short)(Data[21] * 256 + Data[20]);
- textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
- //助力输出
- DataTemp = (short)(Data[23] * 256 + Data[22]);
- textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
- //数据保存
- RunInfoAutoSave();
- }));
- }
- break;
- }
- default:
- {
- break;
- }
- }
- }
- #endregion
- #region 解析BMS广播的命令
- else if (ID == 0x720)
- {
- switch (CmdTemp)
- {
- case 0x1010://BMS运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- BMS_RunInfo_Refresh = true;
- richTextBox_OBC_BMS_RunInfo.Clear();
- //电压
- uData16 = (ushort)(Data[1] * 256 + Data[0]);
- richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
- //电流
- uData16 = (ushort)(Data[3] * 256 + Data[2]);
- richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
- //剩余容量
- uData16 = (ushort)(Data[5] * 256 + Data[4]);
- richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
- //满充容量
- uData16 = (ushort)(Data[7] * 256 + Data[6]);
- richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mV" + "\r\n");
- //电芯温度
- richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
- //剩余电量
- richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
- //电池状态
- richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
- //SOH
- richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %");
- //循环次数
- richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析电机发送OBC的命令
- else if (ID == 0x713)
- {
- switch (CmdTemp)
- {
- case 0x5408://电机用户参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_OBC_ReadUserInfo.Clear();
- //默认周长
- richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
- //启动模式
- richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
- comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
- //限速
- richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
- //周长微调
- numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
- richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
- //助力方案
- richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
- comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
- //关机时间
- richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
- numericUpDown_OBC_OffTime.Value = (int)Data[5];
- }));
- }
- break;
- }
- case 0x5303://电机应答反馈
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- timer_1s.Enabled = false;
- MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }));
- }
- break;
- }
-
- default: break;
- }
- }
- #endregion
- }
- #endregion
- /// <summary>
- /// 端口连接或断开
- /// </summary>
- private void PortConnect()
- {
- bool result = false;
- if (连接ToolStripMenuItem.Text == "连接")
- {
- result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
- if (result)
- {
- toolStripComboBox_ComNum.Enabled = false;
- toolStripComboBox_Baudrate.Enabled = false;
- 刷新ToolStripMenuItem.Enabled = false;
- 连接ToolStripMenuItem.Text = "断开";
- 连接ToolStripMenuItem.Checked = true;
- label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
- label_PortStatus.BackColor = Color.Green;
- }
- }
- else if (连接ToolStripMenuItem.Text == "断开")
- {
- checkBox_OBC_StartSetGearSt.Checked = false;
- checkBox_OBC_StartReadBMS.Checked = false;
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
- toolStripComboBox_ComNum.Enabled = true;
- toolStripComboBox_Baudrate.Enabled = true;
- 刷新ToolStripMenuItem.Enabled = true;
- 连接ToolStripMenuItem.Text = "连接";
- 连接ToolStripMenuItem.Checked = false;
- label_COM_Sta.Text = "连接状态:未连接";
- label_PortStatus.BackColor = Color.Red;
- }
- }
- /// <summary>
- /// 端口连接事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
- {
- PortConnect();
- }
- /// <summary>
- /// 端口号刷新事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- toolStripComboBox_ComNum.Items.Clear();
- toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
- }
- /// <summary>
- /// 转速调节事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
- {
- //生产模式转速设置值更新
- trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
- label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
- //设置转速百分比
- var Data = new byte[1];
- Data[0] = (byte)numericUpDown_SpeedAdj.Value;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- }
- /// <summary>
- /// 存储标志修改事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 1s定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_1s_Tick(object sender, EventArgs e)
- {
- //时间更新
- label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString();
- //MC_Runinfo超时清除
- if (MC_RunInfo_Refresh == false)
- {
- MC_RunInfo_Refresh_Cnt++;
- if (MC_RunInfo_Refresh_Cnt > 10)//5s
- {
- MC_RunInfo_Clear();
- MC_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_RunInfo_Refresh_Cnt = 0;
- }
- MC_RunInfo_Refresh = false;
- //MC_Debuginfo超时清除
- if (MC_DebugInfo_Refresh == false)
- {
- MC_DebugInfo_Refresh_Cnt++;
- if (MC_DebugInfo_Refresh_Cnt > 10)//5s
- {
- MC_DebugInfo_Clear();
- MC_DebugInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_DebugInfo_Refresh_Cnt = 0;
- }
- MC_DebugInfo_Refresh = false;
- //BMS_RunInfo超时清除
- if (BMS_RunInfo_Refresh == false)
- {
- BMS_RunInfo_Refresh_Cnt++;
- if (BMS_RunInfo_Refresh_Cnt > 10)//5s
- {
- richTextBox_OBC_BMS_RunInfo.Clear();
- BMS_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- BMS_RunInfo_Refresh_Cnt = 0;
- }
- BMS_RunInfo_Refresh = false;
- //故障码超时清除
- if (MC_ErrorCode_Refresh == false)
- {
- MC_ErrorCode_Refresh_Cnt++;
- if (MC_ErrorCode_Refresh_Cnt > 10)//5s
- {
- textBox_ErrorCode.Text = "---";
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- MC_ErrorCode_Refresh = false;
- //CDL连接超时
- if (识别通讯盒ToolStripMenuItem.Checked)
- {
- if (mySerialProcess.CDL_Online_Flag == false)
- {
- mySerialProcess.CDL_OnlineCheck_Cnt++;
- if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
- {
- timer_1s.Enabled = false;
- MessageBox.Show("连接失败!", "提示");
- timer_1s.Enabled = true;
- //关闭串口
- mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
- toolStripComboBox_ComNum.Enabled = true;
- toolStripComboBox_Baudrate.Enabled = true;
- 刷新ToolStripMenuItem.Enabled = true;
- 连接ToolStripMenuItem.Text = "连接";
- 连接ToolStripMenuItem.Checked = false;
- label_COM_Sta.Text = "连接状态:未连接";
- label_PortStatus.BackColor = Color.Red;
- }
- }
- }
-
- //OBC定时发送设置档位
- if (checkBox_OBC_StartSetGearSt.Checked == true)
- {
- var CtrlCode = new byte[2];
- if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
- CtrlCode[0] = 0x33;
- else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
- CtrlCode[0] = 0x22;
- else
- CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
- if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
- CtrlCode[1] = 0xF1;
- else
- CtrlCode[1] = 0xF0;
- if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
- {
- checkBox_OBC_StartSetGearSt.Checked = false;
- }
- }
- //OBC定时发送查询电池
- if (checkBox_OBC_StartReadBMS.Checked == true)
- {
- if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
- {
- checkBox_OBC_StartReadBMS.Checked = false;
- }
- }
- //定时读取存储器
- if (checkBox_ReadRanFlash_AutoSW.Checked == true)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- if (checkBox_ReadRanFlash_AutoClear.Checked == true)
- richTextBox_RamFlasgData.Clear();
- do
- {
- if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else
- {
- Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End < Address_Begin)
- {
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- continue;
- }
- else
- {
- var SendByte = new byte[8];
- SendByte[0] = (byte)(Address_Begin >> 24);
- SendByte[1] = (byte)(Address_Begin >> 16);
- SendByte[2] = (byte)(Address_Begin >> 8);
- SendByte[3] = (byte)(Address_Begin);
- SendByte[4] = (byte)(Addres_End >> 24);
- SendByte[5] = (byte)(Addres_End >> 16);
- SendByte[6] = (byte)(Addres_End >> 8);
- SendByte[7] = (byte)(Addres_End);
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- }
- }
- } while (false);
- }
- }
- /// <summary>
- /// 字符串转成字节流
- /// </summary>
- /// <param name="hexStr"></param>
- /// <param name="Flag_Space"></param>
- /// <returns></returns>
- public static byte[] HexStringToBytes(string hexStr, bool Flag_Space)
- {
- if (string.IsNullOrEmpty(hexStr))
- {
- return new byte[0];
- }
- if (hexStr.StartsWith("0x"))
- {
- hexStr = hexStr.Remove(0, 2);
- }
- var count = hexStr.Length;
- var byteCount = 0;
- if (Flag_Space == true)//相邻字节含空格
- {
- if ((count % 3) == 0)//最后字节含空格
- {
- byteCount = count / 3;
- }
- else if ((count % 3) == 2)//最后字节不含空格
- {
- byteCount = (count + 1) / 3;
- }
- else//数据无效
- {
- MessageBox.Show("相邻字节请插入空格!", "提示");
- }
- var result = new byte[byteCount];
- for (int ii = 0; ii < byteCount; ++ii)
- {
- var tempBytes = Byte.Parse(hexStr.Substring(3 * ii, 2), System.Globalization.NumberStyles.HexNumber);
- result[ii] = tempBytes;
- }
- return result;
- }
- else if (Flag_Space == false)//相邻字节不含空格
- {
- if (count % 2 == 1)
- {
- MessageBox.Show("请删除相邻字节之间空格!", "提示");
- }
- byteCount = count / 2;
- var result = new byte[byteCount];
- for (int ii = 0; ii < byteCount; ++ii)
- {
- var tempBytes = Byte.Parse(hexStr.Substring(2 * ii, 2), System.Globalization.NumberStyles.HexNumber);
- result[ii] = tempBytes;
- }
- return result;
- }
- else
- {
- return new byte[0];
- }
- }
- /// <summary>
- /// 运行信息清除
- /// </summary>
- private void MC_RunInfo_Clear()
- {
- foreach (Control c in tabPage_RunInfo.Controls)
- {
- if ((c is TextBox))
- {
- if(c.Name != textBox_ErrorCode.ToString())
- c.Text = "---";
- }
- }
- }
- /// <summary>
- /// 调试信息清除
- /// </summary>
- private void MC_DebugInfo_Clear()
- {
- foreach (Control c in tabPage_DebugInfo.Controls)
- {
- if ((c is TextBox))
- {
- if (c.Name != textBox_ErrorCode.ToString())
- c.Text = "---";
- }
- }
- }
- /// <summary>
- /// 读取马达参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Read_MotorParam_Click(object sender, EventArgs e)
- {
- richTextBox_MotorParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
- }
- /// <summary>
- /// 写入马达参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Write_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[40];
- for (int i = 0; i < 40; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- short wDataTemp = 0;
- string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)wDataTemp;
- ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取整车信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadBikeParam_Click(object sender, EventArgs e)
- {
- richTextBox_BikeParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
- }
- /// <summary>
- /// 写入整车信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteBikeParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[28];
- for (int i = 0; i < 28; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- short wDataTemp = 0;
- //前后灯参数修改
- if (i == 8)
- {
- wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
- wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
- wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
- }
- //开关机参数
- else if (i == 11)
- {
- wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
- wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
- wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
- }
- else
- {
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
- }
- ConfigParam[2 * i + 2] = (byte)wDataTemp;
- ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取控制器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadControlParam_Click(object sender, EventArgs e)
- {
- richTextBox_ControlParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
- }
- /// <summary>
- /// 写入控制器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteControlParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[34];
- for (int i = 0; i < 34; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadAssistParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- int AssistNum = 0;
- try
- {
- AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
- ConfigParam[0] = (byte)(AssistNum & 0xFF);
- ConfigParam[1] = (byte)(AssistNum >> 8);
- AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
- ConfigParam[2] = (byte)(AssistNum & 0xFF);
- ConfigParam[3] = (byte)(AssistNum >> 8);
- richTextBox_AssistParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
-
- }
- /// <summary>
- /// 写入助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteAssistParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[80];
- for (int i = 0; i < 80; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- long lDataTemp = 0;
- string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index_1 = 0, index_2 = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
- {
- index_1 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
- {
- index_2 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
- if (i < index_1)
- {
- ConfigParam[2 * i + 4] = (byte)lDataTemp;
- ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
- }
- else if (i <= index_2)
- {
- ConfigParam[4 * i - 4] = (byte)lDataTemp;
- ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
- ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
- ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
- }
- else
- {
- ConfigParam[2 * i + 20] = (byte)lDataTemp;
- ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取调试参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadDebugParam_Click(object sender, EventArgs e)
- {
- richTextBox_DebugParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
- }
- /// <summary>
- /// 写入调试参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteDebugParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[60];
- for (int i = 0; i < 60; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadRecord_Click(object sender, EventArgs e)
- {
- richTextBox_Record.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
- }
- /// <summary>
- /// 读取传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadSensorParam_Click(object sender, EventArgs e)
- {
- richTextBox_SensorParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- /// <summary>
- /// 写入力矩传感器标定值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Write_Cal_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 写入传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSensorParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[14];
- for (int i = 0; i < 14; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- //力矩传感器参数只写入前面14项与力矩传感器相关的参数
- string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "踏频传感器一圈脉冲数")
- {
- index = i;
- break;
- }
- }
- for (int i = 0; i < (strDataTemp.Length - index); i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 写入型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteModel_Click(object sender, EventArgs e)
- {
- string Mode = textBox_Model.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- }
- /// <summary>
- /// 写入SN
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSN_Click(object sender, EventArgs e)
- {
- string SN = textBox_SN.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- /// <summary>
- /// 查询版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadVersion_Click(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
- }
- /// <summary>
- /// 查询自定义1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser1_Click(object sender, EventArgs e)
- {
- textBox_User1.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
- }
- /// <summary>
- /// 查询自定义2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser2_Click(object sender, EventArgs e)
- {
- textBox_User2.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
- }
- /// <summary>
- /// 查询自定义3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser3_Click(object sender, EventArgs e)
- {
- textBox_User3.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
- }
- /// <summary>
- /// 写入自定义字符串1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser1_Click(object sender, EventArgs e)
- {
- string User = textBox_User1.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
- }
- /// <summary>
- /// 写入自定义字符串2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser2_Click(object sender, EventArgs e)
- {
- string User = textBox_User2.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
- }
- /// <summary>
- /// 写入自定义字符串3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser3_Click(object sender, EventArgs e)
- {
- string User = textBox_User3.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
- }
- /// <summary>
- /// 查询生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadMAC_Click(object sender, EventArgs e)
- {
- textBox_MAC.Text = "---";
- textBox_MACAdd.Text = "---";
- textBox_MACDate.Text = "---";
- textBox_PP.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
- }
-
- /// <summary>
- /// 写入生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteMac_Click(object sender, EventArgs e)
- {
- var MACArray = new byte[32];
- //填入生产商
- for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
- {
- MACArray[i] = (byte)textBox_MAC.Text[i];
- }
- if (textBox_MAC.Text.Length < 8)
- {
- MACArray[textBox_MAC.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
- {
- MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
- }
- }
- //填入生产地
- for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
- {
- MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
- }
- if (textBox_MACAdd.Text.Length < 8)
- {
- MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
- {
- MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
- }
- }
- //填入生产日期
- for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
- {
- MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
- }
- if (textBox_MACDate.Text.Length < 8)
- {
- MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
- {
- MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
- }
- }
- //填入品牌
- for (ushort i = 0; i < textBox_PP.Text.Length; i++)
- {
- MACArray[24 + i] = (byte)textBox_PP.Text[i];
- }
- if (textBox_PP.Text.Length < 8)
- {
- MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
- {
- MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
- }
- /// <summary>
- /// 查询密钥
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadKey_Click(object sender, EventArgs e)
- {
- textBox_Key.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
- }
- /// <summary>
- /// 写入校验密钥
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteKey_Click(object sender, EventArgs e)
- {
- string Key = textBox_Key.Text;
- var KeyArray = new byte[8];
- if (Key.Length != 8)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- for (ushort i = 0; i < Key.Length; i++)
- {
- KeyArray[i] = (byte)Key[i];
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
- }
- /// <summary>
- /// 查询在线检测结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadOnLine_Click(object sender, EventArgs e)
- {
- textBox_Online.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
- }
- /// <summary>
- /// 系统清除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_SystemClear_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 参数还原
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Recovery_Click(object sender, EventArgs e)
- {
- var Code = new byte[8];
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'C';
- Code[3] = (byte)'O';
- Code[4] = (byte)'V';
- Code[5] = (byte)'E';
- Code[6] = (byte)'R';
- Code[7] = (byte)'Y';
- timer_1s.Enabled = false;
- if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 系统复位
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Reset_Click(object sender, EventArgs e)
- {
- var Code_Off = new byte[5];
- var Code_Reset = new byte[5];
- Code_Off[0] = (byte)'O';
- Code_Off[1] = (byte)'F';
- Code_Off[2] = (byte)'F';
- Code_Off[3] = (byte)'.';
- Code_Off[4] = (byte)'.';
- Code_Reset[0] = (byte)'R';
- Code_Reset[1] = (byte)'E';
- Code_Reset[2] = (byte)'S';
- Code_Reset[3] = (byte)'E';
- Code_Reset[4] = (byte)'T';
- timer_1s.Enabled = false;
- if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_1s.Enabled = true;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- timer_1s.Enabled = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 记录清除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ClearLog_Click(object sender, EventArgs e)
- {
- var Code = new byte[9];
- Code[0] = (byte)'L';
- Code[1] = (byte)'O';
- Code[2] = (byte)'G';
- Code[3] = (byte)' ';
- Code[4] = (byte)'C';
- Code[5] = (byte)'L';
- Code[6] = (byte)'E';
- Code[7] = (byte)'A';
- Code[8] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
- MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 打开系统计算器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("calc.exe");
- }
- /// <summary>
- ///故障转换和显示
- /// </summary>
- List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
- "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
- "",""};
- private string ErrorInfoDisplay(UInt32 Code)
- {
- string Result = "";
- if (Code == 0)
- {
- Result = "无故障";
- }
- else
- {
- for (int i = 0; i < 32; i++)
- {
- if ((Code & 0x01) == 0x01)
- {
- Result += ErrorInfo[i] + " ";
- }
- Code >>= 1;
- }
- }
- return Result;
- }
- /// <summary>
- /// 鼠标滑过故障码显示具体内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
- {
- // 创建the ToolTip
- ToolTip toolTip1 = new ToolTip();
- // 设置显示样式
- toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
- toolTip1.InitialDelay = 50;//事件触发多久后出现提示
- toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
- toolTip1.ShowAlways = true;//是否显示提示框
- // 设置伴随的对象.
- string ErrorCode = this.textBox_ErrorCode.Text;
- UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
- toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
- }
- /// <summary>
- /// 数据记录
- /// </summary>
- private void RunInfoAutoSave()
- {
- if (运行信息记录ToolStripMenuItem.Checked == true)
- {
- if (RunInfoSaveFilename == string.Empty)
- {
- return;
- }
- string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
- foreach (Control c in tabPage_RunInfo.Controls)
- {
- if (c is TextBox)
- {
- SaveData += c.Text + " , ";
- }
- }
- foreach (Control c in tabPage_DebugInfo.Controls)
- {
- if (c is TextBox)
- {
- SaveData += c.Text + " , ";
- }
- }
- SaveData += "\r\n";
- System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
- }
- }
- /// <summary>
- /// 打开或关闭数据记录
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (运行信息记录ToolStripMenuItem.Checked == false)
- {
- if (mySerialProcess.mySerial.IsOpen == true)
- {
- RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
- System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
- "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
- "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
- timer_1s.Enabled = false;
- MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- 运行信息记录ToolStripMenuItem.Checked = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- }
- else
- {
- 运行信息记录ToolStripMenuItem.Checked = false;
- timer_1s.Enabled = false;
- MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 仪表启动控制档位开关事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_OBC_StartSetGearSt.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartSetGearSt.Checked = false;
- return;
- }
- //检查是否选择档位和打开车灯
- if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartSetGearSt.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// OBC查询电机用户参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
- {
- richTextBox_OBC_ReadUserInfo.Clear();
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
- }
- /// <summary>
- /// OBC设置电机用户参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
- {
- var UserInfoCode = new byte[8];
- for (int i = 0; i < UserInfoCode.Length; i++)
- UserInfoCode[i] = 0;
- if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
- UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
- UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
- UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
- }
-
- /// <summary>
- /// OBC查询电机版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- }
- /// <summary>
- /// OBC读取骑行历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
- {
- textBox_OBC_TRIP_KM.Text = "";
- textBox_OBC_TRIP_TIME.Text = "";
- textBox_OBC_ODO_KM.Text = "";
- textBox_OBC_ODO_TIME.Text = "";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
- }
- /// <summary>
- /// OBC清除TRIP里程
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
- timer_1s.Enabled = true;
- }
- private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_OBC_StartReadBMS.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartReadBMS.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// 写入力矩传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[46];
- for (int i = 0; i < 14; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- //力矩传感器参数只写入前面14项与力矩传感器相关的参数
- string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
- {
- index = i;
- break;
- }
- }
- for (int i = 0; i < (index + 1); i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 查询存储标志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadSaveFlag_Click(object sender, EventArgs e)
- {
- radioButton_EE_SaveYes.Checked = false;
- radioButton_EE_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = false;
- radioButton_SIP_SaveNo.Checked = false;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
- }
- /// <summary>
- /// 写入存储标志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSaveFlag_Click(object sender, EventArgs e)
- {
- var SaveFlag = new byte[6];
- for (int i = 0; i < 6; i++)
- SaveFlag[i] = 0;
- if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
- SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
- SaveFlag[3] = 0;
- SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
- SaveFlag[5] = 0;
- timer_1s.Enabled = false;
- if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 读取指定地址数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadRamFlash_Click(object sender, EventArgs e)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- if(checkBox_ReadRanFlash_AutoClear.Checked == true)
- richTextBox_RamFlasgData.Clear();
- if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- return;
- }
- else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End < Address_Begin)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- var SendByte = new byte[8];
- SendByte[0] = (byte)(Address_Begin >> 24);
- SendByte[1] = (byte)(Address_Begin >> 16);
- SendByte[2] = (byte)(Address_Begin >> 8);
- SendByte[3] = (byte)(Address_Begin);
- SendByte[4] = (byte)(Addres_End >> 24);
- SendByte[5] = (byte)(Addres_End >> 16);
- SendByte[6] = (byte)(Addres_End >> 8);
- SendByte[7] = (byte)(Addres_End);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
- }
- }
- }
- /// <summary>
- /// 工作模式选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
- {
- var RunMode = new byte[1];
- if (comboBox_WorkMode.Text == "配置模式")
- RunMode[0] = 0x01;
- else if (comboBox_WorkMode.Text == "调试模式")
- RunMode[0] = 0x02;
- else
- RunMode[0] = 0x00;
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- }
- /// <summary>
- /// 助力档位选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
- {
- var CtrlCode = new byte[2];
- if (comboBox_GearSt.SelectedIndex == 5)//档位
- CtrlCode[0] = 0x33;
- else if (comboBox_GearSt.SelectedIndex == 6)//档位
- CtrlCode[0] = 0x22;
- else
- CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
- if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
- CtrlCode[1] = 0xF1;
- else
- CtrlCode[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
- comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
- comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
- }
- /// <summary>
- /// 仪表档位选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
- {
- comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
- comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
- }
- /// <summary>
- /// 生产模式初始化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeInit_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_1s.Enabled = true;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- timer_1s.Enabled = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- timer_1s.Enabled = true;
- }
- }
- timer_1s.Enabled = true;
- //清除历史测试记录
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- checkBox_FacModeCheckBikeSpeed.Checked = false;
- checkBox_FacModeCheckCadence.Checked = false;
- checkBox_FacModeCheckNTC.Checked = false;
- checkBox_FacModeCheckVol.Checked = false;
- LightSwitchStatus = false;
- MotorRunStatus = false;
- trackBar_FacModeMotorSpeedAdj.Value = 5;
- textBox_FacModeWheelSize.Text = "";
- textBox_FacModeSpeedLimit.Text = "";
- comboBox_FacModeAssist1.SelectedIndex = -1;
- comboBox_FacModeAssist2.SelectedIndex = -1;
- comboBox_FacModeLightVol.SelectedIndex = -1;
- comboBox_FacModeStartMode.SelectedIndex = -1;
- textBox_FacModeStartGain.Text = "";
- textBox_FacModeCircuitK.Text = "";
- textBox_FacModeFltCounter.Text = "";
- textBox_FacModeSpeedLimitTh.Text = "";
- textBox_FacModeSpeedLimitEnd.Text = "";
- textBox_FacModeCadencePer.Text = "";
- textBox_FacModeName.Text = "";
- textBox_FacModeNum.Text = "";
- textBox_FacModeHW.Text = "";
- textBox_FacModeFW.Text = "";
- }
- /// <summary>
- /// 生产模式读取传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeSensorRead_Click(object sender, EventArgs e)
- {
- richTextBox_SensorParam.Clear();
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- /// <summary>
- /// 生产模式传感器标定1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet1_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 1;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(200);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet2_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 2;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(200);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet3_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 3;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(200);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式传感器标定3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void buttonFacModeSet4_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = 4;//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- Delay_ms(200);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式采集按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeWorkMode_Click(object sender, EventArgs e)
- {
- var RunMode = new byte[1];
- if (button_FacModeWorkMode.Text == "开始")
- {
- RunMode[0] = 0x01;
- if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
- {
- button_FacModeWorkMode.Text = "停止";
- button_FacModeWorkMode.BackColor = Color.Yellow;
- }
- }
- else if (button_FacModeWorkMode.Text == "停止")
- {
- RunMode[0] = 0x00;
- if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
- {
- button_FacModeWorkMode.Text = "开始";
- button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
- }
- }
- }
- /// <summary>
- /// 生产模式开关灯
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- bool LightSwitchStatus = false;
- private void button_FacModeLightSW_Click(object sender, EventArgs e)
- {
- var CtrlCode = new byte[2];
- CtrlCode[0] = 0x00;
- if (LightSwitchStatus)
- {
- CtrlCode[1] = 0xF0;
- button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
- }
- else
- {
- CtrlCode[1] = 0xF1;
- button_FacModeLightSW.BackColor = Color.Yellow;
- }
- if(mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
- {
- LightSwitchStatus = !LightSwitchStatus;
- comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
- comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
- }
- }
- /// <summary>
- /// 生产模式电机控制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- bool MotorRunStatus = false;
- private void button_FacModeMotorRun_Click(object sender, EventArgs e)
- {
- string DebugDefaultInfo = "";
- //获取调试信息
- if (richTextBox_DebugParam.Text == string.Empty)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请先读取调试信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- DebugDefaultInfo = richTextBox_DebugParam.Text;
- }
- //获取参数
- string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- if (strDataTemp.Length != 25)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
-
- var ConfigParam = new byte[60];
- for (int i = 0; i < 60; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = 0x00;
- ushort uwDataTemp = 0;
- if (!MotorRunStatus) //停止状态
- {
- //设置速度环
- if (radioButton_FacModeDriverCity.Checked | radioButton_FacModeDriverMtb.Checked | radioButton_FacModeDriverLG.Checked == true)
- {
- strDataTemp[0] = "整体运行模式=3";
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- //设置带载类型
- if (label_Load.Text == "空载")
- {
- strDataTemp[10] = "转速环控制器带宽=3";
- }
- else if (label_Load.Text == "带载")
- {
- strDataTemp[10] = "转速环控制器带宽=5";
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择带载类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- //选择位置模式
- if (label_MotorSensor.Text == "有感")
- {
- if (radioButton_FacModeDriverCity.Checked | radioButton_FacModeDriverMtb.Checked == true)
- strDataTemp[1] = "位置获取模式=1";
- else if (radioButton_FacModeDriverLG.Checked == true)
- strDataTemp[1] = "位置获取模式=2";
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- }
- else if (label_MotorSensor.Text == "无感")
- {
- strDataTemp[1] = "位置获取模式=0";
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择位置模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- //发送数据
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- if(!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
- return;
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- //设置转速百分比100%
- trackBar_FacModeMotorSpeedAdj.Value = 100;
- MotorRunStatus = !MotorRunStatus;
- button_FacModeMotorRun.BackColor = Color.Yellow;
- //电机进入配置模式
- var RunMode = new byte[1];
- RunMode[0] = 0x01;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- button_FacModeWorkMode.Text = "停止";
- button_FacModeWorkMode.BackColor = Color.Yellow;
- }
- else //运转状态
- {
- //还原为原始值
- if (radioButton_FacModeDriverCity.Checked == true)
- {
- strDataTemp[0] = "整体运行模式=4";
- strDataTemp[1] = "位置获取模式=1";
- strDataTemp[10] = "转速环控制器带宽=5";
- }
- else if (radioButton_FacModeDriverMtb.Checked == true)
- {
- strDataTemp[0] = "整体运行模式=5";
- strDataTemp[1] = "位置获取模式=1";
- strDataTemp[10] = "转速环控制器带宽=5";
- }
- else if (radioButton_FacModeDriverLG.Checked == true)
- {
- strDataTemp[0] = "整体运行模式=6";
- strDataTemp[1] = "位置获取模式=2";
- strDataTemp[10] = "转速环控制器带宽=5";
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
- return;
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- //设置转速百分比2%
- trackBar_FacModeMotorSpeedAdj.Value = 2;
- MotorRunStatus = !MotorRunStatus;
- button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
- //电机退出配置模式
- var RunMode = new byte[1];
- RunMode[0] = 0x00;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- button_FacModeWorkMode.Text = "开始";
- button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
- }
- }
- /// <summary>
- /// 生产模式转速调节
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
- {
- //转速百分比更新
- label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
- numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
- }
- /// <summary>
- /// 生产模式读取整车参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeBikeParaRead_Click(object sender, EventArgs e)
- {
- textBox_FacModeWheelSize.Text = "";
- textBox_FacModeSpeedLimit.Text = "";
- comboBox_FacModeAssist1.SelectedIndex = -1;
- comboBox_FacModeAssist2.SelectedIndex = -1;
- comboBox_FacModeLightVol.SelectedIndex = -1;
- comboBox_FacModeStartMode.SelectedIndex = -1;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
- }
- /// <summary>
- /// 生产模式写入整车参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeBikeParaSet_Click(object sender, EventArgs e)
- {
- string BikeDefaultInfo = "轮胎周长=219, 电控传动比=35, 助力最大限速=25, 推行模式限速=6, 前牙盘T数=38, 后牙盘T数=11, 助力方案1=341, 助力方案2=682, 前后灯电压=6, 轮胎周长微调=0, 启动模式=2, 自动关机时间=15";
- var ConfigParam = new byte[28];
- for (int i = 0; i < 28; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)(0x01);
- ushort uwDataTemp = 0;
- string[] strDataTemp = BikeDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- //周长
- uwDataTemp = Convert.ToUInt16(textBox_FacModeWheelSize.Text);
- ConfigParam[2] = (byte)uwDataTemp;
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- //限速
- uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimit.Text);
- ConfigParam[6] = (byte)uwDataTemp;
- ConfigParam[7] = (byte)(uwDataTemp >> 8);
- //助力方案1
- if (comboBox_FacModeAssist1.SelectedIndex == 0) uwDataTemp = 0;
- else if (comboBox_FacModeAssist1.SelectedIndex == 1) uwDataTemp = 341;
- else if (comboBox_FacModeAssist1.SelectedIndex == 2) uwDataTemp = 682;
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- ConfigParam[14] = (byte)uwDataTemp;
- ConfigParam[15] = (byte)(uwDataTemp >> 8);
- //助力方案2
- if(comboBox_FacModeAssist2.SelectedIndex == 0) uwDataTemp = 0;
- else if (comboBox_FacModeAssist2.SelectedIndex == 1) uwDataTemp = 341;
- else if (comboBox_FacModeAssist2.SelectedIndex == 2) uwDataTemp = 682;
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- ConfigParam[16] = (byte)uwDataTemp;
- ConfigParam[17] = (byte)(uwDataTemp >> 8);
- //灯压
- if(comboBox_FacModeLightVol.SelectedIndex == 0) uwDataTemp = 6;
- else if (comboBox_FacModeLightVol.SelectedIndex == 1) uwDataTemp = 12;
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- ConfigParam[18] = (byte)uwDataTemp;
- ConfigParam[19] = (byte)(uwDataTemp >> 8);
- //启动模式
- if (comboBox_FacModeStartMode.SelectedIndex == 0) uwDataTemp = 1;
- else if (comboBox_FacModeStartMode.SelectedIndex == 2) uwDataTemp = 3;
- else uwDataTemp = 2;
- ConfigParam[22] = (byte)uwDataTemp;
- ConfigParam[23] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式读取助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeAssistParaRead_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- textBox_FacModeStartGain.Text = "";
- textBox_FacModeCircuitK.Text = "";
- textBox_FacModeFltCounter.Text = "";
- textBox_FacModeSpeedLimitTh.Text ="";
- textBox_FacModeSpeedLimitEnd.Text = "";
- textBox_FacModeCadencePer.Text = "";
- ConfigParam[0] = (byte)(1 & 0xFF);
- ConfigParam[1] = (byte)(1 >> 8);
- ConfigParam[2] = (byte)(1 & 0xFF);
- ConfigParam[3] = (byte)(1 >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
- }
- /// <summary>
- /// 生产模式写入助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeAssistParaSet_Click(object sender, EventArgs e)
- {
- string AssistDefaultInfo = "零速启动增益=4096, 巡航启动增益=4096, 助力转矩曲线编号=1, 助力踏频曲线编号=1, 转矩曲线.a=0, 转矩曲线.b=0, 转矩曲线.c=2048, 转矩曲线.d=137, 踏频曲线.a=0, 踏频曲线.b=0, 踏频曲线.c=35000, 踏频曲线.d=0, 助力启动阈值=80, 助力停止阈值=40, 启动时电流增长阶梯=10, 启动对应踏频脉冲数=32, 转矩滤波对应踏频脉冲数=45, 待速转速=0, 待速最大电流=500, 车速限幅启动阈值=25, 车速限幅停止阈值=27, 踏频占比=1229";
- var ConfigParam = new byte[80];
- for (int i = 0; i < 80; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)(0x01);
- ushort uwDataTemp = 0;
- ulong ulDataTemp = 0;
- int index_1 = 0, index_2 = 0;
- string[] strDataTemp = AssistDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- //因数据类型不同,预处理
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
- {
- index_1 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
- {
- index_2 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
- if (i < index_1)
- {
- ConfigParam[2 * i + 4] = (byte)ulDataTemp;
- ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
- }
- else if (i <= index_2)
- {
- ConfigParam[4 * i - 4] = (byte)ulDataTemp;
- ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
- ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
- ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
- }
- else
- {
- ConfigParam[2 * i + 20] = (byte)ulDataTemp;
- ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
- }
- }
- //零速增益
- uwDataTemp = Convert.ToUInt16(textBox_FacModeStartGain.Text);
- ConfigParam[4] = (byte)uwDataTemp;
- ConfigParam[5] = (byte)(uwDataTemp >> 8);
- //电流阶梯
- uwDataTemp = Convert.ToUInt16(textBox_FacModeCircuitK.Text);
- ConfigParam[48] = (byte)uwDataTemp;
- ConfigParam[49] = (byte)(uwDataTemp >> 8);
- //滤波脉冲
- uwDataTemp = Convert.ToUInt16(textBox_FacModeFltCounter.Text);
- ConfigParam[52] = (byte)uwDataTemp;
- ConfigParam[53] = (byte)(uwDataTemp >> 8);
- //限速启动
- uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitTh.Text);
- ConfigParam[58] = (byte)uwDataTemp;
- ConfigParam[59] = (byte)(uwDataTemp >> 8);
- //限速停止
- uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitEnd.Text);
- ConfigParam[60] = (byte)uwDataTemp;
- ConfigParam[61] = (byte)(uwDataTemp >> 8);
- //踏频占比
- uwDataTemp = Convert.ToUInt16(textBox_FacModeCadencePer.Text);
- ConfigParam[62] = (byte)uwDataTemp;
- ConfigParam[63] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 生产模式写入型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_FacModeSetName_Click(object sender, EventArgs e)
- {
- string Mode = textBox_FacModeName.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- }
- /// <summary>
- /// 生产模式写入SN
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSetNum_Click(object sender, EventArgs e)
- {
- string SN = textBox_FacModeNum.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- /// <summary>
- /// 生产模式读取版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_SP.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_OBC_ReadSP.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- textBox_FacModeSP.Text = "---";
- textBox_FacModeGit.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- }
- /// <summary>
- /// 生产模式写入生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
- {
- var MACArray = new byte[32];
- string MacDefaultInfo = "";
- string MacAddDefaultInfo = "";
- string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
- string MacPPDefaultInfo = "";
- do
- {
- //填入生产商
- if (toolStripTextBox_MAC.Text == string.Empty)
- {
- break;
- }
- MacDefaultInfo = toolStripTextBox_MAC.Text;
- for (ushort i = 0; i < MacDefaultInfo.Length; i++)
- {
- MACArray[i] = (byte)MacDefaultInfo[i];
- }
- if (MacDefaultInfo.Length < 8)
- {
- MACArray[MacDefaultInfo.Length] = (byte)'.';
- for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
- {
- MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
- }
- }
- //填入生产地
- if (toolStripTextBoxMACAddr.Text == string.Empty)
- {
- break;
- }
- MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
- for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
- {
- MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
- }
- if (MacAddDefaultInfo.Length < 8)
- {
- MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
- for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
- {
- MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
- }
- }
- //填入生产日期
- if (toolStripTextBox_MACDate.Text == string.Empty)
- {
- break;
- }
- MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
- for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
- {
- MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
- }
- if (MacDateDefaultInfo.Length < 8)
- {
- MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
- for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
- {
- MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
- }
- }
- //填入产品标识
- if (toolStripTextBox_MACPD.Text == string.Empty)
- {
- break;
- }
- MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
- for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
- {
- MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
- }
- if (MacPPDefaultInfo.Length < 8)
- {
- MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
- for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
- {
- MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
-
- return;
- } while (false);
- timer_1s.Enabled = false;
- MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 生产模式保存测试页面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
- {
- Button_FacModeSaveResult.Text = "存储中…";
- do
- {
- //读取一次马达参数
- richTextBox_MotorParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
- Delay_ms(100);
- //读取一次整车参数
- richTextBox_BikeParam.Clear();
- textBox_FacModeWheelSize.Text = "";
- textBox_FacModeSpeedLimit.Text = "";
- comboBox_FacModeAssist1.SelectedIndex = -1;
- comboBox_FacModeAssist2.SelectedIndex = -1;
- comboBox_FacModeLightVol.SelectedIndex = -1;
- comboBox_FacModeStartMode.SelectedIndex = -1;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
- Delay_ms(100);
- //读取一次控制参数
- richTextBox_ControlParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
- Delay_ms(100);
- //查询传感器
- richTextBox_SensorParam.Clear();
- textBox_FacModeSensorADC0.Text = "";
- textBox_FacModeSensorADC1.Text = "";
- textBox_FacModeSensorADC2.Text = "";
- textBox_FacModeSensorADC3.Text = "";
- textBox_FacModeSensorADC4.Text = "";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
- Delay_ms(100);
- //读取一次助力参数
- var ConfigParam = new byte[4];
- textBox_FacModeStartGain.Text = "";
- textBox_FacModeCircuitK.Text = "";
- textBox_FacModeFltCounter.Text = "";
- textBox_FacModeSpeedLimitTh.Text = "";
- textBox_FacModeSpeedLimitEnd.Text = "";
- textBox_FacModeCadencePer.Text = "";
- richTextBox_AssistParam.Clear();
- ConfigParam[0] = (byte)(1 & 0xFF);
- ConfigParam[1] = (byte)(1 >> 8);
- ConfigParam[2] = (byte)(1 & 0xFF);
- ConfigParam[3] = (byte)(1 >> 8);
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
- Delay_ms(100);
- //读取一次调试信息
- richTextBox_DebugParam.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
- Delay_ms(100);
- //读取一次历史信息
- richTextBox_Record.Clear();
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
- Delay_ms(100);
- //读取一次电机运行信息
- var CtrlCode = new byte[2];
- CtrlCode[0] = 0x00;
- CtrlCode[1] = 0xF0;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
- Delay_ms(100);
- //读取一次版本信息
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- textBox_FacModeName.Text = "---";
- textBox_FacModeNum.Text = "---";
- textBox_FacModeHW.Text = "---";
- textBox_FacModeFW.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
- Delay_ms(100);
- //读取一次生产信息
- textBox_MAC.Text = "";
- textBox_MACAdd.Text = "";
- textBox_MACDate.Text = "";
- textBox_PP.Text = "";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
- Delay_ms(100);
- //读取一次自定义信息
- textBox_User1.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
- Delay_ms(100);
- textBox_User2.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
- Delay_ms(100);
- textBox_User3.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
- Delay_ms(100);
- //读取一次密钥
- textBox_Key.Text = "---";
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
- Delay_ms(100);
- //读取一次存储标志
- radioButton_EE_SaveYes.Checked = false;
- radioButton_EE_SaveNo.Checked = false;
- radioButton_SIP_SaveYes.Checked = false;
- radioButton_SIP_SaveNo.Checked = false;
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
- Delay_ms(100);
- //提示检查
- #if false
- timer_1s.Enabled = false;
- if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- timer_1s.Enabled = true;
- Delay_ms(200);
- #endif
- //判断数据是否有效
- if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "--"))
- {
- MessageBox.Show("SN无效,上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- break;
- }
- if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
- {
- MessageBox.Show("SN无效,上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- break;
- }
- if (!textBox_FacModeName.Text.Contains("MIGIC"))
- {
- MessageBox.Show("型号名无效,上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- break;
- }
- //设置文件存储路径
- string Save_Path = localInfo.LocalPath + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; ;
- string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
- Save_Path += PD_PathName;
- if (!Directory.Exists(Save_Path))
- Directory.CreateDirectory(Save_Path);
- //保存页面
- string PIC_SaveFileName = "";
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
- PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
- bit.Save(PIC_SaveFileName);
- //保存数据
- string DataFileName = "";
- string FileInfo = "";
- DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
- FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[电机信息]\r\n";
- FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
- FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
- FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
- FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
- FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[马达参数]\r\n";
- FileInfo += richTextBox_MotorParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[整车参数]\r\n";
- FileInfo += richTextBox_BikeParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[控制参数]\r\n";
- FileInfo += richTextBox_ControlParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[传感器参数]\r\n";
- FileInfo += richTextBox_SensorParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[助力参数]\r\n";
- FileInfo += richTextBox_AssistParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[调试参数]\r\n";
- FileInfo += richTextBox_DebugParam.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[历史信息]\r\n";
- FileInfo += richTextBox_Record.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[生产信息]\r\n";
- FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
- FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
- FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
- FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[自定义信息]\r\n";
- FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
- FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
- FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[校验密钥]\r\n";
- FileInfo += textBox_Key.Text + "\r\n";
- FileInfo += "\r\n";
- FileInfo += "[存储标志]\r\n";
- FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
- FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
- FileInfo += "\r\n";
- System.IO.File.WriteAllText(DataFileName, FileInfo);
- timer_1s.Enabled = false;
- MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- //数据上传
- if (myFtp.IsNetConnected == true)
- {
- string DataNow= DateTime.Now.ToString("yyyy-MM-dd");
- //检查路径
- if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
- }
- if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, DataNow) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\" + DataNow);
- }
- if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\" + DataNow, PD_PathName) == false)
- {
- myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
- }
- //上传文件
- bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
- bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
- if ((result1 & result2) == true)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- }
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- }
- Button_FacModeSaveResult.Text = "保存数据";
- return;
- } while (false);
- timer_1s.Enabled = false;
- MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- Button_FacModeSaveResult.Text = "保存数据";
- }
- /// <summary>
- /// 工具箱页面保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //保存页面
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
- SaveFileDialog sf = new SaveFileDialog();
- sf.Title = "页面保存";
- sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
- sf.Filter = "图片|*.png";
- timer_1s.Enabled = false;
- if (sf.ShowDialog() == DialogResult.OK)
- {
- bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 生产模式关机
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_FacModePowerOff_Click(object sender, EventArgs e)
- {
- var Code_Off = new byte[5];
- var Code_Reset = new byte[5];
- Code_Off[0] = (byte)'O';
- Code_Off[1] = (byte)'F';
- Code_Off[2] = (byte)'F';
- Code_Off[3] = (byte)'.';
- Code_Off[4] = (byte)'.';
- Code_Reset[0] = (byte)'R';
- Code_Reset[1] = (byte)'E';
- Code_Reset[2] = (byte)'S';
- Code_Reset[3] = (byte)'E';
- Code_Reset[4] = (byte)'T';
- timer_1s.Enabled = false;
- if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- timer_1s.Enabled = true;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- int TryCnt = 3;
- while ((TryCnt--) >= 0)
- {
- if (!PowerOffAckStatus)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
- PowerOffAckStatus = false;
- Delay_ms(250);
- }
- else break;
- }
- if (PowerOffAckStatus)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
- timer_1s.Enabled = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- timer_1s.Enabled = true;
- }
- //仪表电源键按下
- private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00100000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表加键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00010000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表减键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00001000;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Walk键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000100;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Light键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000010;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 仪表Set键按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
- {
- var Code = new byte[2];
- Code[0] = 0;
- Code[1] = 0b00000001;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
- }
- /// <summary>
- /// 带载类型选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label_Load_Click(object sender, EventArgs e)
- {
- if (label_Load.Text == "带载")
- label_Load.Text = "空载";
- else if (label_Load.Text == "空载")
- label_Load.Text = "带载";
- }
- /// <summary>
- /// 控制模式选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label_MotorSensor_Click(object sender, EventArgs e)
- {
- if (label_MotorSensor.Text == "有感")
- label_MotorSensor.Text = "无感";
- else if (label_MotorSensor.Text == "无感")
- label_MotorSensor.Text = "有感";
- }
- /// <summary>
- /// 导出电机故障日志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ExportLog_Click(object sender, EventArgs e)
- {
- var Address = new byte[4];
- UInt32 Address_Begin;
- UInt32 Addres_End;
- string textBox_Address_Begin = textBox_LogAddrBegin.Text;
- string textBox_Address_End = textBox_LogAddrEnd.Text;
- richTextBox_Record.Clear();
- textBox_LogAddrBegin.ReadOnly = true;
- textBox_LogAddrEnd.ReadOnly = true;
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- Address = HexStringToBytes(textBox_Address_Begin, false);
- Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- Address = HexStringToBytes(textBox_Address_End, false);
- Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
- if (Addres_End <= Address_Begin)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("结束地址应大于起始地址!", "提示");
- timer_1s.Enabled = true;
- return;
- }
- else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
- {
- timer_1s.Enabled = false;
- MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
- timer_1s.Enabled = true;
- return;
- }
- else
- {
- UInt32 ReadCount = 0;
- button_ExportLog.Text = "导出中...";
- button_ExportLog.Enabled = false;
- ReadCount = (Addres_End - Address_Begin + 1) / 128;
- for (ushort i = 0; i < ReadCount; i++)
- {
- var SendByte = new byte[8];
- UInt32 Address_Temp_Begin;
- UInt32 Address_Temp_End;
- Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
- SendByte[0] = (byte)(Address_Temp_Begin >> 24);
- SendByte[1] = (byte)(Address_Temp_Begin >> 16);
- SendByte[2] = (byte)(Address_Temp_Begin >> 8);
- SendByte[3] = (byte)(Address_Temp_Begin);
- Address_Temp_End = Address_Temp_Begin + 127;
- SendByte[4] = (byte)(Address_Temp_End >> 24);
- SendByte[5] = (byte)(Address_Temp_End >> 16);
- SendByte[6] = (byte)(Address_Temp_End >> 8);
- SendByte[7] = (byte)(Address_Temp_End);
- mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
- Delay_ms(200);//Thread.Sleep(200);
- }
- button_ExportLog.Text = "导出日志";
- button_ExportLog.Enabled = true;
- }
- }
- }
- /// <summary>
- /// 保存日志信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_SaveRecordInfo_Click(object sender, EventArgs e)
- {
- string SaveInfo = "";
- if (richTextBox_Record.Text == string.Empty)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- return;
- }
- //获取保存信息
- SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
- SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
- SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
- SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
- SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
- SaveInfo += "\r\n";
- SaveInfo += richTextBox_Record.Text;
- //设置保存路径和文件名
- SaveFileDialog sf = new SaveFileDialog();
- sf.Title = "数据保存";
- sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
- sf.FileName.Replace(" ", "");
- sf.Filter = "日志|*.ttlog";
- if (sf.ShowDialog() == DialogResult.OK)
- {
- System.IO.File.AppendAllText(sf.FileName, SaveInfo);
- }
- }
- /// <summary>
- /// 双击修改日志起始地址
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
- {
- textBox_LogAddrBegin.ReadOnly = false;
- }
- /// <summary>
- /// 双击修改日志结束地址
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void label88_DoubleClick(object sender, EventArgs e)
- {
- textBox_LogAddrEnd.ReadOnly = false;
- }
- /// <summary>
- /// 存储器自动读取选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_ReadRanFlash_AutoSW.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_ReadRanFlash_AutoSW.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// 系统开机按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- byte[] Data = new byte[1];
- Data[0] = 0xF1;
- if (mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data))
- {
- 开机ToolStripMenuItem.Checked = true;
- 关机ToolStripMenuItem.Checked = false;
- }
- }
- /// <summary>
- /// 系统关机按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- byte[] Data = new byte[1];
- Data[0] = 0xF0;
- if (mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data))
- {
- 开机ToolStripMenuItem.Checked = false;
- 关机ToolStripMenuItem.Checked = true;
- }
- }
- /// <summary>
- /// 连接开机选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 断开关机选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 识别通讯盒选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- /// <summary>
- /// 将配置信息导出为cfg文件
- /// </summary>
- private void ConfigFileSave(bool DeleteFlag, string FileName)
- {
- if (DeleteFlag)
- {
- if (File.Exists(FileName))
- File.Delete(FileName);
- }
- string CfgFileInfo = "";
- CfgFileInfo += "[PortSet]" + "\r\n";
- CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
- CfgFileInfo += "PortBaudrate:" + toolStripComboBox_Baudrate.Text + "\r\n";
- CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[Option]" + "\r\n";
- CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
- CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[ServerSet]" + "\r\n";
- CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
- CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
- CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
- CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
- CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[MacInfo]" + "\r\n";
- CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
- CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
- CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
- CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
- CfgFileInfo += "\r\n";
- CfgFileInfo += "[LogAddress]" + "\r\n";
- CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
- CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
- System.IO.File.WriteAllText(FileName, CfgFileInfo);
- }
- /// <summary>
- /// 配置状态更新,点击时保存
- /// </summary>
- private void ConfigFileSave_Click(object sender, EventArgs e)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 文本框修改结束,回车保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- }
- /// <summary>
- /// 允许离线使用
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 允许ToolStripMenuItem.Checked = true;
- 不允许ToolStripMenuItem.Checked = false;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 允许ToolStripMenuItem.Checked = false;
- 不允许ToolStripMenuItem.Checked = true;
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 允许ToolStripMenuItem.Checked = false;
- 不允许ToolStripMenuItem.Checked = true;
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 允许ToolStripMenuItem.Checked = false;
- 不允许ToolStripMenuItem.Checked = true;
- }
- }
- /// <summary>
- /// 不允许离线使用
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 允许ToolStripMenuItem.Checked = false;
- 不允许ToolStripMenuItem.Checked = true;
- ConfigFileSave(true, localInfo.LocalPath + localInfo.ConfigFileName);
- }
- /// <summary>
- /// 弹出扫码按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ScanCode_Click(object sender, EventArgs e)
- {
- Scan scan_form = new Scan();
- scan_form.ShowDialog();
- do
- {
- if (scan_form.textBox_Code.Text == string.Empty)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- break;
- }
- string ScanInfo = scan_form.textBox_Code.Text;
- string regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
- string[] InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
- if (InfoList.Length >= 2)
- {
- //写入型号
- textBox_FacModeName.Text = InfoList[0];
- string Mode = textBox_FacModeName.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- //写入SN
- textBox_FacModeNum.Text = InfoList[1];
- string SN = textBox_FacModeNum.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- break;
- }
- } while (false);
- scan_form.Dispose();
- }
- private void 服务器配置ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- IP地址ToolStripMenuItem.Visible = true;
- 端口ToolStripMenuItem.Visible = true;
- 用户名ToolStripMenuItem.Visible = true;
- 密码ToolStripMenuItem.Visible = true;
- 存储路径ToolStripMenuItem.Visible = true;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- IP地址ToolStripMenuItem.Visible = false;
- 端口ToolStripMenuItem.Visible = false;
- 用户名ToolStripMenuItem.Visible = false;
- 密码ToolStripMenuItem.Visible = false;
- 存储路径ToolStripMenuItem.Visible = false;
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- IP地址ToolStripMenuItem.Visible = false;
- 端口ToolStripMenuItem.Visible = false;
- 用户名ToolStripMenuItem.Visible = false;
- 密码ToolStripMenuItem.Visible = false;
- 存储路径ToolStripMenuItem.Visible = false;
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- IP地址ToolStripMenuItem.Visible = false;
- 端口ToolStripMenuItem.Visible = false;
- 用户名ToolStripMenuItem.Visible = false;
- 密码ToolStripMenuItem.Visible = false;
- 存储路径ToolStripMenuItem.Visible = false;
- }
- }
- private void 生产信息ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //输入用户名
- EnterForm1.ShowDialog();
- try
- {
- if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
- {
- if (EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 生产商ToolStripMenuItem.Visible = true;
- 生产地ToolStripMenuItem.Visible = true;
- 生产日期ToolStripMenuItem.Visible = true;
- 产品标识ToolStripMenuItem.Visible = true;
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 生产商ToolStripMenuItem.Visible = false;
- 生产地ToolStripMenuItem.Visible = false;
- 生产日期ToolStripMenuItem.Visible = false;
- 产品标识ToolStripMenuItem.Visible = false;
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 生产商ToolStripMenuItem.Visible = false;
- 生产地ToolStripMenuItem.Visible = false;
- 生产日期ToolStripMenuItem.Visible = false;
- 产品标识ToolStripMenuItem.Visible = false;
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- 生产商ToolStripMenuItem.Visible = false;
- 生产地ToolStripMenuItem.Visible = false;
- 生产日期ToolStripMenuItem.Visible = false;
- 产品标识ToolStripMenuItem.Visible = false;
- }
- }
- }
- }
|