Form1.cs 221 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Runtime.InteropServices;
  9. using System.Text.RegularExpressions;
  10. using System.Threading;
  11. using System.Windows.Forms;
  12. namespace Welling_Motor_Debug_Tool
  13. {
  14. public partial class Form1 : Form
  15. {
  16. #region 变量定义
  17. //串口实例
  18. Serial_Process mySerialProcess = new Serial_Process();
  19. string PortNumSave = "";
  20. string PortBaudrateSave = "";
  21. //FTP实例
  22. ftp myFtp = new ftp();
  23. //本地存储数据路径
  24. string LocalPath = "";
  25. string ConfigFileName = "C:\\Temp\\Config.ttcfg";
  26. //MC运行信息超时计数
  27. bool MC_RunInfo_Refresh = false;
  28. ushort MC_RunInfo_Refresh_Cnt = 0;
  29. //MC调试信息超时计数
  30. bool MC_DebugInfo_Refresh = false;
  31. ushort MC_DebugInfo_Refresh_Cnt = 0;
  32. //MC故障码超时计数
  33. bool MC_ErrorCode_Refresh = false;
  34. ushort MC_ErrorCode_Refresh_Cnt = 0;
  35. //配置参数实例
  36. Params myParams = new Params();
  37. //记录文件名称
  38. string RunInfoSaveFilename = "";
  39. //BMS运行信息超时计数
  40. bool BMS_RunInfo_Refresh = false;
  41. ushort BMS_RunInfo_Refresh_Cnt = 0;
  42. //生产模式关机指令反馈装
  43. bool PowerOffAckStatus = false;
  44. #endregion
  45. #region 故障日志结构体定义
  46. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  47. [StructLayout(LayoutKind.Sequential)]
  48. public struct MC_ErrorLogSaveInfo_Struct_t
  49. {
  50. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  51. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  52. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  53. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  54. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  55. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  56. //电机运行信息,占用空间32bytes
  57. [StructLayout(LayoutKind.Sequential)]
  58. public struct MC_RunInfo_Struct_t
  59. {
  60. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  61. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  62. public ushort Power; //电功率 1W,地址偏移4
  63. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  64. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  65. public byte Cadence; //踏频 1rpm,地址偏移10
  66. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  67. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  68. public byte GearSt; //助力档位,地址偏移13
  69. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  70. public byte SOC; //剩余电量 1%,地址偏移15
  71. public ushort RemainDistance; //续航里程 1km,地址偏移16
  72. public ushort Torque_AD; //力矩寄存器,地址偏移18
  73. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  74. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  75. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  76. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  77. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  78. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  79. public UInt32 RS; //预留 4bytes
  80. };
  81. [MarshalAs(UnmanagedType.Struct)]
  82. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  83. //控制变量
  84. public Int16 IqCurrent; //Pu, 地址偏移 48
  85. public Int16 IqVoltage; //Pu, 地址偏移 50
  86. public Int16 IdCurrent; //Pu, 地址偏移 52
  87. public Int16 IdVoltage; //Pu, 地址偏移 54
  88. //状态机
  89. public UInt16 FSM; //高到低依次表示系统状态机、二层状态机、电机状态机、助力状态机, 地址偏移 56
  90. //预留
  91. public UInt16 RS1;
  92. public UInt16 RS2;
  93. public UInt16 RS3;
  94. };
  95. #endregion
  96. public Form1()
  97. {
  98. InitializeComponent();
  99. //检查配置文件
  100. if (File.Exists(ConfigFileName)) //存在配置文件,导入配置信息
  101. {
  102. //打开文件
  103. StreamReader objReader = new StreamReader(ConfigFileName);
  104. string sLine = "";
  105. ArrayList array_CfgInfo = new ArrayList();
  106. array_CfgInfo.Clear();
  107. while (sLine != null)
  108. {
  109. sLine = objReader.ReadLine();
  110. array_CfgInfo.Add(sLine);
  111. }
  112. objReader.Close();
  113. //解析配置文件
  114. try
  115. {
  116. //Port Set
  117. PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
  118. PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
  119. 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
  120. 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
  121. 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
  122. //Option
  123. 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
  124. 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
  125. 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
  126. //Server Set
  127. toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
  128. toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
  129. toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
  130. toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
  131. toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
  132. //MacInfo
  133. toolStripTextBox_MAC.Text= array_CfgInfo[19].ToString().Split(':')[1];
  134. toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
  135. toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
  136. toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
  137. //Log Address
  138. textBox_LogAddrBegin.Text = array_CfgInfo[25].ToString().Split(':')[1];
  139. textBox_LogAddrEnd.Text = array_CfgInfo[26].ToString().Split(':')[1];
  140. }
  141. catch (System.Exception)
  142. {
  143. timer_1s.Enabled = false;
  144. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  145. timer_1s.Enabled = true;
  146. ConfigFileSave(false, ConfigFileName);
  147. }
  148. }
  149. else //不存在配置文件,生成文件写入默认值
  150. {
  151. ConfigFileSave(false, ConfigFileName);
  152. }
  153. //配置网络FTP服务器
  154. myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text);
  155. //配置本地数据存储路径
  156. LocalPath = Directory.GetCurrentDirectory() + "\\" + toolStripTextBox_ServerPath.Text;
  157. //检查本地文件夹
  158. if (!Directory.Exists(LocalPath))
  159. Directory.CreateDirectory(LocalPath);
  160. //创建线程,定时检测网络连接状态
  161. Thread th = new Thread(NetworkCheck);
  162. th.IsBackground = true;
  163. th.Start();
  164. }
  165. /// <summary>
  166. /// 检查网络状态线程
  167. /// </summary>
  168. private void NetworkCheck()
  169. {
  170. //初始化第一次连接FTP服务器
  171. bool Result = myFtp.CheckFtp();
  172. this.Invoke((EventHandler)(delegate
  173. {
  174. if (Result == true)//服务器连接成功
  175. {
  176. label_Server_ComStatus.Text = "网络已连接";
  177. label_ServerStatus.BackColor = Color.Green;
  178. myFtp.IsNetConnected = true;
  179. }
  180. else//服务器连接失败
  181. {
  182. label_Server_ComStatus.Text = "网络断开";
  183. label_ServerStatus.BackColor = Color.Red;
  184. myFtp.IsNetConnected = false;
  185. if (允许ToolStripMenuItem.Checked == false) ///不允许离线使用,自动关闭
  186. {
  187. timer_1s.Enabled = false;
  188. MessageBox.Show("网络断开,将自动关闭!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  189. timer_1s.Enabled = true;
  190. this.Close();
  191. }
  192. else //离线使用
  193. {
  194. timer_1s.Enabled = false;
  195. MessageBox.Show("网络断开,离线使用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  196. timer_1s.Enabled = true;
  197. }
  198. }
  199. }));
  200. //创建定时器,定时30s检查网络
  201. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  202. timer_CheckNet.Enabled = true;
  203. timer_CheckNet.Interval = 30000;
  204. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  205. timer_CheckNet.Start();
  206. while (true)
  207. {
  208. Thread.Sleep(1);
  209. }
  210. }
  211. /// <summary>
  212. /// 线程中定时任务,检查网络状态
  213. /// </summary>
  214. /// <param name="sender"></param>
  215. /// <param name="e"></param>
  216. private void timer_CheckNet_Tick(object sender, EventArgs e)
  217. {
  218. //连接FTP服务器
  219. bool Result = myFtp.CheckFtp();
  220. this.Invoke((EventHandler)(delegate
  221. {
  222. if (Result == true)//服务器连接成功
  223. {
  224. label_Server_ComStatus.Text = "网络已连接";
  225. label_ServerStatus.BackColor = Color.Green;
  226. myFtp.IsNetConnected = true;
  227. }
  228. else//服务器连接失败
  229. {
  230. label_Server_ComStatus.Text = "网络断开";
  231. label_ServerStatus.BackColor = Color.Red;
  232. myFtp.IsNetConnected = false;
  233. }
  234. }));
  235. }
  236. #region 非独占性延时函数
  237. public static void Delay_ms(int milliSecond)
  238. {
  239. int start = Environment.TickCount;
  240. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  241. {
  242. Application.DoEvents();
  243. }
  244. }
  245. #endregion
  246. private void Form1_Load(object sender, System.EventArgs e)
  247. {
  248. //页面初始化
  249. label_BuildTime.Text= "编译时间:"+ System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
  250. label_Computername.Text = "用户名:" + System.Environment.UserName;
  251. //下拉控件初始值设定
  252. comboBox_WorkMode.SelectedIndex = 0;
  253. comboBox_GearSt.SelectedIndex = 0;
  254. comboBox_LightSwitch.SelectedIndex = 1;
  255. comboBox_OBC_SetGearST.SelectedIndex = 0;
  256. comboBox_OBC_LightSw.SelectedIndex = 1;
  257. comboBox_AssistTorque.SelectedIndex = 0;
  258. comboBox_AssistCadence.SelectedIndex = 0;
  259. //combobox事件定义
  260. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  261. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  262. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  263. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  264. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  265. //端口设置
  266. mySerialProcess.Init();
  267. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  268. if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
  269. {
  270. try
  271. {
  272. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
  273. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
  274. PortConnect();
  275. }
  276. catch (System.Exception)
  277. {
  278. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  279. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
  280. timer_1s.Enabled = false;
  281. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  282. timer_1s.Enabled = true;
  283. }
  284. }
  285. else //否则采用默认值
  286. {
  287. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  288. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
  289. }
  290. //创建线程,定时解析数据
  291. Thread th = new Thread(Task_SerialProcess);
  292. th.IsBackground = true;
  293. th.Start();
  294. }
  295. #region 结构体与字节流相互转换
  296. public static class MyConverter
  297. {
  298. /// <summary>
  299. /// 由结构体转换为byte数组
  300. /// </summary>
  301. public static byte[] StructureToByte<T>(T structure)
  302. {
  303. int size = Marshal.SizeOf(typeof(T));
  304. byte[] buffer = new byte[size];
  305. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  306. try
  307. {
  308. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  309. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  310. }
  311. finally
  312. {
  313. Marshal.FreeHGlobal(bufferIntPtr);
  314. }
  315. return buffer;
  316. }
  317. /// <summary>
  318. /// 由byte数组转换为结构体
  319. /// </summary>
  320. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  321. {
  322. object structure = null;
  323. int size = Marshal.SizeOf(typeof(T));
  324. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  325. try
  326. {
  327. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  328. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  329. }
  330. finally
  331. {
  332. Marshal.FreeHGlobal(allocIntPtr);
  333. }
  334. return (T)structure;
  335. }
  336. }
  337. #endregion
  338. #region 故障日志解析显示
  339. private void ErrorLogDisplay(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  340. {
  341. string SaveData = "";
  342. //Log1
  343. if (Log1.Error_Index != 0xFFFF)
  344. {
  345. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  346. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  347. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  348. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  349. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  350. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  351. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  352. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  353. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  354. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  355. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  356. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  357. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  358. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  359. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  360. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  361. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  362. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  363. {
  364. SaveData += "续航:" + "---km" + ", ";
  365. }
  366. else
  367. {
  368. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  369. }
  370. SaveData += "力矩AD:" + Convert.ToString(Log1.RunInfo.Torque_AD) + ", ";
  371. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  372. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "℃" + ", ";
  373. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "℃" + ", ";
  374. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "℃" + ", ";
  375. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  376. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  377. SaveData += "q轴电流:" + Convert.ToString(Log1.IqCurrent) + ", ";
  378. SaveData += "q轴电压:" + Convert.ToString(Log1.IqVoltage) + ", ";
  379. SaveData += "d轴电流:" + Convert.ToString(Log1.IdCurrent) + ", ";
  380. SaveData += "d轴电压:" + Convert.ToString(Log1.IdVoltage) + ", ";
  381. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  382. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  383. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  384. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  385. SaveData += "\r\n\r\n";
  386. richTextBox_Record.AppendText(SaveData);
  387. SaveData = "";
  388. }
  389. //Log2
  390. if (Log2.Error_Index != 0xFFFF)
  391. {
  392. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  393. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  394. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  395. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  396. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  397. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  398. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  399. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  400. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  401. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  402. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  403. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  404. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  405. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  406. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  407. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  408. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  409. if ((Log2.RunInfo.RemainDistance == 0xEEEE) || (Log2.RunInfo.RemainDistance == 0xFFFF))
  410. {
  411. SaveData += "续航:" + "---km" + ", ";
  412. }
  413. else
  414. {
  415. SaveData += "续航:" + Convert.ToString(Log2.RunInfo.RemainDistance) + "km" + ", ";
  416. }
  417. SaveData += "力矩AD:" + Convert.ToString(Log2.RunInfo.Torque_AD) + ", ";
  418. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  419. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  420. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  421. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  422. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  423. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  424. SaveData += "q轴电流:" + Convert.ToString(Log2.IqCurrent) + ", ";
  425. SaveData += "q轴电压:" + Convert.ToString(Log2.IqVoltage) + ", ";
  426. SaveData += "d轴电流:" + Convert.ToString(Log2.IdCurrent) + ", ";
  427. SaveData += "d轴电压:" + Convert.ToString(Log2.IdVoltage) + ", ";
  428. SaveData += "系统状态机:" + Convert.ToString((Log1.FSM & 0xF000) >> 12) + ", ";
  429. SaveData += "二层状态机:" + Convert.ToString((Log1.FSM & 0x0F00) >> 8) + ", ";
  430. SaveData += "电机状态机:" + Convert.ToString((Log1.FSM & 0x00F0) >> 4) + ", ";
  431. SaveData += "助力状态机:" + Convert.ToString((Log1.FSM & 0x000F)) + ", ";
  432. SaveData += "\r\n\r\n";
  433. richTextBox_Record.AppendText(SaveData);
  434. SaveData = "";
  435. }
  436. }
  437. #endregion
  438. #region 串口数据解析线程
  439. /// <summary>
  440. /// 串口数据解析线程
  441. /// </summary>
  442. private void Task_SerialProcess()
  443. {
  444. //创建定时器,定时读取串口数据
  445. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  446. timer_ReadSerial.Enabled = true;
  447. timer_ReadSerial.Interval = 20;
  448. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  449. timer_ReadSerial.Start();
  450. while (true)
  451. {
  452. Thread.Sleep(1);
  453. };
  454. }
  455. /// <summary>
  456. /// 串口解析定时器
  457. /// </summary>
  458. /// <param name="sender"></param>
  459. /// <param name="e"></param>
  460. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  461. {
  462. //串口解析
  463. Serial_process(mySerialProcess.buffer);
  464. }
  465. #endregion
  466. #region 数据解析
  467. public void Serial_process(List<byte> buffer)
  468. {
  469. byte DataNum = 0; //记录每条命令数据段的长度
  470. ushort PackageID, Cmd;
  471. byte[] Data = new byte[1024];
  472. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  473. {
  474. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  475. {
  476. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  477. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  478. {
  479. int CmdLen = buffer[5];
  480. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  481. buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
  482. while (CmdLen > 0) //读取命令段
  483. {
  484. Cmd = (ushort)(buffer[0] * 256 + buffer[1]);
  485. DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
  486. if (DataNum <= (CmdLen - 2))
  487. {
  488. for (int i = 0; i < DataNum; i++)
  489. {
  490. Data[i] = buffer[i + 2];
  491. }
  492. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  493. buffer.RemoveRange(0, DataNum);//移除处理过的数据段
  494. CmdLen -= (DataNum + 2);
  495. if (CmdLen < 2)
  496. {
  497. buffer.RemoveRange(0, CmdLen + 2);
  498. return;
  499. }
  500. }
  501. else
  502. {
  503. buffer.RemoveRange(0, CmdLen + 11);
  504. }
  505. }
  506. }
  507. else
  508. {
  509. buffer.RemoveAt(0);//ID不对
  510. }
  511. }
  512. else
  513. {
  514. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  515. }
  516. }
  517. }
  518. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  519. {
  520. int DataTemp;
  521. ushort uData16;
  522. unchecked
  523. {
  524. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  525. }
  526. #region 解析发送给CDL的指令
  527. if (ID == 0x7FF)
  528. {
  529. switch (CmdTemp)
  530. {
  531. case 0x1100://
  532. {
  533. unchecked
  534. {
  535. this.Invoke((EventHandler)(delegate
  536. {
  537. //CDL连接成功
  538. mySerialProcess.CDL_Online_Flag = true;
  539. MessageBox.Show("连接成功!", "提示");
  540. }));
  541. }
  542. break;
  543. }
  544. default: break;
  545. }
  546. }
  547. #endregion
  548. #region 解析电机的命令
  549. else if ((ID == 0x715) || (ID == 0x710))
  550. {
  551. switch (CmdTemp)
  552. {
  553. case 0x1020://电机运行信息
  554. {
  555. unchecked
  556. {
  557. this.Invoke((EventHandler)(delegate
  558. {
  559. MC_RunInfo_Refresh = true;
  560. //车速
  561. DataTemp = (int)(Data[1] * 256 + Data[0]);
  562. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  563. //输出转速
  564. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  565. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  566. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  567. Class_MotorSpeed.Data = DataTemp;
  568. //电功率
  569. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  570. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  571. //母线电压
  572. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  573. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  574. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  575. //母线电流
  576. DataTemp = (short)(Data[9] * 256 + Data[8]);
  577. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  578. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  579. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  580. Class_CurrentData.Data = DataTemp;
  581. //踏频
  582. DataTemp = (ushort)(Data[10]);
  583. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  584. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  585. Class_CadenceData.Data = DataTemp;
  586. //踩踏力矩
  587. DataTemp = (ushort)(Data[11]);
  588. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  589. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  590. Class_TorqueData.Data = DataTemp;
  591. //踩踏方向
  592. DataTemp = (ushort)(Data[12]);
  593. if (DataTemp == 0)
  594. {
  595. textBox_RunInfo_Dir.Text = "正向";
  596. }
  597. else if (DataTemp == 1)
  598. {
  599. textBox_RunInfo_Dir.Text = "反向";
  600. }
  601. else if (DataTemp == 2)
  602. {
  603. textBox_RunInfo_Dir.Text = "停止";
  604. }
  605. //助力档位
  606. DataTemp = (ushort)(Data[13]);
  607. if (DataTemp == 0x33)
  608. {
  609. textBox_RunInfo_GearSt.Text = "SMART";
  610. //comboBox_GearSt.SelectedIndex = 5;
  611. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  612. }
  613. else if (DataTemp == 0x22)
  614. {
  615. textBox_RunInfo_GearSt.Text = "WALK";
  616. //comboBox_GearSt.SelectedIndex = 6;
  617. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  618. }
  619. else
  620. {
  621. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  622. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  623. //comboBox_GearSt.SelectedIndex = DataTemp;
  624. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  625. }
  626. //大灯状态
  627. DataTemp = (ushort)(Data[14]);
  628. if (DataTemp == 0xF0)
  629. {
  630. textBox_RunInfo_LightSwitch.Text = "OFF";
  631. //comboBox_LightSwitch.SelectedIndex = 1;
  632. //comboBox_OBC_LightSw.SelectedIndex = 1;
  633. }
  634. else if (DataTemp == 0xF1)
  635. {
  636. textBox_RunInfo_LightSwitch.Text = "ON";
  637. //comboBox_LightSwitch.SelectedIndex = 0;
  638. //comboBox_OBC_LightSw.SelectedIndex = 0;
  639. }
  640. //剩余电量
  641. DataTemp = (ushort)(Data[15]);
  642. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  643. //剩余续航里程
  644. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  645. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  646. {
  647. textBox_RunInfo_Range.Text = "---";
  648. }
  649. else
  650. {
  651. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  652. }
  653. //预留(显示力矩Reg),空2bytes
  654. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  655. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  656. //平均功耗
  657. DataTemp = (ushort)(Data[20]);
  658. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  659. //PCB温度
  660. DataTemp = (ushort)(Data[21]);
  661. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40))+" ℃";
  662. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  663. Class_MotorTemp.Data = DataTemp - 40;
  664. //绕组温度
  665. DataTemp = (ushort)(Data[22]);
  666. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  667. //MCU温度
  668. DataTemp = (ushort)(Data[23]);
  669. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  670. //单次里程
  671. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  672. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  673. //单次时间
  674. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  675. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  676. //数据保存
  677. RunInfoAutoSave();
  678. }));
  679. }
  680. break;
  681. }
  682. case 0x1104://故障码
  683. {
  684. unchecked
  685. {
  686. this.Invoke((EventHandler)(delegate
  687. {
  688. MC_ErrorCode_Refresh = true;
  689. textBox_ErrorCode.Text =
  690. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  691. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  692. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  693. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  694. "H";
  695. }));
  696. }
  697. break;
  698. }
  699. case 0xA903://反馈指令
  700. {
  701. unchecked
  702. {
  703. this.Invoke((EventHandler)(delegate
  704. {
  705. timer_1s.Enabled = false;
  706. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  707. timer_1s.Enabled = true;
  708. //关机反馈
  709. PowerOffAckStatus = true;
  710. }));
  711. }
  712. break;
  713. }
  714. case 0xB226://马达参数
  715. {
  716. unchecked
  717. {
  718. this.Invoke((EventHandler)(delegate
  719. {
  720. richTextBox_MotorParam.Clear();
  721. for (int i = 0; i < myParams.MotorParma.Count; i++)
  722. {
  723. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  724. }
  725. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  726. }));
  727. }
  728. break;
  729. }
  730. case 0xB31A://整车信息
  731. {
  732. unchecked
  733. {
  734. this.Invoke((EventHandler)(delegate
  735. {
  736. richTextBox_BikeParam.Clear();
  737. for (int i = 0; i < myParams.BikeParma.Count; i++)
  738. {
  739. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  740. if (i == 8) //更新前后灯参数
  741. {
  742. comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
  743. comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
  744. comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
  745. }
  746. else if (i == 11) //更新开关机参数
  747. {
  748. textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
  749. textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
  750. textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
  751. }
  752. }
  753. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  754. //更新生产模式中整车参数
  755. textBox_FacModeWheelSize.Text = (Data[1] * 256 + Data[0]).ToString();//周长
  756. textBox_FacModeSpeedLimit.Text= (Data[5] * 256 + Data[4]).ToString();//限速
  757. DataTemp = (int)(Data[13] * 256 + Data[12]);//助力方案1
  758. if (DataTemp == 0) comboBox_FacModeAssist1.SelectedIndex = 0;
  759. else if (DataTemp == 341) comboBox_FacModeAssist1.SelectedIndex = 1;
  760. else if (DataTemp == 682) comboBox_FacModeAssist1.SelectedIndex = 2;
  761. else comboBox_FacModeAssist1.SelectedIndex = 3;
  762. DataTemp = (int)(Data[15] * 256 + Data[14]);//助力方案2
  763. if (DataTemp == 0) comboBox_FacModeAssist2.SelectedIndex = 0;
  764. else if (DataTemp == 341) comboBox_FacModeAssist2.SelectedIndex = 1;
  765. else if (DataTemp == 682) comboBox_FacModeAssist2.SelectedIndex = 2;
  766. else comboBox_FacModeAssist2.SelectedIndex = 3;
  767. DataTemp = (int)(Data[17] * 256 + Data[16]);//灯压
  768. if (DataTemp == 6) comboBox_FacModeLightVol.SelectedIndex = 0;
  769. else if (DataTemp == 12) comboBox_FacModeLightVol.SelectedIndex = 1;
  770. else comboBox_FacModeLightVol.SelectedIndex = 2;
  771. DataTemp = (int)(Data[21] * 256 + Data[20]);//启动模式
  772. if (DataTemp == 1) comboBox_FacModeStartMode.SelectedIndex = 0;
  773. else if (DataTemp == 3) comboBox_FacModeStartMode.SelectedIndex = 2;
  774. else comboBox_FacModeStartMode.SelectedIndex = 1;
  775. }));
  776. }
  777. break;
  778. }
  779. case 0xB420://控制器参数
  780. {
  781. unchecked
  782. {
  783. this.Invoke((EventHandler)(delegate
  784. {
  785. richTextBox_ControlParam.Clear();
  786. for (int i = 0; i < myParams.ControlParma.Count; i++)
  787. {
  788. richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  789. }
  790. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  791. }));
  792. }
  793. break;
  794. }
  795. case 0xB528://传感器参数
  796. {
  797. unchecked
  798. {
  799. this.Invoke((EventHandler)(delegate
  800. {
  801. richTextBox_SensorParam.Clear();
  802. for (int i = 0; i < myParams.SensorParam.Count; i++)
  803. {
  804. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  805. }
  806. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  807. //更新生产模式页面传感器零点和标定值
  808. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  809. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  810. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  811. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  812. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  813. }));
  814. }
  815. break;
  816. }
  817. case 0xB64C://助力参数
  818. {
  819. unchecked
  820. {
  821. this.Invoke((EventHandler)(delegate
  822. {
  823. richTextBox_AssistParam.Clear();
  824. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  825. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  826. int index_3 = myParams.AssistParam.IndexOf("踏频助力加速限制");
  827. int index_4 = myParams.AssistParam.IndexOf("踏频助力电流步进");
  828. for (int i = 0; i < myParams.AssistParam.Count; i++)
  829. {
  830. if (i < index_1) //数据占用2bytes
  831. {
  832. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  833. }
  834. else if (i <= index_2) //数据占用4bytes
  835. {
  836. 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])) + ", ");
  837. }
  838. else if (i < index_3) //数据占用2bytes,无符号
  839. {
  840. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  841. }
  842. else if (i <= index_4) //数据占用2bytes,有符号
  843. {
  844. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  845. }
  846. else //数据占用2bytes,无符号
  847. {
  848. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  849. }
  850. }
  851. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  852. //更新生产模式中助力参数
  853. textBox_FacModeStartGain.Text = (Data[1] * 256 + Data[0]).ToString();//零速增益
  854. textBox_FacModeCircuitK.Text = (Data[45] * 256 + Data[44]).ToString();//电流阶梯
  855. textBox_FacModeFltCounter.Text = (Data[49] * 256 + Data[48]).ToString();//滤波脉冲
  856. textBox_FacModeSpeedLimitTh.Text = (Data[55] * 256 + Data[54]).ToString();//限速启动
  857. textBox_FacModeSpeedLimitEnd.Text = (Data[57] * 256 + Data[56]).ToString();//限速停止
  858. textBox_FacModeCadencePer.Text = (Data[59] * 256 + Data[58]).ToString();//踏频占比
  859. }));
  860. }
  861. break;
  862. }
  863. case 0xB74C://历史记录
  864. {
  865. unchecked
  866. {
  867. this.Invoke((EventHandler)(delegate
  868. {
  869. richTextBox_Record.Clear();
  870. for (int i = 0; i < myParams.Record.Count; i++)
  871. {
  872. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  873. }
  874. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  875. }));
  876. }
  877. break;
  878. }
  879. case 0xB83A://调试参数
  880. {
  881. unchecked
  882. {
  883. this.Invoke((EventHandler)(delegate
  884. {
  885. richTextBox_DebugParam.Clear();
  886. for (int i = 0; i < myParams.DebugParam.Count; i++)
  887. {
  888. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  889. }
  890. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  891. }));
  892. }
  893. break;
  894. }
  895. case 0xB904://存储标志
  896. {
  897. unchecked
  898. {
  899. this.Invoke((EventHandler)(delegate
  900. {
  901. ushort Flag = 0;
  902. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  903. if (Flag == 0)
  904. {
  905. radioButton_EE_SaveNo.Checked = true;
  906. radioButton_EE_SaveYes.Checked = false;
  907. }
  908. else
  909. {
  910. radioButton_EE_SaveNo.Checked = false;
  911. radioButton_EE_SaveYes.Checked = true;
  912. }
  913. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  914. if (Flag == 0)
  915. {
  916. radioButton_SIP_SaveNo.Checked = true;
  917. radioButton_SIP_SaveYes.Checked = false;
  918. }
  919. else
  920. {
  921. radioButton_SIP_SaveNo.Checked = false;
  922. radioButton_SIP_SaveYes.Checked = true;
  923. }
  924. }));
  925. }
  926. break;
  927. }
  928. case 0x1240://电机版本信息
  929. {
  930. unchecked
  931. {
  932. this.Invoke((EventHandler)(delegate
  933. {
  934. //电机型号
  935. textBox_Model.Text = "";
  936. textBox_OBC_ReadModel.Text = "";
  937. textBox_FacModeName.Text = "";
  938. for (ushort i = 0; i < 16; i++)
  939. {
  940. if (Data[i] == 0x2E)
  941. {
  942. break;
  943. }
  944. textBox_Model.Text += ((char)Data[i]).ToString();
  945. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  946. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  947. }
  948. Class_Motor_Ver.Mode = textBox_Model.Text;
  949. //电机SN
  950. textBox_SN.Text = "";
  951. textBox_OBC_ReadSN.Text = "";
  952. textBox_FacModeNum.Text = "";
  953. for (ushort i = 0; i < 16; i++)
  954. {
  955. if (Data[16 + i] == 0x2E)
  956. {
  957. break;
  958. }
  959. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  960. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  961. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  962. }
  963. Class_Motor_Ver.SN = textBox_SN.Text;
  964. //电机HW
  965. textBox_HW.Text = "";
  966. textBox_OBC_ReadHW.Text = "";
  967. textBox_FacModeHW.Text = "";
  968. for (ushort i = 0; i < 8; i++)//前8位:硬件板号
  969. {
  970. if (Data[32 + i] == 0x2E)
  971. {
  972. break;
  973. }
  974. else if (Data[32 + i] == 'r')
  975. {
  976. Data[32 + i] = (byte)'.';
  977. break;
  978. }
  979. string strTemp = "";
  980. strTemp = ((char)Data[32 + i]).ToString();
  981. textBox_HW.Text += strTemp;
  982. textBox_OBC_ReadHW.Text += strTemp;
  983. textBox_FacModeHW.Text += strTemp;
  984. }
  985. for (ushort i = 0; i < 4; i++)//9-12位:单片机型号
  986. {
  987. if (Data[40 + i] == 0x2E)
  988. {
  989. break;
  990. }
  991. else if (Data[40 + i] == 'r')
  992. {
  993. Data[40 + i] = (byte)'.';
  994. break;
  995. }
  996. string strTemp = "";
  997. strTemp = ((char)Data[40 + i]).ToString();
  998. textBox_HW.Text += strTemp;
  999. textBox_OBC_ReadHW.Text += strTemp;
  1000. textBox_FacModeHW.Text += strTemp;
  1001. }
  1002. for (ushort i = 0; i < 4; i++)//13-16位:单片机ID
  1003. {
  1004. string strTemp = "";
  1005. strTemp = Convert.ToString(Data[44 + i], 16).PadLeft(2, '0').ToUpper();
  1006. textBox_HW.Text += strTemp;
  1007. textBox_OBC_ReadHW.Text += strTemp;
  1008. textBox_FacModeHW.Text += strTemp;
  1009. }
  1010. Class_Motor_Ver.HW = textBox_HW.Text;
  1011. //电机FW
  1012. textBox_FW.Text = "";
  1013. textBox_OBC_ReadFW.Text = "";
  1014. textBox_FacModeFW.Text = "";
  1015. for (ushort i = 0; i < 16; i++)
  1016. {
  1017. if (Data[48 + i] == 0x2E)
  1018. {
  1019. break;
  1020. }
  1021. if (Data[48 + i] == 'r')
  1022. {
  1023. Data[48 + i] = (byte)'.';
  1024. }
  1025. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  1026. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  1027. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  1028. }
  1029. Class_Motor_Ver.FW = textBox_FW.Text;
  1030. }));
  1031. }
  1032. break;
  1033. }
  1034. case 0xA610://自定义1
  1035. {
  1036. unchecked
  1037. {
  1038. this.Invoke((EventHandler)(delegate
  1039. {
  1040. textBox_User1.Text = "";
  1041. for (ushort i = 0; i < 16; i++)
  1042. {
  1043. if (Data[i] == 0x2E)
  1044. {
  1045. break;
  1046. }
  1047. textBox_User1.Text += ((char)Data[i]).ToString();
  1048. }
  1049. }));
  1050. }
  1051. break;
  1052. }
  1053. case 0xA710://自定义2
  1054. {
  1055. unchecked
  1056. {
  1057. this.Invoke((EventHandler)(delegate
  1058. {
  1059. textBox_User2.Text = "";
  1060. for (ushort i = 0; i < 16; i++)
  1061. {
  1062. if (Data[i] == 0x2E)
  1063. {
  1064. break;
  1065. }
  1066. textBox_User2.Text += ((char)Data[i]).ToString();
  1067. }
  1068. }));
  1069. }
  1070. break;
  1071. }
  1072. case 0xA810://自定义1
  1073. {
  1074. unchecked
  1075. {
  1076. this.Invoke((EventHandler)(delegate
  1077. {
  1078. textBox_User3.Text = "";
  1079. for (ushort i = 0; i < 16; i++)
  1080. {
  1081. if (Data[i] == 0x2E)
  1082. {
  1083. break;
  1084. }
  1085. textBox_User3.Text += ((char)Data[i]).ToString();
  1086. }
  1087. }));
  1088. }
  1089. break;
  1090. }
  1091. case 0xA520://生产信息
  1092. {
  1093. unchecked
  1094. {
  1095. this.Invoke((EventHandler)(delegate
  1096. {
  1097. //生产商
  1098. textBox_MAC.Text = "";
  1099. for (ushort i = 0; i < 8; i++)
  1100. {
  1101. if (Data[i] == 0x2E)
  1102. {
  1103. break;
  1104. }
  1105. textBox_MAC.Text += ((char)Data[i]).ToString();
  1106. }
  1107. //生产地
  1108. textBox_MACAdd.Text = "";
  1109. for (ushort i = 0; i < 8; i++)
  1110. {
  1111. if (Data[8 + i] == 0x2E)
  1112. {
  1113. break;
  1114. }
  1115. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  1116. }
  1117. //生产日期
  1118. textBox_MACDate.Text = "";
  1119. for (ushort i = 0; i < 8; i++)
  1120. {
  1121. if (Data[16 + i] == 0x2E)
  1122. {
  1123. break;
  1124. }
  1125. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  1126. }
  1127. //品牌信息
  1128. textBox_PP.Text = "";
  1129. for (ushort i = 0; i < 8; i++)
  1130. {
  1131. if (Data[24 + i] == 0x2E)
  1132. {
  1133. break;
  1134. }
  1135. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  1136. }
  1137. }));
  1138. }
  1139. break;
  1140. }
  1141. case 0xA408://密钥
  1142. {
  1143. unchecked
  1144. {
  1145. this.Invoke((EventHandler)(delegate
  1146. {
  1147. textBox_Key.Text = "";
  1148. for (ushort i = 0; i < 8; i++)
  1149. {
  1150. textBox_Key.Text += ((char)Data[i]).ToString();
  1151. }
  1152. }));
  1153. }
  1154. break;
  1155. }
  1156. case 0xAB09://存储器数据
  1157. case 0xAB0A:
  1158. case 0xAB0B:
  1159. case 0xAB0C:
  1160. {
  1161. unchecked
  1162. {
  1163. this.Invoke((EventHandler)(delegate
  1164. {
  1165. long ByteNum = 0;
  1166. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  1167. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1168. {
  1169. for (int i = 0; i < ByteNum; i++)
  1170. {
  1171. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1172. }
  1173. }
  1174. else //根据设置自动转换10进制显示
  1175. {
  1176. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  1177. {
  1178. switch (ByteNum)
  1179. {
  1180. case 1:
  1181. {
  1182. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  1183. break;
  1184. }
  1185. case 2:
  1186. {
  1187. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  1188. break;
  1189. }
  1190. case 3:
  1191. {
  1192. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  1193. break;
  1194. }
  1195. case 4:
  1196. {
  1197. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  1198. break;
  1199. }
  1200. default:
  1201. {
  1202. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1203. break;
  1204. }
  1205. }
  1206. }
  1207. else //16进制显示
  1208. {
  1209. switch (ByteNum)
  1210. {
  1211. case 1:
  1212. {
  1213. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  1214. break;
  1215. }
  1216. case 2:
  1217. {
  1218. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1219. break;
  1220. }
  1221. case 3:
  1222. {
  1223. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1224. break;
  1225. }
  1226. case 4:
  1227. {
  1228. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1229. break;
  1230. }
  1231. default:
  1232. {
  1233. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  1234. break;
  1235. }
  1236. }
  1237. }
  1238. }
  1239. }));
  1240. }
  1241. break;
  1242. }
  1243. case 0xAB88://故障日志
  1244. {
  1245. unchecked
  1246. {
  1247. this.Invoke((EventHandler)(delegate
  1248. {
  1249. //电机存储的故障日志,一包128字节包含2条故障日志
  1250. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1251. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1252. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 8);
  1253. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(Data, 72);
  1254. //数据显示
  1255. ErrorLogDisplay(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1256. }));
  1257. }
  1258. break;
  1259. }
  1260. case 0x1401://在线检测结果
  1261. {
  1262. unchecked
  1263. {
  1264. this.Invoke((EventHandler)(delegate
  1265. {
  1266. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  1267. }));
  1268. }
  1269. break;
  1270. }
  1271. case 0x1510://骑行历史信息
  1272. {
  1273. unchecked
  1274. {
  1275. this.Invoke((EventHandler)(delegate
  1276. {
  1277. long DataTemp32;
  1278. //ODO里程
  1279. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  1280. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1281. //ODO时间
  1282. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  1283. if (DataTemp32 >= 60 * 100000)
  1284. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1285. else
  1286. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1287. //TRIP里程
  1288. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  1289. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  1290. //TRIP时间
  1291. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  1292. if (DataTemp32 >= 60 * 100000)
  1293. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  1294. else
  1295. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  1296. }));
  1297. }
  1298. break;
  1299. }
  1300. case 0x1720://客户信息
  1301. {
  1302. unchecked
  1303. {
  1304. this.Invoke((EventHandler)(delegate
  1305. {
  1306. //程序特性
  1307. textBox_SP.Text = "";
  1308. textBox_OBC_ReadSP.Text = "";
  1309. textBox_FacModeSP.Text = "";
  1310. for (ushort i = 0; i < 32; i++)
  1311. {
  1312. if (Data[i] == 0x2E)
  1313. {
  1314. break;
  1315. }
  1316. if (Data[i] == 'r')
  1317. {
  1318. Data[i] = (byte)'.';
  1319. }
  1320. textBox_SP.Text += ((char)Data[i]).ToString();
  1321. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  1322. textBox_FacModeSP.Text += ((char)Data[i]).ToString(); ;
  1323. }
  1324. //Git提交版本信息
  1325. textBox_FacModeGit.Text = "";
  1326. for (ushort i = 0; i < 9; i++)
  1327. {
  1328. textBox_FacModeGit.Text += ((char)Data[23 + i]).ToString();
  1329. }
  1330. Class_Motor_Ver.Special = textBox_SP.Text;
  1331. }));
  1332. }
  1333. break;
  1334. }
  1335. case 0xBA20: //调试信息
  1336. {
  1337. unchecked
  1338. {
  1339. this.Invoke((EventHandler)(delegate
  1340. {
  1341. MC_DebugInfo_Refresh = true;
  1342. //系统状态机
  1343. DataTemp = (short)(Data[0]);
  1344. textBox_DebugInfo_SysFun.Text = Convert.ToString(DataTemp);
  1345. //二层状态机
  1346. DataTemp = (short)(Data[1]);
  1347. textBox_DebugInfo_SecondFun.Text = Convert.ToString(DataTemp);
  1348. //电机状态机
  1349. DataTemp = (short)(Data[2]);
  1350. textBox_DebugInfo_MotorFun.Text = Convert.ToString(DataTemp);
  1351. //助力状态机
  1352. DataTemp = (short)(Data[3]);
  1353. textBox_DebugInfo_AssistFun.Text = Convert.ToString(DataTemp);
  1354. //IdRef
  1355. DataTemp = (short)(Data[5] * 256 + Data[4]);
  1356. textBox_DebugInfo_IdRef.Text = Convert.ToString(DataTemp);
  1357. //IqRef
  1358. DataTemp = (short)(Data[7] * 256 + Data[6]);
  1359. textBox_DebugInfo_IqRef.Text = Convert.ToString(DataTemp);
  1360. //UdRef
  1361. DataTemp = (short)(Data[9] * 256 + Data[8]);
  1362. textBox_DebugInfo_UdRef.Text = Convert.ToString(DataTemp);
  1363. //UqRef
  1364. DataTemp = (short)(Data[11] * 256 + Data[10]);
  1365. textBox_DebugInfo_UqRef.Text = Convert.ToString(DataTemp);
  1366. //瞬时力矩
  1367. DataTemp = (short)(Data[13] * 256 + Data[12]);
  1368. textBox_DebugInfo_TorquePu.Text = Convert.ToString(DataTemp);
  1369. //时间滤波力矩
  1370. DataTemp = (short)(Data[15] * 256 + Data[14]);
  1371. textBox_DebugInfo_TorqueFil.Text = Convert.ToString(DataTemp);
  1372. //踏频滤波力矩
  1373. DataTemp = (short)(Data[17] * 256 + Data[16]);
  1374. textBox_DebugInfo_TorqueCadence.Text = Convert.ToString(DataTemp);
  1375. //IdFdb
  1376. DataTemp = (short)(Data[19] * 256 + Data[18]);
  1377. textBox_DebugInfo_IdFdb.Text = Convert.ToString(DataTemp);
  1378. //IqFdb
  1379. DataTemp = (short)(Data[21] * 256 + Data[20]);
  1380. textBox_DebugInfo_IqFdb.Text = Convert.ToString(DataTemp);
  1381. //助力输出
  1382. DataTemp = (short)(Data[23] * 256 + Data[22]);
  1383. textBox_DebugInfo_AssistOut.Text = Convert.ToString(DataTemp);
  1384. //数据保存
  1385. RunInfoAutoSave();
  1386. }));
  1387. }
  1388. break;
  1389. }
  1390. default:
  1391. {
  1392. break;
  1393. }
  1394. }
  1395. }
  1396. #endregion
  1397. #region 解析BMS广播的命令
  1398. else if (ID == 0x720)
  1399. {
  1400. switch (CmdTemp)
  1401. {
  1402. case 0x1010://BMS运行信息
  1403. {
  1404. unchecked
  1405. {
  1406. this.Invoke((EventHandler)(delegate
  1407. {
  1408. BMS_RunInfo_Refresh = true;
  1409. richTextBox_OBC_BMS_RunInfo.Clear();
  1410. //电压
  1411. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  1412. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  1413. //电流
  1414. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  1415. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  1416. //剩余容量
  1417. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  1418. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  1419. //满充容量
  1420. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  1421. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mV" + "\r\n");
  1422. //电芯温度
  1423. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  1424. //剩余电量
  1425. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  1426. //电池状态
  1427. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  1428. //SOH
  1429. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %");
  1430. //循环次数
  1431. richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
  1432. }));
  1433. }
  1434. break;
  1435. }
  1436. default: break;
  1437. }
  1438. }
  1439. #endregion
  1440. #region 解析电机发送OBC的命令
  1441. else if (ID == 0x713)
  1442. {
  1443. switch (CmdTemp)
  1444. {
  1445. case 0x5408://电机用户参数
  1446. {
  1447. unchecked
  1448. {
  1449. this.Invoke((EventHandler)(delegate
  1450. {
  1451. richTextBox_OBC_ReadUserInfo.Clear();
  1452. //默认周长
  1453. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  1454. //启动模式
  1455. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  1456. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  1457. //限速
  1458. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  1459. //周长微调
  1460. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  1461. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  1462. //助力方案
  1463. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  1464. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  1465. //关机时间
  1466. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  1467. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  1468. }));
  1469. }
  1470. break;
  1471. }
  1472. case 0x5303://电机应答反馈
  1473. {
  1474. unchecked
  1475. {
  1476. this.Invoke((EventHandler)(delegate
  1477. {
  1478. timer_1s.Enabled = false;
  1479. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1480. timer_1s.Enabled = true;
  1481. }));
  1482. }
  1483. break;
  1484. }
  1485. default: break;
  1486. }
  1487. }
  1488. #endregion
  1489. }
  1490. #endregion
  1491. /// <summary>
  1492. /// 端口连接或断开
  1493. /// </summary>
  1494. private void PortConnect()
  1495. {
  1496. bool result = false;
  1497. if (连接ToolStripMenuItem.Text == "连接")
  1498. {
  1499. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
  1500. if (result)
  1501. {
  1502. toolStripComboBox_ComNum.Enabled = false;
  1503. toolStripComboBox_Baudrate.Enabled = false;
  1504. 刷新ToolStripMenuItem.Enabled = false;
  1505. 连接ToolStripMenuItem.Text = "断开";
  1506. 连接ToolStripMenuItem.Checked = true;
  1507. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  1508. label_PortStatus.BackColor = Color.Green;
  1509. }
  1510. }
  1511. else if (连接ToolStripMenuItem.Text == "断开")
  1512. {
  1513. checkBox_OBC_StartSetGearSt.Checked = false;
  1514. checkBox_OBC_StartReadBMS.Checked = false;
  1515. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1516. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  1517. toolStripComboBox_ComNum.Enabled = true;
  1518. toolStripComboBox_Baudrate.Enabled = true;
  1519. 刷新ToolStripMenuItem.Enabled = true;
  1520. 连接ToolStripMenuItem.Text = "连接";
  1521. 连接ToolStripMenuItem.Checked = false;
  1522. label_COM_Sta.Text = "连接状态:未连接";
  1523. label_PortStatus.BackColor = Color.Red;
  1524. }
  1525. }
  1526. /// <summary>
  1527. /// 端口连接事件
  1528. /// </summary>
  1529. /// <param name="sender"></param>
  1530. /// <param name="e"></param>
  1531. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  1532. {
  1533. PortConnect();
  1534. }
  1535. /// <summary>
  1536. /// 端口号刷新事件
  1537. /// </summary>
  1538. /// <param name="sender"></param>
  1539. /// <param name="e"></param>
  1540. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  1541. {
  1542. toolStripComboBox_ComNum.Items.Clear();
  1543. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  1544. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  1545. }
  1546. /// <summary>
  1547. /// 转速调节事件
  1548. /// </summary>
  1549. /// <param name="sender"></param>
  1550. /// <param name="e"></param>
  1551. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  1552. {
  1553. //生产模式转速设置值更新
  1554. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  1555. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  1556. //设置转速百分比
  1557. var Data = new byte[1];
  1558. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  1559. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  1560. }
  1561. /// <summary>
  1562. /// 存储标志修改事件
  1563. /// </summary>
  1564. /// <param name="sender"></param>
  1565. /// <param name="e"></param>
  1566. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  1567. {
  1568. 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
  1569. ConfigFileSave(true, ConfigFileName);
  1570. }
  1571. /// <summary>
  1572. /// 1s定时器
  1573. /// </summary>
  1574. /// <param name="sender"></param>
  1575. /// <param name="e"></param>
  1576. private void timer_1s_Tick(object sender, EventArgs e)
  1577. {
  1578. //时间更新
  1579. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString();
  1580. //MC_Runinfo超时清除
  1581. if (MC_RunInfo_Refresh == false)
  1582. {
  1583. MC_RunInfo_Refresh_Cnt++;
  1584. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  1585. {
  1586. MC_RunInfo_Clear();
  1587. MC_RunInfo_Refresh_Cnt = 0;
  1588. }
  1589. }
  1590. else
  1591. {
  1592. MC_RunInfo_Refresh_Cnt = 0;
  1593. }
  1594. MC_RunInfo_Refresh = false;
  1595. //MC_Debuginfo超时清除
  1596. if (MC_DebugInfo_Refresh == false)
  1597. {
  1598. MC_DebugInfo_Refresh_Cnt++;
  1599. if (MC_DebugInfo_Refresh_Cnt > 10)//5s
  1600. {
  1601. MC_DebugInfo_Clear();
  1602. MC_DebugInfo_Refresh_Cnt = 0;
  1603. }
  1604. }
  1605. else
  1606. {
  1607. MC_DebugInfo_Refresh_Cnt = 0;
  1608. }
  1609. MC_DebugInfo_Refresh = false;
  1610. //BMS_RunInfo超时清除
  1611. if (BMS_RunInfo_Refresh == false)
  1612. {
  1613. BMS_RunInfo_Refresh_Cnt++;
  1614. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  1615. {
  1616. richTextBox_OBC_BMS_RunInfo.Clear();
  1617. BMS_RunInfo_Refresh_Cnt = 0;
  1618. }
  1619. }
  1620. else
  1621. {
  1622. BMS_RunInfo_Refresh_Cnt = 0;
  1623. }
  1624. BMS_RunInfo_Refresh = false;
  1625. //故障码超时清除
  1626. if (MC_ErrorCode_Refresh == false)
  1627. {
  1628. MC_ErrorCode_Refresh_Cnt++;
  1629. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  1630. {
  1631. textBox_ErrorCode.Text = "---";
  1632. MC_ErrorCode_Refresh_Cnt = 0;
  1633. }
  1634. }
  1635. else
  1636. {
  1637. MC_ErrorCode_Refresh_Cnt = 0;
  1638. }
  1639. MC_ErrorCode_Refresh = false;
  1640. //CDL连接超时
  1641. if (识别通讯盒ToolStripMenuItem.Checked)
  1642. {
  1643. if (mySerialProcess.CDL_Online_Flag == false)
  1644. {
  1645. mySerialProcess.CDL_OnlineCheck_Cnt++;
  1646. if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
  1647. {
  1648. timer_1s.Enabled = false;
  1649. MessageBox.Show("连接失败!", "提示");
  1650. timer_1s.Enabled = true;
  1651. //关闭串口
  1652. mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
  1653. toolStripComboBox_ComNum.Enabled = true;
  1654. toolStripComboBox_Baudrate.Enabled = true;
  1655. 刷新ToolStripMenuItem.Enabled = true;
  1656. 连接ToolStripMenuItem.Text = "连接";
  1657. 连接ToolStripMenuItem.Checked = false;
  1658. label_COM_Sta.Text = "连接状态:未连接";
  1659. label_PortStatus.BackColor = Color.Red;
  1660. }
  1661. }
  1662. }
  1663. //OBC定时发送设置档位
  1664. if (checkBox_OBC_StartSetGearSt.Checked == true)
  1665. {
  1666. var CtrlCode = new byte[2];
  1667. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  1668. CtrlCode[0] = 0x33;
  1669. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  1670. CtrlCode[0] = 0x22;
  1671. else
  1672. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  1673. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  1674. CtrlCode[1] = 0xF1;
  1675. else
  1676. CtrlCode[1] = 0xF0;
  1677. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  1678. {
  1679. checkBox_OBC_StartSetGearSt.Checked = false;
  1680. }
  1681. }
  1682. //OBC定时发送查询电池
  1683. if (checkBox_OBC_StartReadBMS.Checked == true)
  1684. {
  1685. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  1686. {
  1687. checkBox_OBC_StartReadBMS.Checked = false;
  1688. }
  1689. }
  1690. //定时读取存储器
  1691. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  1692. {
  1693. var Address = new byte[4];
  1694. UInt32 Address_Begin;
  1695. UInt32 Addres_End;
  1696. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  1697. richTextBox_RamFlasgData.Clear();
  1698. do
  1699. {
  1700. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  1701. {
  1702. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1703. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1704. continue;
  1705. }
  1706. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  1707. {
  1708. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1709. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1710. continue;
  1711. }
  1712. else
  1713. {
  1714. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  1715. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  1716. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  1717. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  1718. if (Addres_End < Address_Begin)
  1719. {
  1720. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1721. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1722. continue;
  1723. }
  1724. else
  1725. {
  1726. var SendByte = new byte[8];
  1727. SendByte[0] = (byte)(Address_Begin >> 24);
  1728. SendByte[1] = (byte)(Address_Begin >> 16);
  1729. SendByte[2] = (byte)(Address_Begin >> 8);
  1730. SendByte[3] = (byte)(Address_Begin);
  1731. SendByte[4] = (byte)(Addres_End >> 24);
  1732. SendByte[5] = (byte)(Addres_End >> 16);
  1733. SendByte[6] = (byte)(Addres_End >> 8);
  1734. SendByte[7] = (byte)(Addres_End);
  1735. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  1736. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1737. }
  1738. }
  1739. } while (false);
  1740. }
  1741. }
  1742. /// <summary>
  1743. /// 字符串转成字节流
  1744. /// </summary>
  1745. /// <param name="hexStr"></param>
  1746. /// <param name="Flag_Space"></param>
  1747. /// <returns></returns>
  1748. public static byte[] HexStringToBytes(string hexStr, bool Flag_Space)
  1749. {
  1750. if (string.IsNullOrEmpty(hexStr))
  1751. {
  1752. return new byte[0];
  1753. }
  1754. if (hexStr.StartsWith("0x"))
  1755. {
  1756. hexStr = hexStr.Remove(0, 2);
  1757. }
  1758. var count = hexStr.Length;
  1759. var byteCount = 0;
  1760. if (Flag_Space == true)//相邻字节含空格
  1761. {
  1762. if ((count % 3) == 0)//最后字节含空格
  1763. {
  1764. byteCount = count / 3;
  1765. }
  1766. else if ((count % 3) == 2)//最后字节不含空格
  1767. {
  1768. byteCount = (count + 1) / 3;
  1769. }
  1770. else//数据无效
  1771. {
  1772. MessageBox.Show("相邻字节请插入空格!", "提示");
  1773. }
  1774. var result = new byte[byteCount];
  1775. for (int ii = 0; ii < byteCount; ++ii)
  1776. {
  1777. var tempBytes = Byte.Parse(hexStr.Substring(3 * ii, 2), System.Globalization.NumberStyles.HexNumber);
  1778. result[ii] = tempBytes;
  1779. }
  1780. return result;
  1781. }
  1782. else if (Flag_Space == false)//相邻字节不含空格
  1783. {
  1784. if (count % 2 == 1)
  1785. {
  1786. MessageBox.Show("请删除相邻字节之间空格!", "提示");
  1787. }
  1788. byteCount = count / 2;
  1789. var result = new byte[byteCount];
  1790. for (int ii = 0; ii < byteCount; ++ii)
  1791. {
  1792. var tempBytes = Byte.Parse(hexStr.Substring(2 * ii, 2), System.Globalization.NumberStyles.HexNumber);
  1793. result[ii] = tempBytes;
  1794. }
  1795. return result;
  1796. }
  1797. else
  1798. {
  1799. return new byte[0];
  1800. }
  1801. }
  1802. /// <summary>
  1803. /// 运行信息清除
  1804. /// </summary>
  1805. private void MC_RunInfo_Clear()
  1806. {
  1807. foreach (Control c in tabPage_RunInfo.Controls)
  1808. {
  1809. if ((c is TextBox))
  1810. {
  1811. if(c.Name != textBox_ErrorCode.ToString())
  1812. c.Text = "---";
  1813. }
  1814. }
  1815. }
  1816. /// <summary>
  1817. /// 调试信息清除
  1818. /// </summary>
  1819. private void MC_DebugInfo_Clear()
  1820. {
  1821. foreach (Control c in tabPage_DebugInfo.Controls)
  1822. {
  1823. if ((c is TextBox))
  1824. {
  1825. if (c.Name != textBox_ErrorCode.ToString())
  1826. c.Text = "---";
  1827. }
  1828. }
  1829. }
  1830. /// <summary>
  1831. /// 读取马达参数
  1832. /// </summary>
  1833. /// <param name="sender"></param>
  1834. /// <param name="e"></param>
  1835. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  1836. {
  1837. richTextBox_MotorParam.Clear();
  1838. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  1839. }
  1840. /// <summary>
  1841. /// 写入马达参数
  1842. /// </summary>
  1843. /// <param name="sender"></param>
  1844. /// <param name="e"></param>
  1845. private void button_Write_Click(object sender, EventArgs e)
  1846. {
  1847. var ConfigParam = new byte[40];
  1848. for (int i = 0; i < 40; i++)
  1849. ConfigParam[i] = 0;
  1850. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1851. short wDataTemp = 0;
  1852. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
  1853. try
  1854. {
  1855. for (int i = 0; i < strDataTemp.Length; i++)
  1856. {
  1857. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  1858. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  1859. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  1860. }
  1861. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  1862. }
  1863. catch (Exception)
  1864. {
  1865. timer_1s.Enabled = false;
  1866. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1867. timer_1s.Enabled = true;
  1868. }
  1869. }
  1870. /// <summary>
  1871. /// 读取整车信息
  1872. /// </summary>
  1873. /// <param name="sender"></param>
  1874. /// <param name="e"></param>
  1875. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  1876. {
  1877. richTextBox_BikeParam.Clear();
  1878. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  1879. }
  1880. /// <summary>
  1881. /// 写入整车信息
  1882. /// </summary>
  1883. /// <param name="sender"></param>
  1884. /// <param name="e"></param>
  1885. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  1886. {
  1887. var ConfigParam = new byte[28];
  1888. for (int i = 0; i < 28; i++)
  1889. ConfigParam[i] = 0;
  1890. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1891. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1892. try
  1893. {
  1894. for (int i = 0; i < strDataTemp.Length; i++)
  1895. {
  1896. short wDataTemp = 0;
  1897. //前后灯参数修改
  1898. if (i == 8)
  1899. {
  1900. wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
  1901. wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
  1902. wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
  1903. }
  1904. //开关机参数
  1905. else if (i == 11)
  1906. {
  1907. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
  1908. wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
  1909. wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
  1910. }
  1911. else
  1912. {
  1913. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  1914. }
  1915. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  1916. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  1917. }
  1918. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  1919. }
  1920. catch (Exception)
  1921. {
  1922. timer_1s.Enabled = false;
  1923. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1924. timer_1s.Enabled = true;
  1925. }
  1926. }
  1927. /// <summary>
  1928. /// 读取控制器参数
  1929. /// </summary>
  1930. /// <param name="sender"></param>
  1931. /// <param name="e"></param>
  1932. private void button_ReadControlParam_Click(object sender, EventArgs e)
  1933. {
  1934. richTextBox_ControlParam.Clear();
  1935. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  1936. }
  1937. /// <summary>
  1938. /// 写入控制器参数
  1939. /// </summary>
  1940. /// <param name="sender"></param>
  1941. /// <param name="e"></param>
  1942. private void button_WriteControlParam_Click(object sender, EventArgs e)
  1943. {
  1944. var ConfigParam = new byte[34];
  1945. for (int i = 0; i < 34; i++)
  1946. ConfigParam[i] = 0;
  1947. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1948. ushort uwDataTemp = 0;
  1949. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1950. try
  1951. {
  1952. for (int i = 0; i < strDataTemp.Length; i++)
  1953. {
  1954. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1955. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1956. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1957. }
  1958. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  1959. }
  1960. catch (Exception)
  1961. {
  1962. timer_1s.Enabled = false;
  1963. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1964. timer_1s.Enabled = true;
  1965. }
  1966. }
  1967. /// <summary>
  1968. /// 读取助力参数
  1969. /// </summary>
  1970. /// <param name="sender"></param>
  1971. /// <param name="e"></param>
  1972. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  1973. {
  1974. var ConfigParam = new byte[4];
  1975. int AssistNum = 0;
  1976. try
  1977. {
  1978. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  1979. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  1980. ConfigParam[1] = (byte)(AssistNum >> 8);
  1981. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  1982. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  1983. ConfigParam[3] = (byte)(AssistNum >> 8);
  1984. richTextBox_AssistParam.Clear();
  1985. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  1986. }
  1987. catch (Exception)
  1988. {
  1989. timer_1s.Enabled = false;
  1990. MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  1991. timer_1s.Enabled = true;
  1992. }
  1993. }
  1994. /// <summary>
  1995. /// 写入助力参数
  1996. /// </summary>
  1997. /// <param name="sender"></param>
  1998. /// <param name="e"></param>
  1999. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  2000. {
  2001. var ConfigParam = new byte[80];
  2002. for (int i = 0; i < 80; i++)
  2003. ConfigParam[i] = 0;
  2004. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2005. long lDataTemp = 0;
  2006. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2007. int index_1 = 0, index_2 = 0;
  2008. try
  2009. {
  2010. for (int i = 0; i < strDataTemp.Length; i++)
  2011. {
  2012. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2013. {
  2014. index_1 = i;
  2015. break;
  2016. }
  2017. }
  2018. for (int i = 0; i < strDataTemp.Length; i++)
  2019. {
  2020. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2021. {
  2022. index_2 = i;
  2023. break;
  2024. }
  2025. }
  2026. for (int i = 0; i < strDataTemp.Length; i++)
  2027. {
  2028. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  2029. if (i < index_1)
  2030. {
  2031. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  2032. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  2033. }
  2034. else if (i <= index_2)
  2035. {
  2036. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  2037. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  2038. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  2039. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  2040. }
  2041. else
  2042. {
  2043. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  2044. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  2045. }
  2046. }
  2047. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2048. }
  2049. catch (Exception)
  2050. {
  2051. timer_1s.Enabled = false;
  2052. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2053. timer_1s.Enabled = true;
  2054. }
  2055. }
  2056. /// <summary>
  2057. /// 读取调试参数
  2058. /// </summary>
  2059. /// <param name="sender"></param>
  2060. /// <param name="e"></param>
  2061. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  2062. {
  2063. richTextBox_DebugParam.Clear();
  2064. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  2065. }
  2066. /// <summary>
  2067. /// 写入调试参数
  2068. /// </summary>
  2069. /// <param name="sender"></param>
  2070. /// <param name="e"></param>
  2071. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  2072. {
  2073. var ConfigParam = new byte[60];
  2074. for (int i = 0; i < 60; i++)
  2075. ConfigParam[i] = 0;
  2076. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2077. ushort uwDataTemp = 0;
  2078. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2079. try
  2080. {
  2081. for (int i = 0; i < strDataTemp.Length; i++)
  2082. {
  2083. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2084. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2085. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2086. }
  2087. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  2088. }
  2089. catch (Exception)
  2090. {
  2091. timer_1s.Enabled = false;
  2092. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2093. timer_1s.Enabled = true;
  2094. }
  2095. }
  2096. /// <summary>
  2097. /// 读取历史
  2098. /// </summary>
  2099. /// <param name="sender"></param>
  2100. /// <param name="e"></param>
  2101. private void button_ReadRecord_Click(object sender, EventArgs e)
  2102. {
  2103. richTextBox_Record.Clear();
  2104. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2105. }
  2106. /// <summary>
  2107. /// 读取传感器参数
  2108. /// </summary>
  2109. /// <param name="sender"></param>
  2110. /// <param name="e"></param>
  2111. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  2112. {
  2113. richTextBox_SensorParam.Clear();
  2114. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2115. }
  2116. /// <summary>
  2117. /// 写入力矩传感器标定值
  2118. /// </summary>
  2119. /// <param name="sender"></param>
  2120. /// <param name="e"></param>
  2121. private void button_Write_Cal_Click(object sender, EventArgs e)
  2122. {
  2123. var ConfigParam = new byte[4];
  2124. for (int i = 0; i < 4; i++)
  2125. ConfigParam[i] = 0;
  2126. ushort uwDataTemp = 0;
  2127. try
  2128. {
  2129. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  2130. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2131. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2132. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  2133. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2134. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2135. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2136. }
  2137. catch (Exception)
  2138. {
  2139. timer_1s.Enabled = false;
  2140. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2141. timer_1s.Enabled = true;
  2142. }
  2143. }
  2144. /// <summary>
  2145. /// 写入传感器参数
  2146. /// </summary>
  2147. /// <param name="sender"></param>
  2148. /// <param name="e"></param>
  2149. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  2150. {
  2151. var ConfigParam = new byte[14];
  2152. for (int i = 0; i < 14; i++)
  2153. ConfigParam[i] = 0;
  2154. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2155. ushort uwDataTemp = 0;
  2156. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2157. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2158. int index = 0;
  2159. try
  2160. {
  2161. for (int i = 0; i < strDataTemp.Length; i++)
  2162. {
  2163. if (strDataTemp[i].Split('=')[0] == "踏频传感器一圈脉冲数")
  2164. {
  2165. index = i;
  2166. break;
  2167. }
  2168. }
  2169. for (int i = 0; i < (strDataTemp.Length - index); i++)
  2170. {
  2171. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  2172. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2173. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2174. }
  2175. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  2176. }
  2177. catch (Exception)
  2178. {
  2179. timer_1s.Enabled = false;
  2180. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2181. timer_1s.Enabled = true;
  2182. }
  2183. }
  2184. /// <summary>
  2185. /// 写入型号
  2186. /// </summary>
  2187. /// <param name="sender"></param>
  2188. /// <param name="e"></param>
  2189. private void button_WriteModel_Click(object sender, EventArgs e)
  2190. {
  2191. string Mode = textBox_Model.Text;
  2192. var ModeArray = new byte[16];
  2193. for (ushort i = 0; i < Mode.Length; i++)
  2194. {
  2195. ModeArray[i] = (byte)Mode[i];
  2196. }
  2197. if (Mode.Length < 16)
  2198. {
  2199. ModeArray[Mode.Length] = (byte)'.';
  2200. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2201. {
  2202. ModeArray[Mode.Length + 1 + i] = 0x20;
  2203. }
  2204. }
  2205. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2206. }
  2207. /// <summary>
  2208. /// 写入SN
  2209. /// </summary>
  2210. /// <param name="sender"></param>
  2211. /// <param name="e"></param>
  2212. private void button_WriteSN_Click(object sender, EventArgs e)
  2213. {
  2214. string SN = textBox_SN.Text;
  2215. var SNArray = new byte[16];
  2216. for (ushort i = 0; i < SN.Length; i++)
  2217. {
  2218. SNArray[i] = (byte)SN[i];
  2219. }
  2220. if (SN.Length < 16)
  2221. {
  2222. SNArray[SN.Length] = (byte)'.';
  2223. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2224. {
  2225. SNArray[SN.Length + 1 + i] = 0x20;
  2226. }
  2227. }
  2228. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2229. }
  2230. /// <summary>
  2231. /// 查询版本信息
  2232. /// </summary>
  2233. /// <param name="sender"></param>
  2234. /// <param name="e"></param>
  2235. private void button_ReadVersion_Click(object sender, EventArgs e)
  2236. {
  2237. textBox_Model.Text = "---";
  2238. textBox_SN.Text = "---";
  2239. textBox_HW.Text = "---";
  2240. textBox_FW.Text = "---";
  2241. textBox_SP.Text = "---";
  2242. textBox_OBC_ReadModel.Text = "---";
  2243. textBox_OBC_ReadSN.Text = "---";
  2244. textBox_OBC_ReadHW.Text = "---";
  2245. textBox_OBC_ReadFW.Text = "---";
  2246. textBox_OBC_ReadSP.Text = "---";
  2247. textBox_FacModeName.Text = "---";
  2248. textBox_FacModeNum.Text = "---";
  2249. textBox_FacModeHW.Text = "---";
  2250. textBox_FacModeFW.Text = "---";
  2251. textBox_FacModeSP.Text = "---";
  2252. Class_Motor_Ver.Mode = "---";
  2253. Class_Motor_Ver.SN = "---";
  2254. Class_Motor_Ver.HW = "---";
  2255. Class_Motor_Ver.FW = "---";
  2256. Class_Motor_Ver.Special = "---";
  2257. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2258. }
  2259. /// <summary>
  2260. /// 查询自定义1
  2261. /// </summary>
  2262. /// <param name="sender"></param>
  2263. /// <param name="e"></param>
  2264. private void button_ReadUser1_Click(object sender, EventArgs e)
  2265. {
  2266. textBox_User1.Text = "---";
  2267. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  2268. }
  2269. /// <summary>
  2270. /// 查询自定义2
  2271. /// </summary>
  2272. /// <param name="sender"></param>
  2273. /// <param name="e"></param>
  2274. private void button_ReadUser2_Click(object sender, EventArgs e)
  2275. {
  2276. textBox_User2.Text = "---";
  2277. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  2278. }
  2279. /// <summary>
  2280. /// 查询自定义3
  2281. /// </summary>
  2282. /// <param name="sender"></param>
  2283. /// <param name="e"></param>
  2284. private void button_ReadUser3_Click(object sender, EventArgs e)
  2285. {
  2286. textBox_User3.Text = "---";
  2287. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  2288. }
  2289. /// <summary>
  2290. /// 写入自定义字符串1
  2291. /// </summary>
  2292. /// <param name="sender"></param>
  2293. /// <param name="e"></param>
  2294. private void button_WriteUser1_Click(object sender, EventArgs e)
  2295. {
  2296. string User = textBox_User1.Text;
  2297. var UserArray = new byte[16];
  2298. for (ushort i = 0; i < User.Length; i++)
  2299. {
  2300. UserArray[i] = (byte)User[i];
  2301. }
  2302. if (User.Length < 16)
  2303. {
  2304. UserArray[User.Length] = (byte)'.';
  2305. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2306. {
  2307. UserArray[User.Length + 1 + i] = 0x20;
  2308. }
  2309. }
  2310. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  2311. }
  2312. /// <summary>
  2313. /// 写入自定义字符串2
  2314. /// </summary>
  2315. /// <param name="sender"></param>
  2316. /// <param name="e"></param>
  2317. private void button_WriteUser2_Click(object sender, EventArgs e)
  2318. {
  2319. string User = textBox_User2.Text;
  2320. var UserArray = new byte[16];
  2321. for (ushort i = 0; i < User.Length; i++)
  2322. {
  2323. UserArray[i] = (byte)User[i];
  2324. }
  2325. if (User.Length < 16)
  2326. {
  2327. UserArray[User.Length] = (byte)'.';
  2328. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2329. {
  2330. UserArray[User.Length + 1 + i] = 0x20;
  2331. }
  2332. }
  2333. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  2334. }
  2335. /// <summary>
  2336. /// 写入自定义字符串3
  2337. /// </summary>
  2338. /// <param name="sender"></param>
  2339. /// <param name="e"></param>
  2340. private void button_WriteUser3_Click(object sender, EventArgs e)
  2341. {
  2342. string User = textBox_User3.Text;
  2343. var UserArray = new byte[16];
  2344. for (ushort i = 0; i < User.Length; i++)
  2345. {
  2346. UserArray[i] = (byte)User[i];
  2347. }
  2348. if (User.Length < 16)
  2349. {
  2350. UserArray[User.Length] = (byte)'.';
  2351. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  2352. {
  2353. UserArray[User.Length + 1 + i] = 0x20;
  2354. }
  2355. }
  2356. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  2357. }
  2358. /// <summary>
  2359. /// 查询生产信息
  2360. /// </summary>
  2361. /// <param name="sender"></param>
  2362. /// <param name="e"></param>
  2363. private void button_ReadMAC_Click(object sender, EventArgs e)
  2364. {
  2365. textBox_MAC.Text = "---";
  2366. textBox_MACAdd.Text = "---";
  2367. textBox_MACDate.Text = "---";
  2368. textBox_PP.Text = "---";
  2369. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  2370. }
  2371. /// <summary>
  2372. /// 写入生产信息
  2373. /// </summary>
  2374. /// <param name="sender"></param>
  2375. /// <param name="e"></param>
  2376. private void button_WriteMac_Click(object sender, EventArgs e)
  2377. {
  2378. var MACArray = new byte[32];
  2379. //填入生产商
  2380. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  2381. {
  2382. MACArray[i] = (byte)textBox_MAC.Text[i];
  2383. }
  2384. if (textBox_MAC.Text.Length < 8)
  2385. {
  2386. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  2387. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  2388. {
  2389. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  2390. }
  2391. }
  2392. //填入生产地
  2393. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  2394. {
  2395. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  2396. }
  2397. if (textBox_MACAdd.Text.Length < 8)
  2398. {
  2399. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  2400. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  2401. {
  2402. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  2403. }
  2404. }
  2405. //填入生产日期
  2406. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  2407. {
  2408. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  2409. }
  2410. if (textBox_MACDate.Text.Length < 8)
  2411. {
  2412. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  2413. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  2414. {
  2415. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  2416. }
  2417. }
  2418. //填入品牌
  2419. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  2420. {
  2421. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  2422. }
  2423. if (textBox_PP.Text.Length < 8)
  2424. {
  2425. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  2426. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  2427. {
  2428. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  2429. }
  2430. }
  2431. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  2432. }
  2433. /// <summary>
  2434. /// 查询密钥
  2435. /// </summary>
  2436. /// <param name="sender"></param>
  2437. /// <param name="e"></param>
  2438. private void button_ReadKey_Click(object sender, EventArgs e)
  2439. {
  2440. textBox_Key.Text = "---";
  2441. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  2442. }
  2443. /// <summary>
  2444. /// 写入校验密钥
  2445. /// </summary>
  2446. /// <param name="sender"></param>
  2447. /// <param name="e"></param>
  2448. private void button_WriteKey_Click(object sender, EventArgs e)
  2449. {
  2450. string Key = textBox_Key.Text;
  2451. var KeyArray = new byte[8];
  2452. if (Key.Length != 8)
  2453. {
  2454. timer_1s.Enabled = false;
  2455. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2456. timer_1s.Enabled = true;
  2457. return;
  2458. }
  2459. for (ushort i = 0; i < Key.Length; i++)
  2460. {
  2461. KeyArray[i] = (byte)Key[i];
  2462. }
  2463. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  2464. }
  2465. /// <summary>
  2466. /// 查询在线检测结果
  2467. /// </summary>
  2468. /// <param name="sender"></param>
  2469. /// <param name="e"></param>
  2470. private void button_ReadOnLine_Click(object sender, EventArgs e)
  2471. {
  2472. textBox_Online.Text = "---";
  2473. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  2474. }
  2475. /// <summary>
  2476. /// 系统清除
  2477. /// </summary>
  2478. /// <param name="sender"></param>
  2479. /// <param name="e"></param>
  2480. private void button_SystemClear_Click(object sender, EventArgs e)
  2481. {
  2482. var Code = new byte[5];
  2483. Code[0] = (byte)'C';
  2484. Code[1] = (byte)'L';
  2485. Code[2] = (byte)'E';
  2486. Code[3] = (byte)'A';
  2487. Code[4] = (byte)'R';
  2488. timer_1s.Enabled = false;
  2489. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2490. {
  2491. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2492. {
  2493. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2494. {
  2495. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  2496. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2497. }
  2498. }
  2499. }
  2500. timer_1s.Enabled = true;
  2501. }
  2502. /// <summary>
  2503. /// 参数还原
  2504. /// </summary>
  2505. /// <param name="sender"></param>
  2506. /// <param name="e"></param>
  2507. private void button_Recovery_Click(object sender, EventArgs e)
  2508. {
  2509. var Code = new byte[8];
  2510. Code[0] = (byte)'R';
  2511. Code[1] = (byte)'E';
  2512. Code[2] = (byte)'C';
  2513. Code[3] = (byte)'O';
  2514. Code[4] = (byte)'V';
  2515. Code[5] = (byte)'E';
  2516. Code[6] = (byte)'R';
  2517. Code[7] = (byte)'Y';
  2518. timer_1s.Enabled = false;
  2519. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2520. {
  2521. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2522. {
  2523. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2524. {
  2525. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  2526. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2527. }
  2528. }
  2529. }
  2530. timer_1s.Enabled = true;
  2531. }
  2532. /// <summary>
  2533. /// 系统复位
  2534. /// </summary>
  2535. /// <param name="sender"></param>
  2536. /// <param name="e"></param>
  2537. private void button_Reset_Click(object sender, EventArgs e)
  2538. {
  2539. var Code_Off = new byte[5];
  2540. var Code_Reset = new byte[5];
  2541. Code_Off[0] = (byte)'O';
  2542. Code_Off[1] = (byte)'F';
  2543. Code_Off[2] = (byte)'F';
  2544. Code_Off[3] = (byte)'.';
  2545. Code_Off[4] = (byte)'.';
  2546. Code_Reset[0] = (byte)'R';
  2547. Code_Reset[1] = (byte)'E';
  2548. Code_Reset[2] = (byte)'S';
  2549. Code_Reset[3] = (byte)'E';
  2550. Code_Reset[4] = (byte)'T';
  2551. timer_1s.Enabled = false;
  2552. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2553. {
  2554. timer_1s.Enabled = true;
  2555. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  2556. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  2557. PowerOffAckStatus = false;
  2558. Delay_ms(250);
  2559. int TryCnt = 3;
  2560. while ((TryCnt--) >= 0)
  2561. {
  2562. if (!PowerOffAckStatus)
  2563. {
  2564. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  2565. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  2566. PowerOffAckStatus = false;
  2567. Delay_ms(250);
  2568. }
  2569. else break;
  2570. }
  2571. if (PowerOffAckStatus)
  2572. {
  2573. timer_1s.Enabled = false;
  2574. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  2575. timer_1s.Enabled = true;
  2576. }
  2577. else
  2578. {
  2579. timer_1s.Enabled = false;
  2580. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2581. timer_1s.Enabled = true;
  2582. }
  2583. }
  2584. timer_1s.Enabled = true;
  2585. }
  2586. /// <summary>
  2587. /// 记录清除
  2588. /// </summary>
  2589. /// <param name="sender"></param>
  2590. /// <param name="e"></param>
  2591. private void button_ClearLog_Click(object sender, EventArgs e)
  2592. {
  2593. var Code = new byte[9];
  2594. Code[0] = (byte)'L';
  2595. Code[1] = (byte)'O';
  2596. Code[2] = (byte)'G';
  2597. Code[3] = (byte)' ';
  2598. Code[4] = (byte)'C';
  2599. Code[5] = (byte)'L';
  2600. Code[6] = (byte)'E';
  2601. Code[7] = (byte)'A';
  2602. Code[8] = (byte)'R';
  2603. timer_1s.Enabled = false;
  2604. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2605. {
  2606. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2607. {
  2608. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2609. {
  2610. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  2611. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2612. }
  2613. }
  2614. }
  2615. timer_1s.Enabled = true;
  2616. }
  2617. /// <summary>
  2618. /// 打开系统计算器
  2619. /// </summary>
  2620. /// <param name="sender"></param>
  2621. /// <param name="e"></param>
  2622. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  2623. {
  2624. System.Diagnostics.Process.Start("calc.exe");
  2625. }
  2626. /// <summary>
  2627. ///故障转换和显示
  2628. /// </summary>
  2629. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  2630. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  2631. "",""};
  2632. private string ErrorInfoDisplay(UInt32 Code)
  2633. {
  2634. string Result = "";
  2635. if (Code == 0)
  2636. {
  2637. Result = "无故障";
  2638. }
  2639. else
  2640. {
  2641. for (int i = 0; i < 32; i++)
  2642. {
  2643. if ((Code & 0x01) == 0x01)
  2644. {
  2645. Result += ErrorInfo[i] + " ";
  2646. }
  2647. Code >>= 1;
  2648. }
  2649. }
  2650. return Result;
  2651. }
  2652. /// <summary>
  2653. /// 鼠标滑过故障码显示具体内容
  2654. /// </summary>
  2655. /// <param name="sender"></param>
  2656. /// <param name="e"></param>
  2657. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  2658. {
  2659. // 创建the ToolTip
  2660. ToolTip toolTip1 = new ToolTip();
  2661. // 设置显示样式
  2662. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  2663. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  2664. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  2665. toolTip1.ShowAlways = true;//是否显示提示框
  2666. // 设置伴随的对象.
  2667. string ErrorCode = this.textBox_ErrorCode.Text;
  2668. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  2669. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  2670. }
  2671. /// <summary>
  2672. /// 数据记录
  2673. /// </summary>
  2674. private void RunInfoAutoSave()
  2675. {
  2676. if (运行信息记录ToolStripMenuItem.Checked == true)
  2677. {
  2678. if (RunInfoSaveFilename == string.Empty)
  2679. {
  2680. return;
  2681. }
  2682. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").Replace(" ", "_") + " --> ";
  2683. foreach (Control c in tabPage_RunInfo.Controls)
  2684. {
  2685. if (c is TextBox)
  2686. {
  2687. SaveData += c.Text + " , ";
  2688. }
  2689. }
  2690. foreach (Control c in tabPage_DebugInfo.Controls)
  2691. {
  2692. if (c is TextBox)
  2693. {
  2694. SaveData += c.Text + " , ";
  2695. }
  2696. }
  2697. SaveData += "\r\n";
  2698. System.IO.File.AppendAllText(RunInfoSaveFilename, SaveData);//sb.ToString());
  2699. }
  2700. }
  2701. /// <summary>
  2702. /// 打开或关闭数据记录
  2703. /// </summary>
  2704. /// <param name="sender"></param>
  2705. /// <param name="e"></param>
  2706. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  2707. {
  2708. if (运行信息记录ToolStripMenuItem.Checked == false)
  2709. {
  2710. if (mySerialProcess.mySerial.IsOpen == true)
  2711. {
  2712. RunInfoSaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  2713. System.IO.File.AppendAllText(RunInfoSaveFilename, "时间 --> 车速 , 转速 , 踏频 , 力矩Reg , 力矩 , 踩踏方向 , 电压 , 电流 , 功率 , 电量 , " +
  2714. "PCB温度 , 绕组温度 , MOS温度 , 挡位 , 灯开关 , 续航 , 平均功耗 , 单次里程 , 单次时间 , 故障码 , " +
  2715. "系统状态机 , 二层状态机 , 电机状态机 , 助力状态机 , D轴电流给定 , Q轴电流给定 , D轴电压给定 , Q轴电压给定 , 瞬时力矩 , 时间滤波力矩 , 踏频滤波力矩 , D轴电流反馈 , Q轴电流反馈 , 助力函数输出" + "\r\n");
  2716. timer_1s.Enabled = false;
  2717. MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2718. timer_1s.Enabled = true;
  2719. 运行信息记录ToolStripMenuItem.Checked = true;
  2720. }
  2721. else
  2722. {
  2723. timer_1s.Enabled = false;
  2724. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2725. timer_1s.Enabled = true;
  2726. }
  2727. }
  2728. else
  2729. {
  2730. 运行信息记录ToolStripMenuItem.Checked = false;
  2731. timer_1s.Enabled = false;
  2732. MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2733. timer_1s.Enabled = true;
  2734. }
  2735. }
  2736. /// <summary>
  2737. /// 仪表启动控制档位开关事件
  2738. /// </summary>
  2739. /// <param name="sender"></param>
  2740. /// <param name="e"></param>
  2741. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  2742. {
  2743. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2744. {
  2745. //检查串口是否打开
  2746. if (!mySerialProcess.mySerial.IsOpen)
  2747. {
  2748. timer_1s.Enabled = false;
  2749. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2750. timer_1s.Enabled = true;
  2751. checkBox_OBC_StartSetGearSt.Checked = false;
  2752. return;
  2753. }
  2754. //检查是否选择档位和打开车灯
  2755. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  2756. {
  2757. timer_1s.Enabled = false;
  2758. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2759. timer_1s.Enabled = true;
  2760. checkBox_OBC_StartSetGearSt.Checked = false;
  2761. return;
  2762. }
  2763. }
  2764. }
  2765. /// <summary>
  2766. /// OBC查询电机用户参数
  2767. /// </summary>
  2768. /// <param name="sender"></param>
  2769. /// <param name="e"></param>
  2770. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  2771. {
  2772. richTextBox_OBC_ReadUserInfo.Clear();
  2773. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  2774. }
  2775. /// <summary>
  2776. /// OBC设置电机用户参数
  2777. /// </summary>
  2778. /// <param name="sender"></param>
  2779. /// <param name="e"></param>
  2780. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  2781. {
  2782. var UserInfoCode = new byte[8];
  2783. for (int i = 0; i < UserInfoCode.Length; i++)
  2784. UserInfoCode[i] = 0;
  2785. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  2786. {
  2787. timer_1s.Enabled = false;
  2788. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2789. timer_1s.Enabled = true;
  2790. return;
  2791. }
  2792. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  2793. {
  2794. timer_1s.Enabled = false;
  2795. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2796. timer_1s.Enabled = true;
  2797. return;
  2798. }
  2799. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  2800. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  2801. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  2802. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  2803. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  2804. }
  2805. /// <summary>
  2806. /// OBC查询电机版本信息
  2807. /// </summary>
  2808. /// <param name="sender"></param>
  2809. /// <param name="e"></param>
  2810. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  2811. {
  2812. textBox_Model.Text = "---";
  2813. textBox_SN.Text = "---";
  2814. textBox_HW.Text = "---";
  2815. textBox_FW.Text = "---";
  2816. textBox_SP.Text = "---";
  2817. textBox_OBC_ReadModel.Text = "---";
  2818. textBox_OBC_ReadSN.Text = "---";
  2819. textBox_OBC_ReadHW.Text = "---";
  2820. textBox_OBC_ReadFW.Text = "---";
  2821. textBox_OBC_ReadSP.Text = "---";
  2822. textBox_FacModeName.Text = "---";
  2823. textBox_FacModeNum.Text = "---";
  2824. textBox_FacModeHW.Text = "---";
  2825. textBox_FacModeFW.Text = "---";
  2826. textBox_FacModeSP.Text = "---";
  2827. Class_Motor_Ver.Mode = "---";
  2828. Class_Motor_Ver.SN = "---";
  2829. Class_Motor_Ver.HW = "---";
  2830. Class_Motor_Ver.FW = "---";
  2831. Class_Motor_Ver.Special = "---";
  2832. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  2833. }
  2834. /// <summary>
  2835. /// OBC读取骑行历史
  2836. /// </summary>
  2837. /// <param name="sender"></param>
  2838. /// <param name="e"></param>
  2839. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  2840. {
  2841. textBox_OBC_TRIP_KM.Text = "";
  2842. textBox_OBC_TRIP_TIME.Text = "";
  2843. textBox_OBC_ODO_KM.Text = "";
  2844. textBox_OBC_ODO_TIME.Text = "";
  2845. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  2846. }
  2847. /// <summary>
  2848. /// OBC清除TRIP里程
  2849. /// </summary>
  2850. /// <param name="sender"></param>
  2851. /// <param name="e"></param>
  2852. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  2853. {
  2854. var Code = new byte[5];
  2855. Code[0] = (byte)'C';
  2856. Code[1] = (byte)'L';
  2857. Code[2] = (byte)'E';
  2858. Code[3] = (byte)'A';
  2859. Code[4] = (byte)'R';
  2860. timer_1s.Enabled = false;
  2861. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2862. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  2863. timer_1s.Enabled = true;
  2864. }
  2865. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  2866. {
  2867. if (checkBox_OBC_StartReadBMS.Checked == true)
  2868. {
  2869. //检查串口是否打开
  2870. if (!mySerialProcess.mySerial.IsOpen)
  2871. {
  2872. timer_1s.Enabled = false;
  2873. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2874. timer_1s.Enabled = true;
  2875. checkBox_OBC_StartReadBMS.Checked = false;
  2876. return;
  2877. }
  2878. }
  2879. }
  2880. /// <summary>
  2881. /// 写入力矩传感器参数
  2882. /// </summary>
  2883. /// <param name="sender"></param>
  2884. /// <param name="e"></param>
  2885. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  2886. {
  2887. var ConfigParam = new byte[46];
  2888. for (int i = 0; i < 14; i++)
  2889. ConfigParam[i] = 0;
  2890. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2891. ushort uwDataTemp = 0;
  2892. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2893. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2894. int index = 0;
  2895. try
  2896. {
  2897. for (int i = 0; i < strDataTemp.Length; i++)
  2898. {
  2899. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  2900. {
  2901. index = i;
  2902. break;
  2903. }
  2904. }
  2905. for (int i = 0; i < (index + 1); i++)
  2906. {
  2907. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2908. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2909. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2910. }
  2911. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  2912. }
  2913. catch (Exception)
  2914. {
  2915. timer_1s.Enabled = false;
  2916. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2917. timer_1s.Enabled = true;
  2918. }
  2919. }
  2920. /// <summary>
  2921. /// 查询存储标志
  2922. /// </summary>
  2923. /// <param name="sender"></param>
  2924. /// <param name="e"></param>
  2925. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  2926. {
  2927. radioButton_EE_SaveYes.Checked = false;
  2928. radioButton_EE_SaveNo.Checked = false;
  2929. radioButton_SIP_SaveYes.Checked = false;
  2930. radioButton_SIP_SaveNo.Checked = false;
  2931. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  2932. }
  2933. /// <summary>
  2934. /// 写入存储标志
  2935. /// </summary>
  2936. /// <param name="sender"></param>
  2937. /// <param name="e"></param>
  2938. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  2939. {
  2940. var SaveFlag = new byte[6];
  2941. for (int i = 0; i < 6; i++)
  2942. SaveFlag[i] = 0;
  2943. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  2944. {
  2945. timer_1s.Enabled = false;
  2946. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2947. timer_1s.Enabled = true;
  2948. return;
  2949. }
  2950. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  2951. {
  2952. timer_1s.Enabled = false;
  2953. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2954. timer_1s.Enabled = true;
  2955. return;
  2956. }
  2957. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  2958. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  2959. SaveFlag[3] = 0;
  2960. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  2961. SaveFlag[5] = 0;
  2962. timer_1s.Enabled = false;
  2963. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2964. {
  2965. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  2966. }
  2967. timer_1s.Enabled = true;
  2968. }
  2969. /// <summary>
  2970. /// 读取指定地址数据
  2971. /// </summary>
  2972. /// <param name="sender"></param>
  2973. /// <param name="e"></param>
  2974. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  2975. {
  2976. var Address = new byte[4];
  2977. UInt32 Address_Begin;
  2978. UInt32 Addres_End;
  2979. if(checkBox_ReadRanFlash_AutoClear.Checked == true)
  2980. richTextBox_RamFlasgData.Clear();
  2981. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2982. {
  2983. timer_1s.Enabled = false;
  2984. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2985. timer_1s.Enabled = true;
  2986. return;
  2987. }
  2988. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2989. {
  2990. timer_1s.Enabled = false;
  2991. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2992. timer_1s.Enabled = true;
  2993. return;
  2994. }
  2995. else
  2996. {
  2997. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2998. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2999. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  3000. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3001. if (Addres_End < Address_Begin)
  3002. {
  3003. timer_1s.Enabled = false;
  3004. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3005. timer_1s.Enabled = true;
  3006. return;
  3007. }
  3008. else
  3009. {
  3010. var SendByte = new byte[8];
  3011. SendByte[0] = (byte)(Address_Begin >> 24);
  3012. SendByte[1] = (byte)(Address_Begin >> 16);
  3013. SendByte[2] = (byte)(Address_Begin >> 8);
  3014. SendByte[3] = (byte)(Address_Begin);
  3015. SendByte[4] = (byte)(Addres_End >> 24);
  3016. SendByte[5] = (byte)(Addres_End >> 16);
  3017. SendByte[6] = (byte)(Addres_End >> 8);
  3018. SendByte[7] = (byte)(Addres_End);
  3019. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3020. }
  3021. }
  3022. }
  3023. /// <summary>
  3024. /// 工作模式选择
  3025. /// </summary>
  3026. /// <param name="sender"></param>
  3027. /// <param name="e"></param>
  3028. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  3029. {
  3030. var RunMode = new byte[1];
  3031. if (comboBox_WorkMode.Text == "配置模式")
  3032. RunMode[0] = 0x01;
  3033. else if (comboBox_WorkMode.Text == "调试模式")
  3034. RunMode[0] = 0x02;
  3035. else
  3036. RunMode[0] = 0x00;
  3037. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3038. }
  3039. /// <summary>
  3040. /// 助力档位选择
  3041. /// </summary>
  3042. /// <param name="sender"></param>
  3043. /// <param name="e"></param>
  3044. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  3045. {
  3046. var CtrlCode = new byte[2];
  3047. if (comboBox_GearSt.SelectedIndex == 5)//档位
  3048. CtrlCode[0] = 0x33;
  3049. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  3050. CtrlCode[0] = 0x22;
  3051. else
  3052. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  3053. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  3054. CtrlCode[1] = 0xF1;
  3055. else
  3056. CtrlCode[1] = 0xF0;
  3057. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  3058. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  3059. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  3060. }
  3061. /// <summary>
  3062. /// 仪表档位选择
  3063. /// </summary>
  3064. /// <param name="sender"></param>
  3065. /// <param name="e"></param>
  3066. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  3067. {
  3068. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  3069. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  3070. }
  3071. /// <summary>
  3072. /// 生产模式初始化
  3073. /// </summary>
  3074. /// <param name="sender"></param>
  3075. /// <param name="e"></param>
  3076. private void button_FacModeInit_Click(object sender, EventArgs e)
  3077. {
  3078. var Code = new byte[5];
  3079. Code[0] = (byte)'C';
  3080. Code[1] = (byte)'L';
  3081. Code[2] = (byte)'E';
  3082. Code[3] = (byte)'A';
  3083. Code[4] = (byte)'R';
  3084. timer_1s.Enabled = false;
  3085. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3086. {
  3087. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3088. {
  3089. timer_1s.Enabled = true;
  3090. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3091. PowerOffAckStatus = false;
  3092. Delay_ms(250);
  3093. int TryCnt = 3;
  3094. while ((TryCnt--) >= 0)
  3095. {
  3096. if (!PowerOffAckStatus)
  3097. {
  3098. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  3099. PowerOffAckStatus = false;
  3100. Delay_ms(250);
  3101. }
  3102. else break;
  3103. }
  3104. if (PowerOffAckStatus)
  3105. {
  3106. timer_1s.Enabled = false;
  3107. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3108. timer_1s.Enabled = true;
  3109. }
  3110. else
  3111. {
  3112. timer_1s.Enabled = false;
  3113. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3114. timer_1s.Enabled = true;
  3115. }
  3116. timer_1s.Enabled = true;
  3117. }
  3118. }
  3119. timer_1s.Enabled = true;
  3120. //清除历史测试记录
  3121. textBox_FacModeSensorADC0.Text = "";
  3122. textBox_FacModeSensorADC1.Text = "";
  3123. textBox_FacModeSensorADC2.Text = "";
  3124. textBox_FacModeSensorADC3.Text = "";
  3125. textBox_FacModeSensorADC4.Text = "";
  3126. checkBox_FacModeCheckBikeSpeed.Checked = false;
  3127. checkBox_FacModeCheckCadence.Checked = false;
  3128. checkBox_FacModeCheckNTC.Checked = false;
  3129. checkBox_FacModeCheckVol.Checked = false;
  3130. LightSwitchStatus = false;
  3131. MotorRunStatus = false;
  3132. trackBar_FacModeMotorSpeedAdj.Value = 5;
  3133. textBox_FacModeWheelSize.Text = "";
  3134. textBox_FacModeSpeedLimit.Text = "";
  3135. comboBox_FacModeAssist1.SelectedIndex = -1;
  3136. comboBox_FacModeAssist2.SelectedIndex = -1;
  3137. comboBox_FacModeLightVol.SelectedIndex = -1;
  3138. comboBox_FacModeStartMode.SelectedIndex = -1;
  3139. textBox_FacModeStartGain.Text = "";
  3140. textBox_FacModeCircuitK.Text = "";
  3141. textBox_FacModeFltCounter.Text = "";
  3142. textBox_FacModeSpeedLimitTh.Text = "";
  3143. textBox_FacModeSpeedLimitEnd.Text = "";
  3144. textBox_FacModeCadencePer.Text = "";
  3145. textBox_FacModeName.Text = "";
  3146. textBox_FacModeNum.Text = "";
  3147. textBox_FacModeHW.Text = "";
  3148. textBox_FacModeFW.Text = "";
  3149. }
  3150. /// <summary>
  3151. /// 生产模式读取传感器参数
  3152. /// </summary>
  3153. /// <param name="sender"></param>
  3154. /// <param name="e"></param>
  3155. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  3156. {
  3157. richTextBox_SensorParam.Clear();
  3158. textBox_FacModeSensorADC0.Text = "";
  3159. textBox_FacModeSensorADC1.Text = "";
  3160. textBox_FacModeSensorADC2.Text = "";
  3161. textBox_FacModeSensorADC3.Text = "";
  3162. textBox_FacModeSensorADC4.Text = "";
  3163. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3164. }
  3165. /// <summary>
  3166. /// 生产模式传感器标定1
  3167. /// </summary>
  3168. /// <param name="sender"></param>
  3169. /// <param name="e"></param>
  3170. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  3171. {
  3172. var ConfigParam = new byte[4];
  3173. for (int i = 0; i < 4; i++)
  3174. ConfigParam[i] = 0;
  3175. ushort uwDataTemp = 0;
  3176. try
  3177. {
  3178. uwDataTemp = 1;//负载序号
  3179. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3180. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3181. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  3182. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3183. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3184. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3185. Delay_ms(200);
  3186. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3187. }
  3188. catch (Exception)
  3189. {
  3190. timer_1s.Enabled = false;
  3191. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3192. timer_1s.Enabled = true;
  3193. }
  3194. }
  3195. /// <summary>
  3196. /// 生产模式传感器标定2
  3197. /// </summary>
  3198. /// <param name="sender"></param>
  3199. /// <param name="e"></param>
  3200. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  3201. {
  3202. var ConfigParam = new byte[4];
  3203. for (int i = 0; i < 4; i++)
  3204. ConfigParam[i] = 0;
  3205. ushort uwDataTemp = 0;
  3206. try
  3207. {
  3208. uwDataTemp = 2;//负载序号
  3209. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3210. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3211. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  3212. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3213. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3214. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3215. Delay_ms(200);
  3216. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3217. }
  3218. catch (Exception)
  3219. {
  3220. timer_1s.Enabled = false;
  3221. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3222. timer_1s.Enabled = true;
  3223. }
  3224. }
  3225. /// <summary>
  3226. /// 生产模式传感器标定3
  3227. /// </summary>
  3228. /// <param name="sender"></param>
  3229. /// <param name="e"></param>
  3230. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  3231. {
  3232. var ConfigParam = new byte[4];
  3233. for (int i = 0; i < 4; i++)
  3234. ConfigParam[i] = 0;
  3235. ushort uwDataTemp = 0;
  3236. try
  3237. {
  3238. uwDataTemp = 3;//负载序号
  3239. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3240. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3241. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  3242. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3243. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3244. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3245. Delay_ms(200);
  3246. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3247. }
  3248. catch (Exception)
  3249. {
  3250. timer_1s.Enabled = false;
  3251. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3252. timer_1s.Enabled = true;
  3253. }
  3254. }
  3255. /// <summary>
  3256. /// 生产模式传感器标定3
  3257. /// </summary>
  3258. /// <param name="sender"></param>
  3259. /// <param name="e"></param>
  3260. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  3261. {
  3262. var ConfigParam = new byte[4];
  3263. for (int i = 0; i < 4; i++)
  3264. ConfigParam[i] = 0;
  3265. ushort uwDataTemp = 0;
  3266. try
  3267. {
  3268. uwDataTemp = 4;//负载序号
  3269. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  3270. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  3271. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  3272. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  3273. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3274. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  3275. Delay_ms(200);
  3276. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  3277. }
  3278. catch (Exception)
  3279. {
  3280. timer_1s.Enabled = false;
  3281. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3282. timer_1s.Enabled = true;
  3283. }
  3284. }
  3285. /// <summary>
  3286. /// 生产模式采集按钮
  3287. /// </summary>
  3288. /// <param name="sender"></param>
  3289. /// <param name="e"></param>
  3290. private void button_FacModeWorkMode_Click(object sender, EventArgs e)
  3291. {
  3292. var RunMode = new byte[1];
  3293. if (button_FacModeWorkMode.Text == "开始")
  3294. {
  3295. RunMode[0] = 0x01;
  3296. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
  3297. {
  3298. button_FacModeWorkMode.Text = "停止";
  3299. button_FacModeWorkMode.BackColor = Color.Yellow;
  3300. }
  3301. }
  3302. else if (button_FacModeWorkMode.Text == "停止")
  3303. {
  3304. RunMode[0] = 0x00;
  3305. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
  3306. {
  3307. button_FacModeWorkMode.Text = "开始";
  3308. button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  3309. }
  3310. }
  3311. }
  3312. /// <summary>
  3313. /// 生产模式开关灯
  3314. /// </summary>
  3315. /// <param name="sender"></param>
  3316. /// <param name="e"></param>
  3317. bool LightSwitchStatus = false;
  3318. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  3319. {
  3320. var CtrlCode = new byte[2];
  3321. CtrlCode[0] = 0x00;
  3322. if (LightSwitchStatus)
  3323. {
  3324. CtrlCode[1] = 0xF0;
  3325. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  3326. }
  3327. else
  3328. {
  3329. CtrlCode[1] = 0xF1;
  3330. button_FacModeLightSW.BackColor = Color.Yellow;
  3331. }
  3332. if(mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  3333. {
  3334. LightSwitchStatus = !LightSwitchStatus;
  3335. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3336. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  3337. }
  3338. }
  3339. /// <summary>
  3340. /// 生产模式电机控制
  3341. /// </summary>
  3342. /// <param name="sender"></param>
  3343. /// <param name="e"></param>
  3344. bool MotorRunStatus = false;
  3345. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  3346. {
  3347. string DebugDefaultInfo = "";
  3348. //获取调试信息
  3349. if (richTextBox_DebugParam.Text == string.Empty)
  3350. {
  3351. timer_1s.Enabled = false;
  3352. MessageBox.Show("请先读取调试信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3353. timer_1s.Enabled = true;
  3354. return;
  3355. }
  3356. else
  3357. {
  3358. DebugDefaultInfo = richTextBox_DebugParam.Text;
  3359. }
  3360. //获取参数
  3361. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  3362. if (strDataTemp.Length != 25)
  3363. {
  3364. timer_1s.Enabled = false;
  3365. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3366. timer_1s.Enabled = true;
  3367. return;
  3368. }
  3369. var ConfigParam = new byte[60];
  3370. for (int i = 0; i < 60; i++)
  3371. ConfigParam[i] = 0;
  3372. ConfigParam[0] = 0x00;
  3373. ushort uwDataTemp = 0;
  3374. if (!MotorRunStatus) //停止状态
  3375. {
  3376. //设置速度环
  3377. if (radioButton_FacModeDriverCity.Checked | radioButton_FacModeDriverMtb.Checked | radioButton_FacModeDriverLG.Checked == true)
  3378. {
  3379. strDataTemp[0] = "整体运行模式=3";
  3380. }
  3381. else
  3382. {
  3383. timer_1s.Enabled = false;
  3384. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3385. timer_1s.Enabled = true;
  3386. return;
  3387. }
  3388. //设置带载类型
  3389. if (label_Load.Text == "空载")
  3390. {
  3391. strDataTemp[10] = "转速环控制器带宽=3";
  3392. }
  3393. else if (label_Load.Text == "带载")
  3394. {
  3395. strDataTemp[10] = "转速环控制器带宽=5";
  3396. }
  3397. else
  3398. {
  3399. timer_1s.Enabled = false;
  3400. MessageBox.Show("请选择带载类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3401. timer_1s.Enabled = true;
  3402. return;
  3403. }
  3404. //选择位置模式
  3405. if (label_MotorSensor.Text == "有感")
  3406. {
  3407. if (radioButton_FacModeDriverCity.Checked | radioButton_FacModeDriverMtb.Checked == true)
  3408. strDataTemp[1] = "位置获取模式=1";
  3409. else if (radioButton_FacModeDriverLG.Checked == true)
  3410. strDataTemp[1] = "位置获取模式=2";
  3411. else
  3412. {
  3413. timer_1s.Enabled = false;
  3414. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3415. timer_1s.Enabled = true;
  3416. return;
  3417. }
  3418. }
  3419. else if (label_MotorSensor.Text == "无感")
  3420. {
  3421. strDataTemp[1] = "位置获取模式=0";
  3422. }
  3423. else
  3424. {
  3425. timer_1s.Enabled = false;
  3426. MessageBox.Show("请选择位置模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3427. timer_1s.Enabled = true;
  3428. return;
  3429. }
  3430. //发送数据
  3431. try
  3432. {
  3433. for (int i = 0; i < strDataTemp.Length; i++)
  3434. {
  3435. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3436. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3437. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3438. }
  3439. if(!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  3440. return;
  3441. }
  3442. catch (Exception)
  3443. {
  3444. timer_1s.Enabled = false;
  3445. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3446. timer_1s.Enabled = true;
  3447. }
  3448. //设置转速百分比100%
  3449. trackBar_FacModeMotorSpeedAdj.Value = 100;
  3450. MotorRunStatus = !MotorRunStatus;
  3451. button_FacModeMotorRun.BackColor = Color.Yellow;
  3452. //电机进入配置模式
  3453. var RunMode = new byte[1];
  3454. RunMode[0] = 0x01;
  3455. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3456. button_FacModeWorkMode.Text = "停止";
  3457. button_FacModeWorkMode.BackColor = Color.Yellow;
  3458. }
  3459. else //运转状态
  3460. {
  3461. //还原为原始值
  3462. if (radioButton_FacModeDriverCity.Checked == true)
  3463. {
  3464. strDataTemp[0] = "整体运行模式=4";
  3465. strDataTemp[1] = "位置获取模式=1";
  3466. strDataTemp[10] = "转速环控制器带宽=5";
  3467. }
  3468. else if (radioButton_FacModeDriverMtb.Checked == true)
  3469. {
  3470. strDataTemp[0] = "整体运行模式=5";
  3471. strDataTemp[1] = "位置获取模式=1";
  3472. strDataTemp[10] = "转速环控制器带宽=5";
  3473. }
  3474. else if (radioButton_FacModeDriverLG.Checked == true)
  3475. {
  3476. strDataTemp[0] = "整体运行模式=6";
  3477. strDataTemp[1] = "位置获取模式=2";
  3478. strDataTemp[10] = "转速环控制器带宽=5";
  3479. }
  3480. else
  3481. {
  3482. timer_1s.Enabled = false;
  3483. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3484. timer_1s.Enabled = true;
  3485. return;
  3486. }
  3487. try
  3488. {
  3489. for (int i = 0; i < strDataTemp.Length; i++)
  3490. {
  3491. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3492. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3493. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3494. }
  3495. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  3496. return;
  3497. }
  3498. catch (Exception)
  3499. {
  3500. timer_1s.Enabled = false;
  3501. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3502. timer_1s.Enabled = true;
  3503. }
  3504. //设置转速百分比2%
  3505. trackBar_FacModeMotorSpeedAdj.Value = 2;
  3506. MotorRunStatus = !MotorRunStatus;
  3507. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  3508. //电机退出配置模式
  3509. var RunMode = new byte[1];
  3510. RunMode[0] = 0x00;
  3511. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3512. button_FacModeWorkMode.Text = "开始";
  3513. button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  3514. }
  3515. }
  3516. /// <summary>
  3517. /// 生产模式转速调节
  3518. /// </summary>
  3519. /// <param name="sender"></param>
  3520. /// <param name="e"></param>
  3521. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  3522. {
  3523. //转速百分比更新
  3524. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  3525. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  3526. }
  3527. /// <summary>
  3528. /// 生产模式读取整车参数
  3529. /// </summary>
  3530. /// <param name="sender"></param>
  3531. /// <param name="e"></param>
  3532. private void button_FacModeBikeParaRead_Click(object sender, EventArgs e)
  3533. {
  3534. textBox_FacModeWheelSize.Text = "";
  3535. textBox_FacModeSpeedLimit.Text = "";
  3536. comboBox_FacModeAssist1.SelectedIndex = -1;
  3537. comboBox_FacModeAssist2.SelectedIndex = -1;
  3538. comboBox_FacModeLightVol.SelectedIndex = -1;
  3539. comboBox_FacModeStartMode.SelectedIndex = -1;
  3540. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  3541. }
  3542. /// <summary>
  3543. /// 生产模式写入整车参数
  3544. /// </summary>
  3545. /// <param name="sender"></param>
  3546. /// <param name="e"></param>
  3547. private void button_FacModeBikeParaSet_Click(object sender, EventArgs e)
  3548. {
  3549. string BikeDefaultInfo = "轮胎周长=219, 电控传动比=35, 助力最大限速=25, 推行模式限速=6, 前牙盘T数=38, 后牙盘T数=11, 助力方案1=341, 助力方案2=682, 前后灯电压=6, 轮胎周长微调=0, 启动模式=2, 自动关机时间=15";
  3550. var ConfigParam = new byte[28];
  3551. for (int i = 0; i < 28; i++)
  3552. ConfigParam[i] = 0;
  3553. ConfigParam[0] = (byte)(0x01);
  3554. ushort uwDataTemp = 0;
  3555. string[] strDataTemp = BikeDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  3556. try
  3557. {
  3558. for (int i = 0; i < strDataTemp.Length; i++)
  3559. {
  3560. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  3561. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  3562. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  3563. }
  3564. //周长
  3565. uwDataTemp = Convert.ToUInt16(textBox_FacModeWheelSize.Text);
  3566. ConfigParam[2] = (byte)uwDataTemp;
  3567. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  3568. //限速
  3569. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimit.Text);
  3570. ConfigParam[6] = (byte)uwDataTemp;
  3571. ConfigParam[7] = (byte)(uwDataTemp >> 8);
  3572. //助力方案1
  3573. if (comboBox_FacModeAssist1.SelectedIndex == 0) uwDataTemp = 0;
  3574. else if (comboBox_FacModeAssist1.SelectedIndex == 1) uwDataTemp = 341;
  3575. else if (comboBox_FacModeAssist1.SelectedIndex == 2) uwDataTemp = 682;
  3576. else
  3577. {
  3578. timer_1s.Enabled = false;
  3579. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3580. timer_1s.Enabled = true;
  3581. return;
  3582. }
  3583. ConfigParam[14] = (byte)uwDataTemp;
  3584. ConfigParam[15] = (byte)(uwDataTemp >> 8);
  3585. //助力方案2
  3586. if(comboBox_FacModeAssist2.SelectedIndex == 0) uwDataTemp = 0;
  3587. else if (comboBox_FacModeAssist2.SelectedIndex == 1) uwDataTemp = 341;
  3588. else if (comboBox_FacModeAssist2.SelectedIndex == 2) uwDataTemp = 682;
  3589. else
  3590. {
  3591. timer_1s.Enabled = false;
  3592. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3593. timer_1s.Enabled = true;
  3594. return;
  3595. }
  3596. ConfigParam[16] = (byte)uwDataTemp;
  3597. ConfigParam[17] = (byte)(uwDataTemp >> 8);
  3598. //灯压
  3599. if(comboBox_FacModeLightVol.SelectedIndex == 0) uwDataTemp = 6;
  3600. else if (comboBox_FacModeLightVol.SelectedIndex == 1) uwDataTemp = 12;
  3601. else
  3602. {
  3603. timer_1s.Enabled = false;
  3604. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3605. timer_1s.Enabled = true;
  3606. return;
  3607. }
  3608. ConfigParam[18] = (byte)uwDataTemp;
  3609. ConfigParam[19] = (byte)(uwDataTemp >> 8);
  3610. //启动模式
  3611. if (comboBox_FacModeStartMode.SelectedIndex == 0) uwDataTemp = 1;
  3612. else if (comboBox_FacModeStartMode.SelectedIndex == 2) uwDataTemp = 3;
  3613. else uwDataTemp = 2;
  3614. ConfigParam[22] = (byte)uwDataTemp;
  3615. ConfigParam[23] = (byte)(uwDataTemp >> 8);
  3616. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  3617. }
  3618. catch (Exception)
  3619. {
  3620. timer_1s.Enabled = false;
  3621. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3622. timer_1s.Enabled = true;
  3623. }
  3624. }
  3625. /// <summary>
  3626. /// 生产模式读取助力参数
  3627. /// </summary>
  3628. /// <param name="sender"></param>
  3629. /// <param name="e"></param>
  3630. private void button_FacModeAssistParaRead_Click(object sender, EventArgs e)
  3631. {
  3632. var ConfigParam = new byte[4];
  3633. textBox_FacModeStartGain.Text = "";
  3634. textBox_FacModeCircuitK.Text = "";
  3635. textBox_FacModeFltCounter.Text = "";
  3636. textBox_FacModeSpeedLimitTh.Text ="";
  3637. textBox_FacModeSpeedLimitEnd.Text = "";
  3638. textBox_FacModeCadencePer.Text = "";
  3639. ConfigParam[0] = (byte)(1 & 0xFF);
  3640. ConfigParam[1] = (byte)(1 >> 8);
  3641. ConfigParam[2] = (byte)(1 & 0xFF);
  3642. ConfigParam[3] = (byte)(1 >> 8);
  3643. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  3644. }
  3645. /// <summary>
  3646. /// 生产模式写入助力参数
  3647. /// </summary>
  3648. /// <param name="sender"></param>
  3649. /// <param name="e"></param>
  3650. private void button_FacModeAssistParaSet_Click(object sender, EventArgs e)
  3651. {
  3652. 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";
  3653. var ConfigParam = new byte[80];
  3654. for (int i = 0; i < 80; i++)
  3655. ConfigParam[i] = 0;
  3656. ConfigParam[0] = (byte)(0x01);
  3657. ushort uwDataTemp = 0;
  3658. ulong ulDataTemp = 0;
  3659. int index_1 = 0, index_2 = 0;
  3660. string[] strDataTemp = AssistDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  3661. try
  3662. {
  3663. //因数据类型不同,预处理
  3664. for (int i = 0; i < strDataTemp.Length; i++)
  3665. {
  3666. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  3667. {
  3668. index_1 = i;
  3669. break;
  3670. }
  3671. }
  3672. for (int i = 0; i < strDataTemp.Length; i++)
  3673. {
  3674. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  3675. {
  3676. index_2 = i;
  3677. break;
  3678. }
  3679. }
  3680. for (int i = 0; i < strDataTemp.Length; i++)
  3681. {
  3682. ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
  3683. if (i < index_1)
  3684. {
  3685. ConfigParam[2 * i + 4] = (byte)ulDataTemp;
  3686. ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
  3687. }
  3688. else if (i <= index_2)
  3689. {
  3690. ConfigParam[4 * i - 4] = (byte)ulDataTemp;
  3691. ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
  3692. ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
  3693. ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
  3694. }
  3695. else
  3696. {
  3697. ConfigParam[2 * i + 20] = (byte)ulDataTemp;
  3698. ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
  3699. }
  3700. }
  3701. //零速增益
  3702. uwDataTemp = Convert.ToUInt16(textBox_FacModeStartGain.Text);
  3703. ConfigParam[4] = (byte)uwDataTemp;
  3704. ConfigParam[5] = (byte)(uwDataTemp >> 8);
  3705. //电流阶梯
  3706. uwDataTemp = Convert.ToUInt16(textBox_FacModeCircuitK.Text);
  3707. ConfigParam[48] = (byte)uwDataTemp;
  3708. ConfigParam[49] = (byte)(uwDataTemp >> 8);
  3709. //滤波脉冲
  3710. uwDataTemp = Convert.ToUInt16(textBox_FacModeFltCounter.Text);
  3711. ConfigParam[52] = (byte)uwDataTemp;
  3712. ConfigParam[53] = (byte)(uwDataTemp >> 8);
  3713. //限速启动
  3714. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitTh.Text);
  3715. ConfigParam[58] = (byte)uwDataTemp;
  3716. ConfigParam[59] = (byte)(uwDataTemp >> 8);
  3717. //限速停止
  3718. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitEnd.Text);
  3719. ConfigParam[60] = (byte)uwDataTemp;
  3720. ConfigParam[61] = (byte)(uwDataTemp >> 8);
  3721. //踏频占比
  3722. uwDataTemp = Convert.ToUInt16(textBox_FacModeCadencePer.Text);
  3723. ConfigParam[62] = (byte)uwDataTemp;
  3724. ConfigParam[63] = (byte)(uwDataTemp >> 8);
  3725. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  3726. }
  3727. catch (Exception)
  3728. {
  3729. timer_1s.Enabled = false;
  3730. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3731. timer_1s.Enabled = true;
  3732. }
  3733. }
  3734. /// <summary>
  3735. /// 生产模式写入型号
  3736. /// </summary>
  3737. /// <param name="sender"></param>
  3738. /// <param name="e"></param>
  3739. private void button_FacModeSetName_Click(object sender, EventArgs e)
  3740. {
  3741. string Mode = textBox_FacModeName.Text;
  3742. var ModeArray = new byte[16];
  3743. for (ushort i = 0; i < Mode.Length; i++)
  3744. {
  3745. ModeArray[i] = (byte)Mode[i];
  3746. }
  3747. if (Mode.Length < 16)
  3748. {
  3749. ModeArray[Mode.Length] = (byte)'.';
  3750. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3751. {
  3752. ModeArray[Mode.Length + 1 + i] = 0x20;
  3753. }
  3754. }
  3755. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3756. }
  3757. /// <summary>
  3758. /// 生产模式写入SN
  3759. /// </summary>
  3760. /// <param name="sender"></param>
  3761. /// <param name="e"></param>
  3762. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  3763. {
  3764. string SN = textBox_FacModeNum.Text;
  3765. var SNArray = new byte[16];
  3766. for (ushort i = 0; i < SN.Length; i++)
  3767. {
  3768. SNArray[i] = (byte)SN[i];
  3769. }
  3770. if (SN.Length < 16)
  3771. {
  3772. SNArray[SN.Length] = (byte)'.';
  3773. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3774. {
  3775. SNArray[SN.Length + 1 + i] = 0x20;
  3776. }
  3777. }
  3778. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3779. }
  3780. /// <summary>
  3781. /// 生产模式读取版本信息
  3782. /// </summary>
  3783. /// <param name="sender"></param>
  3784. /// <param name="e"></param>
  3785. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  3786. {
  3787. textBox_Model.Text = "---";
  3788. textBox_SN.Text = "---";
  3789. textBox_HW.Text = "---";
  3790. textBox_FW.Text = "---";
  3791. textBox_SP.Text = "---";
  3792. textBox_OBC_ReadModel.Text = "---";
  3793. textBox_OBC_ReadSN.Text = "---";
  3794. textBox_OBC_ReadHW.Text = "---";
  3795. textBox_OBC_ReadFW.Text = "---";
  3796. textBox_OBC_ReadSP.Text = "---";
  3797. textBox_FacModeName.Text = "---";
  3798. textBox_FacModeNum.Text = "---";
  3799. textBox_FacModeHW.Text = "---";
  3800. textBox_FacModeFW.Text = "---";
  3801. textBox_FacModeSP.Text = "---";
  3802. textBox_FacModeGit.Text = "---";
  3803. Class_Motor_Ver.Mode = "---";
  3804. Class_Motor_Ver.SN = "---";
  3805. Class_Motor_Ver.HW = "---";
  3806. Class_Motor_Ver.FW = "---";
  3807. Class_Motor_Ver.Special = "---";
  3808. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3809. }
  3810. /// <summary>
  3811. /// 生产模式写入生产信息
  3812. /// </summary>
  3813. /// <param name="sender"></param>
  3814. /// <param name="e"></param>
  3815. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  3816. {
  3817. var MACArray = new byte[32];
  3818. string MacDefaultInfo = "";
  3819. string MacAddDefaultInfo = "";
  3820. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  3821. string MacPPDefaultInfo = "";
  3822. do
  3823. {
  3824. //填入生产商
  3825. if (toolStripTextBox_MAC.Text == string.Empty)
  3826. {
  3827. break;
  3828. }
  3829. MacDefaultInfo = toolStripTextBox_MAC.Text;
  3830. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  3831. {
  3832. MACArray[i] = (byte)MacDefaultInfo[i];
  3833. }
  3834. if (MacDefaultInfo.Length < 8)
  3835. {
  3836. MACArray[MacDefaultInfo.Length] = (byte)'.';
  3837. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  3838. {
  3839. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  3840. }
  3841. }
  3842. //填入生产地
  3843. if (toolStripTextBoxMACAddr.Text == string.Empty)
  3844. {
  3845. break;
  3846. }
  3847. MacAddDefaultInfo = toolStripTextBoxMACAddr.Text;
  3848. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  3849. {
  3850. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  3851. }
  3852. if (MacAddDefaultInfo.Length < 8)
  3853. {
  3854. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  3855. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  3856. {
  3857. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  3858. }
  3859. }
  3860. //填入生产日期
  3861. if (toolStripTextBox_MACDate.Text == string.Empty)
  3862. {
  3863. break;
  3864. }
  3865. MacDateDefaultInfo = toolStripTextBox_MACDate.Text;
  3866. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  3867. {
  3868. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  3869. }
  3870. if (MacDateDefaultInfo.Length < 8)
  3871. {
  3872. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  3873. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  3874. {
  3875. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  3876. }
  3877. }
  3878. //填入产品标识
  3879. if (toolStripTextBox_MACPD.Text == string.Empty)
  3880. {
  3881. break;
  3882. }
  3883. MacPPDefaultInfo = toolStripTextBox_MACPD.Text;
  3884. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  3885. {
  3886. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  3887. }
  3888. if (MacPPDefaultInfo.Length < 8)
  3889. {
  3890. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  3891. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  3892. {
  3893. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  3894. }
  3895. }
  3896. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3897. return;
  3898. } while (false);
  3899. timer_1s.Enabled = false;
  3900. MessageBox.Show("生产信息配置不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3901. timer_1s.Enabled = true;
  3902. }
  3903. /// <summary>
  3904. /// 生产模式保存测试页面
  3905. /// </summary>
  3906. /// <param name="sender"></param>
  3907. /// <param name="e"></param>
  3908. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  3909. {
  3910. Button_FacModeSaveResult.Text = "存储中…";
  3911. do
  3912. {
  3913. //读取一次马达参数
  3914. richTextBox_MotorParam.Clear();
  3915. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
  3916. Delay_ms(100);
  3917. //读取一次整车参数
  3918. richTextBox_BikeParam.Clear();
  3919. textBox_FacModeWheelSize.Text = "";
  3920. textBox_FacModeSpeedLimit.Text = "";
  3921. comboBox_FacModeAssist1.SelectedIndex = -1;
  3922. comboBox_FacModeAssist2.SelectedIndex = -1;
  3923. comboBox_FacModeLightVol.SelectedIndex = -1;
  3924. comboBox_FacModeStartMode.SelectedIndex = -1;
  3925. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
  3926. Delay_ms(100);
  3927. //读取一次控制参数
  3928. richTextBox_ControlParam.Clear();
  3929. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
  3930. Delay_ms(100);
  3931. //查询传感器
  3932. richTextBox_SensorParam.Clear();
  3933. textBox_FacModeSensorADC0.Text = "";
  3934. textBox_FacModeSensorADC1.Text = "";
  3935. textBox_FacModeSensorADC2.Text = "";
  3936. textBox_FacModeSensorADC3.Text = "";
  3937. textBox_FacModeSensorADC4.Text = "";
  3938. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
  3939. Delay_ms(100);
  3940. //读取一次助力参数
  3941. var ConfigParam = new byte[4];
  3942. textBox_FacModeStartGain.Text = "";
  3943. textBox_FacModeCircuitK.Text = "";
  3944. textBox_FacModeFltCounter.Text = "";
  3945. textBox_FacModeSpeedLimitTh.Text = "";
  3946. textBox_FacModeSpeedLimitEnd.Text = "";
  3947. textBox_FacModeCadencePer.Text = "";
  3948. richTextBox_AssistParam.Clear();
  3949. ConfigParam[0] = (byte)(1 & 0xFF);
  3950. ConfigParam[1] = (byte)(1 >> 8);
  3951. ConfigParam[2] = (byte)(1 & 0xFF);
  3952. ConfigParam[3] = (byte)(1 >> 8);
  3953. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
  3954. Delay_ms(100);
  3955. //读取一次调试信息
  3956. richTextBox_DebugParam.Clear();
  3957. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
  3958. Delay_ms(100);
  3959. //读取一次历史信息
  3960. richTextBox_Record.Clear();
  3961. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
  3962. Delay_ms(100);
  3963. //读取一次电机运行信息
  3964. var CtrlCode = new byte[2];
  3965. CtrlCode[0] = 0x00;
  3966. CtrlCode[1] = 0xF0;
  3967. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
  3968. Delay_ms(100);
  3969. //读取一次版本信息
  3970. textBox_Model.Text = "---";
  3971. textBox_SN.Text = "---";
  3972. textBox_HW.Text = "---";
  3973. textBox_FW.Text = "---";
  3974. textBox_OBC_ReadModel.Text = "---";
  3975. textBox_OBC_ReadSN.Text = "---";
  3976. textBox_OBC_ReadHW.Text = "---";
  3977. textBox_OBC_ReadFW.Text = "---";
  3978. textBox_FacModeName.Text = "---";
  3979. textBox_FacModeNum.Text = "---";
  3980. textBox_FacModeHW.Text = "---";
  3981. textBox_FacModeFW.Text = "---";
  3982. Class_Motor_Ver.Mode = "---";
  3983. Class_Motor_Ver.SN = "---";
  3984. Class_Motor_Ver.HW = "---";
  3985. Class_Motor_Ver.FW = "---";
  3986. Class_Motor_Ver.Special = "---";
  3987. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
  3988. Delay_ms(100);
  3989. //读取一次生产信息
  3990. textBox_MAC.Text = "";
  3991. textBox_MACAdd.Text = "";
  3992. textBox_MACDate.Text = "";
  3993. textBox_PP.Text = "";
  3994. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
  3995. Delay_ms(100);
  3996. //读取一次自定义信息
  3997. textBox_User1.Text = "---";
  3998. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
  3999. Delay_ms(100);
  4000. textBox_User2.Text = "---";
  4001. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
  4002. Delay_ms(100);
  4003. textBox_User3.Text = "---";
  4004. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
  4005. Delay_ms(100);
  4006. //读取一次密钥
  4007. textBox_Key.Text = "---";
  4008. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
  4009. Delay_ms(100);
  4010. //读取一次存储标志
  4011. radioButton_EE_SaveYes.Checked = false;
  4012. radioButton_EE_SaveNo.Checked = false;
  4013. radioButton_SIP_SaveYes.Checked = false;
  4014. radioButton_SIP_SaveNo.Checked = false;
  4015. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
  4016. Delay_ms(100);
  4017. //提示检查
  4018. #if false
  4019. timer_1s.Enabled = false;
  4020. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  4021. {
  4022. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4023. timer_1s.Enabled = true;
  4024. return;
  4025. }
  4026. timer_1s.Enabled = true;
  4027. Delay_ms(200);
  4028. #endif
  4029. //判断数据是否有效
  4030. if ((textBox_FacModeName.Text == "---") || (textBox_FacModeNum.Text == "--"))
  4031. {
  4032. MessageBox.Show("SN无效,上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4033. break;
  4034. }
  4035. if ((textBox_FacModeName.Text == string.Empty) || (textBox_FacModeNum.Text == string.Empty))
  4036. {
  4037. MessageBox.Show("SN无效,上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4038. break;
  4039. }
  4040. if (!textBox_FacModeName.Text.Contains("MIGIC"))
  4041. {
  4042. MessageBox.Show("型号名无效,上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4043. break;
  4044. }
  4045. //设置文件存储路径
  4046. string Save_Path = LocalPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; ;
  4047. string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
  4048. Save_Path += PD_PathName;
  4049. if (!Directory.Exists(Save_Path))
  4050. Directory.CreateDirectory(Save_Path);
  4051. //保存页面
  4052. string PIC_SaveFileName = "";
  4053. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  4054. Graphics g = Graphics.FromImage(bit);
  4055. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  4056. PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
  4057. bit.Save(PIC_SaveFileName);
  4058. //保存数据
  4059. string DataFileName = "";
  4060. string FileInfo = "";
  4061. DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
  4062. FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4063. FileInfo += "\r\n";
  4064. FileInfo += "[电机信息]\r\n";
  4065. FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
  4066. FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
  4067. FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
  4068. FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
  4069. FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
  4070. FileInfo += "\r\n";
  4071. FileInfo += "[马达参数]\r\n";
  4072. FileInfo += richTextBox_MotorParam.Text + "\r\n";
  4073. FileInfo += "\r\n";
  4074. FileInfo += "[整车参数]\r\n";
  4075. FileInfo += richTextBox_BikeParam.Text + "\r\n";
  4076. FileInfo += "\r\n";
  4077. FileInfo += "[控制参数]\r\n";
  4078. FileInfo += richTextBox_ControlParam.Text + "\r\n";
  4079. FileInfo += "\r\n";
  4080. FileInfo += "[传感器参数]\r\n";
  4081. FileInfo += richTextBox_SensorParam.Text + "\r\n";
  4082. FileInfo += "\r\n";
  4083. FileInfo += "[助力参数]\r\n";
  4084. FileInfo += richTextBox_AssistParam.Text + "\r\n";
  4085. FileInfo += "\r\n";
  4086. FileInfo += "[调试参数]\r\n";
  4087. FileInfo += richTextBox_DebugParam.Text + "\r\n";
  4088. FileInfo += "\r\n";
  4089. FileInfo += "[历史信息]\r\n";
  4090. FileInfo += richTextBox_Record.Text + "\r\n";
  4091. FileInfo += "\r\n";
  4092. FileInfo += "[生产信息]\r\n";
  4093. FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
  4094. FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
  4095. FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
  4096. FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
  4097. FileInfo += "\r\n";
  4098. FileInfo += "[自定义信息]\r\n";
  4099. FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
  4100. FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
  4101. FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
  4102. FileInfo += "\r\n";
  4103. FileInfo += "[校验密钥]\r\n";
  4104. FileInfo += textBox_Key.Text + "\r\n";
  4105. FileInfo += "\r\n";
  4106. FileInfo += "[存储标志]\r\n";
  4107. FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4108. FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
  4109. FileInfo += "\r\n";
  4110. System.IO.File.WriteAllText(DataFileName, FileInfo);
  4111. timer_1s.Enabled = false;
  4112. MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4113. timer_1s.Enabled = true;
  4114. //数据上传
  4115. if (myFtp.IsNetConnected == true)
  4116. {
  4117. string DataNow= DateTime.Now.ToString("yyyy-MM-dd");
  4118. //检查路径
  4119. if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
  4120. {
  4121. myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
  4122. }
  4123. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, DataNow) == false)
  4124. {
  4125. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\" + DataNow);
  4126. }
  4127. if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\" + DataNow, PD_PathName) == false)
  4128. {
  4129. myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
  4130. }
  4131. //上传文件
  4132. bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
  4133. bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
  4134. if ((result1 & result2) == true)
  4135. {
  4136. timer_1s.Enabled = false;
  4137. MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4138. timer_1s.Enabled = true;
  4139. }
  4140. else
  4141. {
  4142. timer_1s.Enabled = false;
  4143. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4144. timer_1s.Enabled = true;
  4145. }
  4146. }
  4147. else
  4148. {
  4149. timer_1s.Enabled = false;
  4150. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4151. timer_1s.Enabled = true;
  4152. }
  4153. Button_FacModeSaveResult.Text = "保存数据";
  4154. return;
  4155. } while (false);
  4156. timer_1s.Enabled = false;
  4157. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4158. timer_1s.Enabled = true;
  4159. Button_FacModeSaveResult.Text = "保存数据";
  4160. }
  4161. /// <summary>
  4162. /// 工具箱页面保存
  4163. /// </summary>
  4164. /// <param name="sender"></param>
  4165. /// <param name="e"></param>
  4166. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  4167. {
  4168. //保存页面
  4169. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  4170. Graphics g = Graphics.FromImage(bit);
  4171. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  4172. SaveFileDialog sf = new SaveFileDialog();
  4173. sf.Title = "页面保存";
  4174. sf.FileName = "MotorInfo_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  4175. sf.Filter = "图片|*.png";
  4176. timer_1s.Enabled = false;
  4177. if (sf.ShowDialog() == DialogResult.OK)
  4178. {
  4179. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  4180. }
  4181. timer_1s.Enabled = true;
  4182. }
  4183. /// <summary>
  4184. /// 生产模式关机
  4185. /// </summary>
  4186. /// <param name="sender"></param>
  4187. /// <param name="e"></param>
  4188. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  4189. {
  4190. var Code_Off = new byte[5];
  4191. var Code_Reset = new byte[5];
  4192. Code_Off[0] = (byte)'O';
  4193. Code_Off[1] = (byte)'F';
  4194. Code_Off[2] = (byte)'F';
  4195. Code_Off[3] = (byte)'.';
  4196. Code_Off[4] = (byte)'.';
  4197. Code_Reset[0] = (byte)'R';
  4198. Code_Reset[1] = (byte)'E';
  4199. Code_Reset[2] = (byte)'S';
  4200. Code_Reset[3] = (byte)'E';
  4201. Code_Reset[4] = (byte)'T';
  4202. timer_1s.Enabled = false;
  4203. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  4204. {
  4205. timer_1s.Enabled = true;
  4206. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4207. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4208. PowerOffAckStatus = false;
  4209. Delay_ms(250);
  4210. int TryCnt = 3;
  4211. while ((TryCnt--) >= 0)
  4212. {
  4213. if (!PowerOffAckStatus)
  4214. {
  4215. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Off);
  4216. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code_Reset);
  4217. PowerOffAckStatus = false;
  4218. Delay_ms(250);
  4219. }
  4220. else break;
  4221. }
  4222. if (PowerOffAckStatus)
  4223. {
  4224. timer_1s.Enabled = false;
  4225. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  4226. timer_1s.Enabled = true;
  4227. }
  4228. else
  4229. {
  4230. timer_1s.Enabled = false;
  4231. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4232. timer_1s.Enabled = true;
  4233. }
  4234. }
  4235. timer_1s.Enabled = true;
  4236. }
  4237. //仪表电源键按下
  4238. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  4239. {
  4240. var Code = new byte[2];
  4241. Code[0] = 0;
  4242. Code[1] = 0b00100000;
  4243. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4244. }
  4245. /// <summary>
  4246. /// 仪表加键按下
  4247. /// </summary>
  4248. /// <param name="sender"></param>
  4249. /// <param name="e"></param>
  4250. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  4251. {
  4252. var Code = new byte[2];
  4253. Code[0] = 0;
  4254. Code[1] = 0b00010000;
  4255. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4256. }
  4257. /// <summary>
  4258. /// 仪表减键按下
  4259. /// </summary>
  4260. /// <param name="sender"></param>
  4261. /// <param name="e"></param>
  4262. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  4263. {
  4264. var Code = new byte[2];
  4265. Code[0] = 0;
  4266. Code[1] = 0b00001000;
  4267. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4268. }
  4269. /// <summary>
  4270. /// 仪表Walk键按下
  4271. /// </summary>
  4272. /// <param name="sender"></param>
  4273. /// <param name="e"></param>
  4274. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  4275. {
  4276. var Code = new byte[2];
  4277. Code[0] = 0;
  4278. Code[1] = 0b00000100;
  4279. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4280. }
  4281. /// <summary>
  4282. /// 仪表Light键按下
  4283. /// </summary>
  4284. /// <param name="sender"></param>
  4285. /// <param name="e"></param>
  4286. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  4287. {
  4288. var Code = new byte[2];
  4289. Code[0] = 0;
  4290. Code[1] = 0b00000010;
  4291. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4292. }
  4293. /// <summary>
  4294. /// 仪表Set键按下
  4295. /// </summary>
  4296. /// <param name="sender"></param>
  4297. /// <param name="e"></param>
  4298. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  4299. {
  4300. var Code = new byte[2];
  4301. Code[0] = 0;
  4302. Code[1] = 0b00000001;
  4303. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  4304. }
  4305. /// <summary>
  4306. /// 带载类型选择
  4307. /// </summary>
  4308. /// <param name="sender"></param>
  4309. /// <param name="e"></param>
  4310. private void label_Load_Click(object sender, EventArgs e)
  4311. {
  4312. if (label_Load.Text == "带载")
  4313. label_Load.Text = "空载";
  4314. else if (label_Load.Text == "空载")
  4315. label_Load.Text = "带载";
  4316. }
  4317. /// <summary>
  4318. /// 控制模式选择
  4319. /// </summary>
  4320. /// <param name="sender"></param>
  4321. /// <param name="e"></param>
  4322. private void label_MotorSensor_Click(object sender, EventArgs e)
  4323. {
  4324. if (label_MotorSensor.Text == "有感")
  4325. label_MotorSensor.Text = "无感";
  4326. else if (label_MotorSensor.Text == "无感")
  4327. label_MotorSensor.Text = "有感";
  4328. }
  4329. /// <summary>
  4330. /// 导出电机故障日志
  4331. /// </summary>
  4332. /// <param name="sender"></param>
  4333. /// <param name="e"></param>
  4334. private void button_ExportLog_Click(object sender, EventArgs e)
  4335. {
  4336. var Address = new byte[4];
  4337. UInt32 Address_Begin;
  4338. UInt32 Addres_End;
  4339. string textBox_Address_Begin = textBox_LogAddrBegin.Text;
  4340. string textBox_Address_End = textBox_LogAddrEnd.Text;
  4341. richTextBox_Record.Clear();
  4342. textBox_LogAddrBegin.ReadOnly = true;
  4343. textBox_LogAddrEnd.ReadOnly = true;
  4344. if (!mySerialProcess.mySerial.IsOpen)
  4345. {
  4346. timer_1s.Enabled = false;
  4347. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4348. timer_1s.Enabled = true;
  4349. return;
  4350. }
  4351. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  4352. {
  4353. timer_1s.Enabled = false;
  4354. MessageBox.Show("请输入日志存储起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4355. timer_1s.Enabled = true;
  4356. return;
  4357. }
  4358. else
  4359. {
  4360. Address = HexStringToBytes(textBox_Address_Begin, false);
  4361. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4362. Address = HexStringToBytes(textBox_Address_End, false);
  4363. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  4364. if (Addres_End <= Address_Begin)
  4365. {
  4366. timer_1s.Enabled = false;
  4367. MessageBox.Show("结束地址应大于起始地址!", "提示");
  4368. timer_1s.Enabled = true;
  4369. return;
  4370. }
  4371. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  4372. {
  4373. timer_1s.Enabled = false;
  4374. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  4375. timer_1s.Enabled = true;
  4376. return;
  4377. }
  4378. else
  4379. {
  4380. UInt32 ReadCount = 0;
  4381. button_ExportLog.Text = "导出中...";
  4382. button_ExportLog.Enabled = false;
  4383. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  4384. for (ushort i = 0; i < ReadCount; i++)
  4385. {
  4386. var SendByte = new byte[8];
  4387. UInt32 Address_Temp_Begin;
  4388. UInt32 Address_Temp_End;
  4389. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  4390. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  4391. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  4392. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  4393. SendByte[3] = (byte)(Address_Temp_Begin);
  4394. Address_Temp_End = Address_Temp_Begin + 127;
  4395. SendByte[4] = (byte)(Address_Temp_End >> 24);
  4396. SendByte[5] = (byte)(Address_Temp_End >> 16);
  4397. SendByte[6] = (byte)(Address_Temp_End >> 8);
  4398. SendByte[7] = (byte)(Address_Temp_End);
  4399. mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  4400. Delay_ms(200);//Thread.Sleep(200);
  4401. }
  4402. button_ExportLog.Text = "导出日志";
  4403. button_ExportLog.Enabled = true;
  4404. }
  4405. }
  4406. }
  4407. /// <summary>
  4408. /// 保存日志信息
  4409. /// </summary>
  4410. /// <param name="sender"></param>
  4411. /// <param name="e"></param>
  4412. private void button_SaveRecordInfo_Click(object sender, EventArgs e)
  4413. {
  4414. string SaveInfo = "";
  4415. if (richTextBox_Record.Text == string.Empty)
  4416. {
  4417. timer_1s.Enabled = false;
  4418. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  4419. timer_1s.Enabled = true;
  4420. return;
  4421. }
  4422. //获取保存信息
  4423. SaveInfo += "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
  4424. SaveInfo += "电机型号:" + textBox_FacModeName.Text + "\r\n";
  4425. SaveInfo += "电机SN:" + textBox_FacModeNum.Text + "\r\n";
  4426. SaveInfo += "硬件版本:" + textBox_FacModeHW.Text + "\r\n";
  4427. SaveInfo += "软件版本:" + textBox_FacModeFW.Text + "\r\n";
  4428. SaveInfo += "\r\n";
  4429. SaveInfo += richTextBox_Record.Text;
  4430. //设置保存路径和文件名
  4431. SaveFileDialog sf = new SaveFileDialog();
  4432. sf.Title = "数据保存";
  4433. sf.FileName = "MotorLog_" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".ttlog";
  4434. sf.FileName.Replace(" ", "");
  4435. sf.Filter = "日志|*.ttlog";
  4436. if (sf.ShowDialog() == DialogResult.OK)
  4437. {
  4438. System.IO.File.AppendAllText(sf.FileName, SaveInfo);
  4439. }
  4440. }
  4441. /// <summary>
  4442. /// 双击修改日志起始地址
  4443. /// </summary>
  4444. /// <param name="sender"></param>
  4445. /// <param name="e"></param>
  4446. private void label_LogAddrBegin_DoubleClick_1(object sender, EventArgs e)
  4447. {
  4448. textBox_LogAddrBegin.ReadOnly = false;
  4449. }
  4450. /// <summary>
  4451. /// 双击修改日志结束地址
  4452. /// </summary>
  4453. /// <param name="sender"></param>
  4454. /// <param name="e"></param>
  4455. private void label88_DoubleClick(object sender, EventArgs e)
  4456. {
  4457. textBox_LogAddrEnd.ReadOnly = false;
  4458. }
  4459. /// <summary>
  4460. /// 存储器自动读取选择
  4461. /// </summary>
  4462. /// <param name="sender"></param>
  4463. /// <param name="e"></param>
  4464. private void checkBox_ReadRanFlash_AutoSW_CheckedChanged(object sender, EventArgs e)
  4465. {
  4466. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  4467. {
  4468. //检查串口是否打开
  4469. if (!mySerialProcess.mySerial.IsOpen)
  4470. {
  4471. timer_1s.Enabled = false;
  4472. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4473. timer_1s.Enabled = true;
  4474. checkBox_ReadRanFlash_AutoSW.Checked = false;
  4475. return;
  4476. }
  4477. }
  4478. }
  4479. /// <summary>
  4480. /// 系统开机按钮
  4481. /// </summary>
  4482. /// <param name="sender"></param>
  4483. /// <param name="e"></param>
  4484. private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4485. {
  4486. byte[] Data = new byte[1];
  4487. Data[0] = 0xF1;
  4488. if (mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data))
  4489. {
  4490. 开机ToolStripMenuItem.Checked = true;
  4491. 关机ToolStripMenuItem.Checked = false;
  4492. }
  4493. }
  4494. /// <summary>
  4495. /// 系统关机按钮
  4496. /// </summary>
  4497. /// <param name="sender"></param>
  4498. /// <param name="e"></param>
  4499. private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4500. {
  4501. byte[] Data = new byte[1];
  4502. Data[0] = 0xF0;
  4503. if (mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data))
  4504. {
  4505. 开机ToolStripMenuItem.Checked = false;
  4506. 关机ToolStripMenuItem.Checked = true;
  4507. }
  4508. }
  4509. /// <summary>
  4510. /// 连接开机选择
  4511. /// </summary>
  4512. /// <param name="sender"></param>
  4513. /// <param name="e"></param>
  4514. private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
  4515. {
  4516. 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
  4517. ConfigFileSave(true, ConfigFileName);
  4518. }
  4519. /// <summary>
  4520. /// 断开关机选择
  4521. /// </summary>
  4522. /// <param name="sender"></param>
  4523. /// <param name="e"></param>
  4524. private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
  4525. {
  4526. 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
  4527. ConfigFileSave(true, ConfigFileName);
  4528. }
  4529. /// <summary>
  4530. /// 识别通讯盒选择
  4531. /// </summary>
  4532. /// <param name="sender"></param>
  4533. /// <param name="e"></param>
  4534. private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
  4535. {
  4536. 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
  4537. ConfigFileSave(true, ConfigFileName);
  4538. }
  4539. /// <summary>
  4540. /// 将配置信息导出为cfg文件
  4541. /// </summary>
  4542. private void ConfigFileSave(bool DeleteFlag, string FileName)
  4543. {
  4544. if (DeleteFlag)
  4545. {
  4546. if (File.Exists(FileName))
  4547. File.Delete(FileName);
  4548. }
  4549. string CfgFileInfo = "";
  4550. CfgFileInfo += "[PortSet]" + "\r\n";
  4551. CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
  4552. CfgFileInfo += "PortBaudrate:" + toolStripComboBox_Baudrate.Text + "\r\n";
  4553. CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4554. CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
  4555. CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
  4556. CfgFileInfo += "\r\n";
  4557. CfgFileInfo += "[Option]" + "\r\n";
  4558. CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
  4559. CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
  4560. CfgFileInfo += "\r\n";
  4561. CfgFileInfo += "[ServerSet]" + "\r\n";
  4562. CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
  4563. CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
  4564. CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
  4565. CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
  4566. CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
  4567. CfgFileInfo += "\r\n";
  4568. CfgFileInfo += "[MacInfo]" + "\r\n";
  4569. CfgFileInfo += "MacName:" + toolStripTextBox_MAC.Text + "\r\n";
  4570. CfgFileInfo += "MacAddress:" + toolStripTextBoxMACAddr.Text + "\r\n";
  4571. CfgFileInfo += "MacDate:" + toolStripTextBox_MACDate.Text + "\r\n";
  4572. CfgFileInfo += "MacPdInfo:" + toolStripTextBox_MACPD.Text + "\r\n";
  4573. CfgFileInfo += "\r\n";
  4574. CfgFileInfo += "[LogAddress]" + "\r\n";
  4575. CfgFileInfo += "BeginAddress:" + textBox_LogAddrBegin.Text + "\r\n";
  4576. CfgFileInfo += "EndAddress:" + textBox_LogAddrEnd.Text + "\r\n";
  4577. System.IO.File.WriteAllText(FileName, CfgFileInfo);
  4578. }
  4579. /// <summary>
  4580. /// 配置状态更新,点击时保存
  4581. /// </summary>
  4582. private void ConfigFileSave_Click(object sender, EventArgs e)
  4583. {
  4584. ConfigFileSave(true, ConfigFileName);
  4585. }
  4586. /// <summary>
  4587. /// 文本框修改结束,回车保存
  4588. /// </summary>
  4589. /// <param name="sender"></param>
  4590. /// <param name="e"></param>
  4591. private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
  4592. {
  4593. if (e.KeyCode == Keys.Enter)
  4594. {
  4595. ConfigFileSave(true, ConfigFileName);
  4596. }
  4597. }
  4598. /// <summary>
  4599. /// 允许离线使用
  4600. /// </summary>
  4601. /// <param name="sender"></param>
  4602. /// <param name="e"></param>
  4603. private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
  4604. {
  4605. 允许ToolStripMenuItem.Checked = true;
  4606. 不允许ToolStripMenuItem.Checked = false;
  4607. ConfigFileSave(true, ConfigFileName);
  4608. }
  4609. /// <summary>
  4610. /// 不允许离线使用
  4611. /// </summary>
  4612. /// <param name="sender"></param>
  4613. /// <param name="e"></param>
  4614. private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
  4615. {
  4616. 允许ToolStripMenuItem.Checked = false;
  4617. 不允许ToolStripMenuItem.Checked = true;
  4618. ConfigFileSave(true, ConfigFileName);
  4619. }
  4620. /// <summary>
  4621. /// 弹出扫码按钮
  4622. /// </summary>
  4623. /// <param name="sender"></param>
  4624. /// <param name="e"></param>
  4625. private void button_ScanCode_Click(object sender, EventArgs e)
  4626. {
  4627. Scan scan_form = new Scan();
  4628. scan_form.ShowDialog();
  4629. do
  4630. {
  4631. if (scan_form.textBox_Code.Text == string.Empty)
  4632. {
  4633. timer_1s.Enabled = false;
  4634. MessageBox.Show("无内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4635. timer_1s.Enabled = true;
  4636. break;
  4637. }
  4638. string ScanInfo = scan_form.textBox_Code.Text;
  4639. string regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
  4640. string[] InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
  4641. if (InfoList.Length >= 2)
  4642. {
  4643. //写入型号
  4644. textBox_FacModeName.Text = InfoList[0];
  4645. string Mode = textBox_FacModeName.Text;
  4646. var ModeArray = new byte[16];
  4647. for (ushort i = 0; i < Mode.Length; i++)
  4648. {
  4649. ModeArray[i] = (byte)Mode[i];
  4650. }
  4651. if (Mode.Length < 16)
  4652. {
  4653. ModeArray[Mode.Length] = (byte)'.';
  4654. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  4655. {
  4656. ModeArray[Mode.Length + 1 + i] = 0x20;
  4657. }
  4658. }
  4659. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  4660. //写入SN
  4661. textBox_FacModeNum.Text = InfoList[1];
  4662. string SN = textBox_FacModeNum.Text;
  4663. var SNArray = new byte[16];
  4664. for (ushort i = 0; i < SN.Length; i++)
  4665. {
  4666. SNArray[i] = (byte)SN[i];
  4667. }
  4668. if (SN.Length < 16)
  4669. {
  4670. SNArray[SN.Length] = (byte)'.';
  4671. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  4672. {
  4673. SNArray[SN.Length + 1 + i] = 0x20;
  4674. }
  4675. }
  4676. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  4677. }
  4678. else
  4679. {
  4680. timer_1s.Enabled = false;
  4681. MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  4682. timer_1s.Enabled = true;
  4683. break;
  4684. }
  4685. } while (false);
  4686. scan_form.Dispose();
  4687. }
  4688. }
  4689. }