Form1.cs 149 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Threading;
  5. using System.Windows.Forms;
  6. namespace Welling_Motor_Debug_Tool
  7. {
  8. public partial class Form1 : Form
  9. {
  10. #region 变量定义
  11. //串口实例
  12. Serial_Process mySerialProcess = new Serial_Process();
  13. //MC运行信息超时计数
  14. bool MC_RunInfo_Refresh = false;
  15. ushort MC_RunInfo_Refresh_Cnt = 0;
  16. //MC故障码超时计数
  17. bool MC_ErrorCode_Refresh = false;
  18. ushort MC_ErrorCode_Refresh_Cnt = 0;
  19. //配置参数实例
  20. Params myParams = new Params();
  21. //记录文件名称
  22. string SaveFilename = "";
  23. //BMS运行信息超时计数
  24. bool BMS_RunInfo_Refresh = false;
  25. ushort BMS_RunInfo_Refresh_Cnt = 0;
  26. //生产模式关机指令反馈装
  27. bool PowerOffAckStatus = false;
  28. #endregion
  29. public Form1()
  30. {
  31. InitializeComponent();
  32. }
  33. #region 非独占性延时函数
  34. public static void Delay_ms(int milliSecond)
  35. {
  36. int start = Environment.TickCount;
  37. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  38. {
  39. Application.DoEvents();
  40. }
  41. }
  42. #endregion
  43. private void Form1_Load(object sender, System.EventArgs e)
  44. {
  45. //页面初始化
  46. label_BuildTime.Text= "编译时间:"+ System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
  47. //下拉控件初始值设定
  48. comboBox_WorkMode.SelectedIndex = 0;
  49. comboBox_GearSt.SelectedIndex = 0;
  50. comboBox_LightSwitch.SelectedIndex = 1;
  51. comboBox_OBC_SetGearST.SelectedIndex = 0;
  52. comboBox_OBC_LightSw.SelectedIndex = 1;
  53. comboBox_AssistTorque.SelectedIndex = 0;
  54. comboBox_AssistCadence.SelectedIndex = 0;
  55. //combobox事件定义
  56. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  57. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  58. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  59. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  60. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  61. //端口设置
  62. mySerialProcess.Init();
  63. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  64. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  65. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
  66. //创建线程,定时解析数据
  67. Thread th = new Thread(Task_SerialProcess);
  68. th.IsBackground = true;
  69. th.Start();
  70. }
  71. #region 串口数据解析线程
  72. /// <summary>
  73. /// 串口数据解析线程
  74. /// </summary>
  75. private void Task_SerialProcess()
  76. {
  77. //创建定时器,定时读取串口数据
  78. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  79. timer_ReadSerial.Enabled = true;
  80. timer_ReadSerial.Interval = 20;
  81. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  82. timer_ReadSerial.Start();
  83. while (true)
  84. {
  85. Thread.Sleep(1);
  86. };
  87. }
  88. /// <summary>
  89. /// 串口解析定时器
  90. /// </summary>
  91. /// <param name="sender"></param>
  92. /// <param name="e"></param>
  93. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  94. {
  95. //串口解析
  96. Serial_process(mySerialProcess.buffer);
  97. }
  98. #endregion
  99. #region 数据解析
  100. public void Serial_process(List<byte> buffer)
  101. {
  102. byte DataNum = 0; //记录每条命令数据段的长度
  103. ushort PackageID, Cmd;
  104. byte[] Data = new byte[1024];
  105. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  106. {
  107. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  108. {
  109. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  110. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  111. {
  112. int CmdLen = buffer[5];
  113. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  114. buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
  115. while (CmdLen > 0) //读取命令段
  116. {
  117. Cmd = (ushort)(buffer[0] * 256 + buffer[1]);
  118. DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
  119. if (DataNum <= (CmdLen - 2))
  120. {
  121. for (int i = 0; i < DataNum; i++)
  122. {
  123. Data[i] = buffer[i + 2];
  124. }
  125. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  126. buffer.RemoveRange(0, DataNum);//移除处理过的数据段
  127. CmdLen -= (DataNum + 2);
  128. if (CmdLen < 2)
  129. {
  130. buffer.RemoveRange(0, CmdLen + 2);
  131. return;
  132. }
  133. }
  134. else
  135. {
  136. buffer.RemoveRange(0, CmdLen + 11);
  137. }
  138. }
  139. }
  140. else
  141. {
  142. buffer.RemoveAt(0);//ID不对
  143. }
  144. }
  145. else
  146. {
  147. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  148. }
  149. }
  150. }
  151. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  152. {
  153. int DataTemp;
  154. ushort uData16;
  155. unchecked
  156. {
  157. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  158. }
  159. #region 解析发送给CDL的指令
  160. if (ID == 0x7FF)
  161. {
  162. switch (CmdTemp)
  163. {
  164. case 0x1100://
  165. {
  166. unchecked
  167. {
  168. this.Invoke((EventHandler)(delegate
  169. {
  170. //CDL连接成功
  171. mySerialProcess.CDL_Online_Flag = true;
  172. MessageBox.Show("连接成功!", "提示");
  173. }));
  174. }
  175. break;
  176. }
  177. default: break;
  178. }
  179. }
  180. #endregion
  181. #region 解析电机的命令
  182. else if ((ID == 0x715) || (ID == 0x710))
  183. {
  184. switch (CmdTemp)
  185. {
  186. case 0x1020://电机运行信息
  187. {
  188. unchecked
  189. {
  190. this.Invoke((EventHandler)(delegate
  191. {
  192. MC_RunInfo_Refresh = true;
  193. //车速
  194. DataTemp = (int)(Data[1] * 256 + Data[0]);
  195. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  196. //输出转速
  197. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  198. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  199. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  200. Class_MotorSpeed.Data = DataTemp;
  201. //电功率
  202. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  203. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  204. //母线电压
  205. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  206. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  207. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  208. //母线电流
  209. DataTemp = (short)(Data[9] * 256 + Data[8]);
  210. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  211. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  212. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  213. Class_CurrentData.Data = DataTemp;
  214. //踏频
  215. DataTemp = (ushort)(Data[10]);
  216. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  217. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  218. Class_CadenceData.Data = DataTemp;
  219. //踩踏力矩
  220. DataTemp = (ushort)(Data[11]);
  221. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  222. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  223. Class_TorqueData.Data = DataTemp;
  224. //踩踏方向
  225. DataTemp = (ushort)(Data[12]);
  226. if (DataTemp == 0)
  227. {
  228. textBox_RunInfo_Dir.Text = "正向";
  229. }
  230. else if (DataTemp == 1)
  231. {
  232. textBox_RunInfo_Dir.Text = "反向";
  233. }
  234. else if (DataTemp == 2)
  235. {
  236. textBox_RunInfo_Dir.Text = "停止";
  237. }
  238. //助力档位
  239. DataTemp = (ushort)(Data[13]);
  240. if (DataTemp == 0x33)
  241. {
  242. textBox_RunInfo_GearSt.Text = "SMART";
  243. //comboBox_GearSt.SelectedIndex = 5;
  244. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  245. }
  246. else if (DataTemp == 0x22)
  247. {
  248. textBox_RunInfo_GearSt.Text = "WALK";
  249. //comboBox_GearSt.SelectedIndex = 6;
  250. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  251. }
  252. else
  253. {
  254. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  255. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  256. //comboBox_GearSt.SelectedIndex = DataTemp;
  257. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  258. }
  259. //大灯状态
  260. DataTemp = (ushort)(Data[14]);
  261. if (DataTemp == 0xF0)
  262. {
  263. textBox_RunInfo_LightSwitch.Text = "OFF";
  264. //comboBox_LightSwitch.SelectedIndex = 1;
  265. //comboBox_OBC_LightSw.SelectedIndex = 1;
  266. }
  267. else if (DataTemp == 0xF1)
  268. {
  269. textBox_RunInfo_LightSwitch.Text = "ON";
  270. //comboBox_LightSwitch.SelectedIndex = 0;
  271. //comboBox_OBC_LightSw.SelectedIndex = 0;
  272. }
  273. //剩余电量
  274. DataTemp = (ushort)(Data[15]);
  275. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  276. //剩余续航里程
  277. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  278. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  279. {
  280. textBox_RunInfo_Range.Text = "---";
  281. }
  282. else
  283. {
  284. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  285. }
  286. //预留(显示力矩Reg),空2bytes
  287. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  288. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  289. //平均功耗
  290. DataTemp = (ushort)(Data[20]);
  291. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  292. //PCB温度
  293. DataTemp = (ushort)(Data[21]);
  294. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40))+" ℃";
  295. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  296. Class_MotorTemp.Data = DataTemp - 40;
  297. //绕组温度
  298. DataTemp = (ushort)(Data[22]);
  299. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  300. //MCU温度
  301. DataTemp = (ushort)(Data[23]);
  302. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  303. //单次里程
  304. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  305. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  306. //单次时间
  307. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  308. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  309. //数据保存
  310. DataAutoSave();
  311. }));
  312. }
  313. break;
  314. }
  315. case 0x1104://故障码
  316. {
  317. unchecked
  318. {
  319. this.Invoke((EventHandler)(delegate
  320. {
  321. MC_ErrorCode_Refresh = true;
  322. textBox_ErrorCode.Text =
  323. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  324. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  325. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  326. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  327. "H";
  328. }));
  329. }
  330. break;
  331. }
  332. case 0xA903://反馈指令
  333. {
  334. unchecked
  335. {
  336. this.Invoke((EventHandler)(delegate
  337. {
  338. timer_1s.Enabled = false;
  339. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  340. timer_1s.Enabled = true;
  341. //关机反馈
  342. PowerOffAckStatus = true;
  343. }));
  344. }
  345. break;
  346. }
  347. case 0xB226://马达参数
  348. {
  349. unchecked
  350. {
  351. this.Invoke((EventHandler)(delegate
  352. {
  353. richTextBox_MotorParam.Clear();
  354. for (int i = 0; i < myParams.MotorParma.Count; i++)
  355. {
  356. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  357. }
  358. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  359. }));
  360. }
  361. break;
  362. }
  363. case 0xB31A://整车信息
  364. {
  365. unchecked
  366. {
  367. this.Invoke((EventHandler)(delegate
  368. {
  369. richTextBox_BikeParam.Clear();
  370. for (int i = 0; i < myParams.BikeParma.Count; i++)
  371. {
  372. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  373. }
  374. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  375. //更新生产模式中整车参数
  376. textBox_FacModeWheelSize.Text = (Data[1] * 256 + Data[0]).ToString();//周长
  377. textBox_FacModeSpeedLimit.Text= (Data[5] * 256 + Data[4]).ToString();//限速
  378. DataTemp = (int)(Data[13] * 256 + Data[12]);//助力方案1
  379. if (DataTemp == 0) comboBox_FacModeAssist1.SelectedIndex = 0;
  380. else if (DataTemp == 341) comboBox_FacModeAssist1.SelectedIndex = 1;
  381. else if (DataTemp == 682) comboBox_FacModeAssist1.SelectedIndex = 2;
  382. else comboBox_FacModeAssist1.SelectedIndex = 3;
  383. DataTemp = (int)(Data[15] * 256 + Data[14]);//助力方案2
  384. if (DataTemp == 0) comboBox_FacModeAssist2.SelectedIndex = 0;
  385. else if (DataTemp == 341) comboBox_FacModeAssist2.SelectedIndex = 1;
  386. else if (DataTemp == 682) comboBox_FacModeAssist2.SelectedIndex = 2;
  387. else comboBox_FacModeAssist2.SelectedIndex = 3;
  388. DataTemp = (int)(Data[17] * 256 + Data[16]);//灯压
  389. if (DataTemp == 6) comboBox_FacModeLightVol.SelectedIndex = 0;
  390. else if (DataTemp == 12) comboBox_FacModeLightVol.SelectedIndex = 1;
  391. else comboBox_FacModeLightVol.SelectedIndex = 2;
  392. DataTemp = (int)(Data[21] * 256 + Data[20]);//启动模式
  393. if (DataTemp == 1) comboBox_FacModeStartMode.SelectedIndex = 0;
  394. else if (DataTemp == 3) comboBox_FacModeStartMode.SelectedIndex = 2;
  395. else comboBox_FacModeStartMode.SelectedIndex = 1;
  396. }));
  397. }
  398. break;
  399. }
  400. case 0xB420://控制器参数
  401. {
  402. unchecked
  403. {
  404. this.Invoke((EventHandler)(delegate
  405. {
  406. richTextBox_ControlParam.Clear();
  407. for (int i = 0; i < myParams.ControlParma.Count; i++)
  408. {
  409. richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  410. }
  411. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  412. }));
  413. }
  414. break;
  415. }
  416. case 0xB528://传感器参数
  417. {
  418. unchecked
  419. {
  420. this.Invoke((EventHandler)(delegate
  421. {
  422. richTextBox_SensorParam.Clear();
  423. for (int i = 0; i < myParams.SensorParam.Count; i++)
  424. {
  425. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  426. }
  427. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  428. //更新生产模式页面传感器零点和标定值
  429. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  430. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  431. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  432. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  433. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  434. }));
  435. }
  436. break;
  437. }
  438. case 0xB64C://助力参数
  439. {
  440. unchecked
  441. {
  442. this.Invoke((EventHandler)(delegate
  443. {
  444. richTextBox_AssistParam.Clear();
  445. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  446. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  447. for (int i = 0; i < myParams.AssistParam.Count; i++)
  448. {
  449. if (i < index_1) //数据占用2bytes
  450. {
  451. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  452. }
  453. else if (i <= index_2) //数据占用4bytes
  454. {
  455. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((Data[4 * i - 5] << 24) + (Data[4 * i - 6] << 16) + (Data[4 * i - 7] << 8) + Data[4 * i - 8]) + ", ");
  456. }
  457. else //数据占用2bytes
  458. {
  459. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString(Data[2 * i + 17] * 256 + Data[2 * i + 16]) + ", ");
  460. }
  461. }
  462. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  463. //更新生产模式中助力参数
  464. textBox_FacModeStartGain.Text = (Data[1] * 256 + Data[0]).ToString();//零速增益
  465. textBox_FacModeCircuitK.Text = (Data[45] * 256 + Data[44]).ToString();//电流阶梯
  466. textBox_FacModeFltCounter.Text = (Data[49] * 256 + Data[48]).ToString();//滤波脉冲
  467. textBox_FacModeSpeedLimitTh.Text = (Data[55] * 256 + Data[54]).ToString();//限速启动
  468. textBox_FacModeSpeedLimitEnd.Text = (Data[57] * 256 + Data[56]).ToString();//限速停止
  469. textBox_FacModeCadencePer.Text = (Data[59] * 256 + Data[58]).ToString();//踏频占比
  470. }));
  471. }
  472. break;
  473. }
  474. case 0xB74C://历史记录
  475. {
  476. unchecked
  477. {
  478. this.Invoke((EventHandler)(delegate
  479. {
  480. richTextBox_Record.Clear();
  481. for (int i = 0; i < myParams.Record.Count; i++)
  482. {
  483. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  484. }
  485. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  486. }));
  487. }
  488. break;
  489. }
  490. case 0xB83A://调试参数
  491. {
  492. unchecked
  493. {
  494. this.Invoke((EventHandler)(delegate
  495. {
  496. richTextBox_DebugParam.Clear();
  497. for (int i = 0; i < myParams.DebugParam.Count; i++)
  498. {
  499. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  500. }
  501. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  502. }));
  503. }
  504. break;
  505. }
  506. case 0xB904://存储标志
  507. {
  508. unchecked
  509. {
  510. this.Invoke((EventHandler)(delegate
  511. {
  512. ushort Flag = 0;
  513. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  514. if (Flag == 0)
  515. {
  516. radioButton_EE_SaveNo.Checked = true;
  517. radioButton_EE_SaveYes.Checked = false;
  518. }
  519. else
  520. {
  521. radioButton_EE_SaveNo.Checked = false;
  522. radioButton_EE_SaveYes.Checked = true;
  523. }
  524. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  525. if (Flag == 0)
  526. {
  527. radioButton_SIP_SaveNo.Checked = true;
  528. radioButton_SIP_SaveYes.Checked = false;
  529. }
  530. else
  531. {
  532. radioButton_SIP_SaveNo.Checked = false;
  533. radioButton_SIP_SaveYes.Checked = true;
  534. }
  535. }));
  536. }
  537. break;
  538. }
  539. case 0x1240://电机版本信息
  540. {
  541. unchecked
  542. {
  543. this.Invoke((EventHandler)(delegate
  544. {
  545. //电机型号
  546. textBox_Model.Text = "";
  547. textBox_OBC_ReadModel.Text = "";
  548. textBox_FacModeName.Text = "";
  549. for (ushort i = 0; i < 16; i++)
  550. {
  551. if (Data[i] == 0x2E)
  552. {
  553. break;
  554. }
  555. textBox_Model.Text += ((char)Data[i]).ToString();
  556. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  557. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  558. }
  559. Class_Motor_Ver.Mode = textBox_Model.Text;
  560. //电机SN
  561. textBox_SN.Text = "";
  562. textBox_OBC_ReadSN.Text = "";
  563. textBox_FacModeNum.Text = "";
  564. for (ushort i = 0; i < 16; i++)
  565. {
  566. if (Data[16 + i] == 0x2E)
  567. {
  568. break;
  569. }
  570. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  571. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  572. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  573. }
  574. Class_Motor_Ver.SN = textBox_SN.Text;
  575. //电机HW
  576. textBox_HW.Text = "";
  577. textBox_OBC_ReadHW.Text = "";
  578. textBox_FacModeHW.Text = "";
  579. for (ushort i = 0; i < 16; i++)
  580. {
  581. if (Data[32 + i] == 0x2E)
  582. {
  583. break;
  584. }
  585. textBox_HW.Text += ((char)Data[32 + i]).ToString();
  586. textBox_OBC_ReadHW.Text += ((char)Data[32 + i]).ToString();
  587. textBox_FacModeHW.Text += ((char)Data[32 + i]).ToString();
  588. }
  589. Class_Motor_Ver.HW = textBox_HW.Text;
  590. //电机FW
  591. textBox_FW.Text = "";
  592. textBox_OBC_ReadFW.Text = "";
  593. textBox_FacModeFW.Text = "";
  594. for (ushort i = 0; i < 16; i++)
  595. {
  596. if (Data[48 + i] == 0x2E)
  597. {
  598. break;
  599. }
  600. if (Data[48 + i] == 'r')
  601. {
  602. Data[48 + i] = (byte)'.';
  603. }
  604. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  605. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  606. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  607. }
  608. Class_Motor_Ver.FW = textBox_FW.Text;
  609. }));
  610. }
  611. break;
  612. }
  613. case 0xA610://自定义1
  614. {
  615. unchecked
  616. {
  617. this.Invoke((EventHandler)(delegate
  618. {
  619. textBox_User1.Text = "";
  620. for (ushort i = 0; i < 16; i++)
  621. {
  622. if (Data[i] == 0x2E)
  623. {
  624. break;
  625. }
  626. textBox_User1.Text += ((char)Data[i]).ToString();
  627. }
  628. }));
  629. }
  630. break;
  631. }
  632. case 0xA710://自定义2
  633. {
  634. unchecked
  635. {
  636. this.Invoke((EventHandler)(delegate
  637. {
  638. textBox_User2.Text = "";
  639. for (ushort i = 0; i < 16; i++)
  640. {
  641. if (Data[i] == 0x2E)
  642. {
  643. break;
  644. }
  645. textBox_User2.Text += ((char)Data[i]).ToString();
  646. }
  647. }));
  648. }
  649. break;
  650. }
  651. case 0xA810://自定义1
  652. {
  653. unchecked
  654. {
  655. this.Invoke((EventHandler)(delegate
  656. {
  657. textBox_User3.Text = "";
  658. for (ushort i = 0; i < 16; i++)
  659. {
  660. if (Data[i] == 0x2E)
  661. {
  662. break;
  663. }
  664. textBox_User3.Text += ((char)Data[i]).ToString();
  665. }
  666. }));
  667. }
  668. break;
  669. }
  670. case 0xA520://生产信息
  671. {
  672. unchecked
  673. {
  674. this.Invoke((EventHandler)(delegate
  675. {
  676. //生产商
  677. textBox_MAC.Text = "";
  678. for (ushort i = 0; i < 8; i++)
  679. {
  680. if (Data[i] == 0x2E)
  681. {
  682. break;
  683. }
  684. textBox_MAC.Text += ((char)Data[i]).ToString();
  685. }
  686. //生产地
  687. textBox_MACAdd.Text = "";
  688. for (ushort i = 0; i < 8; i++)
  689. {
  690. if (Data[8 + i] == 0x2E)
  691. {
  692. break;
  693. }
  694. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  695. }
  696. //生产日期
  697. textBox_MACDate.Text = "";
  698. for (ushort i = 0; i < 8; i++)
  699. {
  700. if (Data[16 + i] == 0x2E)
  701. {
  702. break;
  703. }
  704. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  705. }
  706. //品牌信息
  707. textBox_PP.Text = "";
  708. for (ushort i = 0; i < 8; i++)
  709. {
  710. if (Data[24 + i] == 0x2E)
  711. {
  712. break;
  713. }
  714. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  715. }
  716. }));
  717. }
  718. break;
  719. }
  720. case 0xA408://密钥
  721. {
  722. unchecked
  723. {
  724. this.Invoke((EventHandler)(delegate
  725. {
  726. textBox_Key.Text = "";
  727. for (ushort i = 0; i < 8; i++)
  728. {
  729. textBox_Key.Text += ((char)Data[i]).ToString();
  730. }
  731. }));
  732. }
  733. break;
  734. }
  735. case 0x1401://在线检测结果
  736. {
  737. unchecked
  738. {
  739. this.Invoke((EventHandler)(delegate
  740. {
  741. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  742. }));
  743. }
  744. break;
  745. }
  746. case 0x1510://骑行历史信息
  747. {
  748. unchecked
  749. {
  750. this.Invoke((EventHandler)(delegate
  751. {
  752. long DataTemp32;
  753. //ODO里程
  754. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  755. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  756. //ODO时间
  757. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  758. if (DataTemp32 >= 60 * 100000)
  759. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  760. else
  761. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  762. //TRIP里程
  763. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  764. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  765. //TRIP时间
  766. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  767. if (DataTemp32 >= 60 * 100000)
  768. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  769. else
  770. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  771. }));
  772. }
  773. break;
  774. }
  775. case 0x1720://客户信息
  776. {
  777. unchecked
  778. {
  779. this.Invoke((EventHandler)(delegate
  780. {
  781. //程序特性
  782. textBox_SP.Text = "";
  783. textBox_OBC_ReadSP.Text = "";
  784. textBox_FacModeSP.Text = "";
  785. for (ushort i = 0; i < 32; i++)
  786. {
  787. if (Data[i] == 0x2E)
  788. {
  789. break;
  790. }
  791. textBox_SP.Text += ((char)Data[i]).ToString();
  792. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  793. textBox_FacModeSP.Text += ((char)Data[i]).ToString(); ;
  794. }
  795. Class_Motor_Ver.Special = textBox_SP.Text;
  796. }));
  797. }
  798. break;
  799. }
  800. default:
  801. {
  802. unchecked
  803. {
  804. if ((CmdTemp & 0xFF00) == 0xAB00) //返回指定地址存储器数据
  805. {
  806. this.Invoke((EventHandler)(delegate
  807. {
  808. long ByteNum = 0;
  809. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  810. for (int i = 0; i < ByteNum; i++)
  811. {
  812. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  813. }
  814. }));
  815. }
  816. }
  817. break;
  818. }
  819. }
  820. }
  821. #endregion
  822. #region 解析BMS广播的命令
  823. else if (ID == 0x720)
  824. {
  825. switch (CmdTemp)
  826. {
  827. case 0x1010://BMS运行信息
  828. {
  829. unchecked
  830. {
  831. this.Invoke((EventHandler)(delegate
  832. {
  833. BMS_RunInfo_Refresh = true;
  834. richTextBox_OBC_BMS_RunInfo.Clear();
  835. //电压
  836. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  837. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  838. //电流
  839. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  840. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  841. //剩余容量
  842. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  843. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  844. //满充容量
  845. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  846. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mV" + "\r\n");
  847. //电芯温度
  848. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  849. //剩余电量
  850. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  851. //电池状态
  852. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  853. //SOH
  854. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  855. }));
  856. }
  857. break;
  858. }
  859. default: break;
  860. }
  861. }
  862. #endregion
  863. #region 解析电机发送OBC的命令
  864. else if (ID == 0x713)
  865. {
  866. switch (CmdTemp)
  867. {
  868. case 0x5408://电机用户参数
  869. {
  870. unchecked
  871. {
  872. this.Invoke((EventHandler)(delegate
  873. {
  874. richTextBox_OBC_ReadUserInfo.Clear();
  875. //默认周长
  876. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  877. //启动模式
  878. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  879. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  880. //限速
  881. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  882. //周长微调
  883. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  884. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  885. //助力方案
  886. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  887. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  888. //关机时间
  889. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  890. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  891. }));
  892. }
  893. break;
  894. }
  895. case 0x5303://电机应答反馈
  896. {
  897. unchecked
  898. {
  899. this.Invoke((EventHandler)(delegate
  900. {
  901. timer_1s.Enabled = false;
  902. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  903. timer_1s.Enabled = true;
  904. }));
  905. }
  906. break;
  907. }
  908. default: break;
  909. }
  910. }
  911. #endregion
  912. }
  913. #endregion
  914. /// <summary>
  915. /// 端口连接事件
  916. /// </summary>
  917. /// <param name="sender"></param>
  918. /// <param name="e"></param>
  919. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  920. {
  921. bool result = false;
  922. if (连接ToolStripMenuItem.Text == "连接")
  923. {
  924. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text);
  925. if (result)
  926. {
  927. toolStripComboBox_ComNum.Enabled = false;
  928. toolStripComboBox_Baudrate.Enabled = false;
  929. 刷新ToolStripMenuItem.Enabled = false;
  930. 连接ToolStripMenuItem.Text = "断开";
  931. 连接ToolStripMenuItem.Checked = true;
  932. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  933. }
  934. }
  935. else if (连接ToolStripMenuItem.Text == "断开")
  936. {
  937. checkBox_OBC_StartSetGearSt.Checked = false;
  938. mySerialProcess.SerialClose();
  939. toolStripComboBox_ComNum.Enabled = true;
  940. toolStripComboBox_Baudrate.Enabled = true;
  941. 刷新ToolStripMenuItem.Enabled = true;
  942. 连接ToolStripMenuItem.Text = "连接";
  943. 连接ToolStripMenuItem.Checked = false;
  944. label_COM_Sta.Text = "连接状态:未连接";
  945. }
  946. }
  947. /// <summary>
  948. /// 端口号刷新事件
  949. /// </summary>
  950. /// <param name="sender"></param>
  951. /// <param name="e"></param>
  952. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  953. {
  954. toolStripComboBox_ComNum.Items.Clear();
  955. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  956. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  957. }
  958. /// <summary>
  959. /// 转速调节事件
  960. /// </summary>
  961. /// <param name="sender"></param>
  962. /// <param name="e"></param>
  963. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  964. {
  965. //生产模式转速设置值更新
  966. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  967. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  968. //设置转速百分比
  969. var Data = new byte[1];
  970. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  971. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  972. }
  973. /// <summary>
  974. /// 存储标志修改事件
  975. /// </summary>
  976. /// <param name="sender"></param>
  977. /// <param name="e"></param>
  978. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  979. {
  980. 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
  981. }
  982. /// <summary>
  983. /// 1s定时器
  984. /// </summary>
  985. /// <param name="sender"></param>
  986. /// <param name="e"></param>
  987. private void timer_1s_Tick(object sender, EventArgs e)
  988. {
  989. //时间更新
  990. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString();
  991. //MC_Runinfo超时清除
  992. if (MC_RunInfo_Refresh == false)
  993. {
  994. MC_RunInfo_Refresh_Cnt++;
  995. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  996. {
  997. MC_RunInfo_Clear();
  998. MC_RunInfo_Refresh_Cnt = 0;
  999. }
  1000. }
  1001. else
  1002. {
  1003. MC_RunInfo_Refresh_Cnt = 0;
  1004. }
  1005. MC_RunInfo_Refresh = false;
  1006. //BMS_RunInfo超时清除
  1007. if (BMS_RunInfo_Refresh == false)
  1008. {
  1009. BMS_RunInfo_Refresh_Cnt++;
  1010. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  1011. {
  1012. richTextBox_OBC_BMS_RunInfo.Clear();
  1013. BMS_RunInfo_Refresh_Cnt = 0;
  1014. }
  1015. }
  1016. else
  1017. {
  1018. BMS_RunInfo_Refresh_Cnt = 0;
  1019. }
  1020. BMS_RunInfo_Refresh = false;
  1021. //故障码超时清除
  1022. if (MC_ErrorCode_Refresh == false)
  1023. {
  1024. MC_ErrorCode_Refresh_Cnt++;
  1025. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  1026. {
  1027. textBox_ErrorCode.Text = "---";
  1028. MC_ErrorCode_Refresh_Cnt = 0;
  1029. }
  1030. }
  1031. else
  1032. {
  1033. MC_ErrorCode_Refresh_Cnt = 0;
  1034. }
  1035. MC_ErrorCode_Refresh = false;
  1036. //CDL连接超时
  1037. #if false
  1038. if (mySerialProcess.CDL_Online_Flag == false)
  1039. {
  1040. mySerialProcess.CDL_OnlineCheck_Cnt++;
  1041. if (mySerialProcess.CDL_OnlineCheck_Cnt > 3)//3s
  1042. {
  1043. timer_1s.Enabled = false;
  1044. MessageBox.Show("连接失败!", "提示");
  1045. timer_1s.Enabled = true;
  1046. //关闭串口
  1047. mySerialProcess.SerialClose();
  1048. toolStripComboBox_ComNum.Enabled = true;
  1049. toolStripComboBox_Baudrate.Enabled = true;
  1050. 刷新ToolStripMenuItem.Enabled = true;
  1051. 连接ToolStripMenuItem.Text = "连接";
  1052. 连接ToolStripMenuItem.Checked = false;
  1053. label_COM_Sta.Text = "连接状态:未连接";
  1054. }
  1055. }
  1056. #endif
  1057. //OBC定时发送设置档位
  1058. if (checkBox_OBC_StartSetGearSt.Checked == true)
  1059. {
  1060. var CtrlCode = new byte[2];
  1061. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  1062. CtrlCode[0] = 0x33;
  1063. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  1064. CtrlCode[0] = 0x22;
  1065. else
  1066. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  1067. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  1068. CtrlCode[1] = 0xF1;
  1069. else
  1070. CtrlCode[1] = 0xF0;
  1071. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  1072. {
  1073. checkBox_OBC_StartSetGearSt.Checked = false;
  1074. }
  1075. }
  1076. //OBC定时发送查询电池
  1077. if (checkBox_OBC_StartReadBMS.Checked == true)
  1078. {
  1079. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  1080. {
  1081. checkBox_OBC_StartReadBMS.Checked = false;
  1082. }
  1083. }
  1084. }
  1085. /// <summary>
  1086. /// 运行信息清除
  1087. /// </summary>
  1088. private void MC_RunInfo_Clear()
  1089. {
  1090. foreach (Control c in groupBox2.Controls)
  1091. {
  1092. if ((c is TextBox))
  1093. {
  1094. if(c.Name != textBox_ErrorCode.ToString())
  1095. c.Text = "---";
  1096. }
  1097. }
  1098. }
  1099. /// <summary>
  1100. /// 读取马达参数
  1101. /// </summary>
  1102. /// <param name="sender"></param>
  1103. /// <param name="e"></param>
  1104. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  1105. {
  1106. richTextBox_MotorParam.Clear();
  1107. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  1108. }
  1109. /// <summary>
  1110. /// 写入马达参数
  1111. /// </summary>
  1112. /// <param name="sender"></param>
  1113. /// <param name="e"></param>
  1114. private void button_Write_Click(object sender, EventArgs e)
  1115. {
  1116. var ConfigParam = new byte[40];
  1117. for (int i = 0; i < 40; i++)
  1118. ConfigParam[i] = 0;
  1119. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1120. ushort uwDataTemp = 0;
  1121. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
  1122. try
  1123. {
  1124. for (int i = 0; i < strDataTemp.Length; i++)
  1125. {
  1126. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1127. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1128. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1129. }
  1130. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  1131. }
  1132. catch (Exception)
  1133. {
  1134. timer_1s.Enabled = false;
  1135. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1136. timer_1s.Enabled = true;
  1137. }
  1138. }
  1139. /// <summary>
  1140. /// 读取整车信息
  1141. /// </summary>
  1142. /// <param name="sender"></param>
  1143. /// <param name="e"></param>
  1144. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  1145. {
  1146. richTextBox_BikeParam.Clear();
  1147. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  1148. }
  1149. /// <summary>
  1150. /// 写入整车信息
  1151. /// </summary>
  1152. /// <param name="sender"></param>
  1153. /// <param name="e"></param>
  1154. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  1155. {
  1156. var ConfigParam = new byte[28];
  1157. for (int i = 0; i < 28; i++)
  1158. ConfigParam[i] = 0;
  1159. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1160. ushort uwDataTemp = 0;
  1161. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1162. try
  1163. {
  1164. for (int i = 0; i < strDataTemp.Length; i++)
  1165. {
  1166. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1167. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1168. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1169. }
  1170. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  1171. }
  1172. catch (Exception)
  1173. {
  1174. timer_1s.Enabled = false;
  1175. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1176. timer_1s.Enabled = true;
  1177. }
  1178. }
  1179. /// <summary>
  1180. /// 读取控制器参数
  1181. /// </summary>
  1182. /// <param name="sender"></param>
  1183. /// <param name="e"></param>
  1184. private void button_ReadControlParam_Click(object sender, EventArgs e)
  1185. {
  1186. richTextBox_ControlParam.Clear();
  1187. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  1188. }
  1189. /// <summary>
  1190. /// 写入控制器参数
  1191. /// </summary>
  1192. /// <param name="sender"></param>
  1193. /// <param name="e"></param>
  1194. private void button_WriteControlParam_Click(object sender, EventArgs e)
  1195. {
  1196. var ConfigParam = new byte[34];
  1197. for (int i = 0; i < 34; i++)
  1198. ConfigParam[i] = 0;
  1199. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1200. ushort uwDataTemp = 0;
  1201. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1202. try
  1203. {
  1204. for (int i = 0; i < strDataTemp.Length; i++)
  1205. {
  1206. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1207. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1208. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1209. }
  1210. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  1211. }
  1212. catch (Exception)
  1213. {
  1214. timer_1s.Enabled = false;
  1215. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1216. timer_1s.Enabled = true;
  1217. }
  1218. }
  1219. /// <summary>
  1220. /// 读取助力参数
  1221. /// </summary>
  1222. /// <param name="sender"></param>
  1223. /// <param name="e"></param>
  1224. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  1225. {
  1226. var ConfigParam = new byte[4];
  1227. int AssistNum = 0;
  1228. try
  1229. {
  1230. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  1231. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  1232. ConfigParam[1] = (byte)(AssistNum >> 8);
  1233. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  1234. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  1235. ConfigParam[3] = (byte)(AssistNum >> 8);
  1236. richTextBox_AssistParam.Clear();
  1237. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  1238. }
  1239. catch (Exception)
  1240. {
  1241. timer_1s.Enabled = false;
  1242. MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  1243. timer_1s.Enabled = true;
  1244. }
  1245. }
  1246. /// <summary>
  1247. /// 写入助力参数
  1248. /// </summary>
  1249. /// <param name="sender"></param>
  1250. /// <param name="e"></param>
  1251. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  1252. {
  1253. var ConfigParam = new byte[80];
  1254. for (int i = 0; i < 80; i++)
  1255. ConfigParam[i] = 0;
  1256. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1257. ulong ulDataTemp = 0;
  1258. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1259. int index_1 = 0, index_2 = 0;
  1260. try
  1261. {
  1262. for (int i = 0; i < strDataTemp.Length; i++)
  1263. {
  1264. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  1265. {
  1266. index_1 = i;
  1267. break;
  1268. }
  1269. }
  1270. for (int i = 0; i < strDataTemp.Length; i++)
  1271. {
  1272. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  1273. {
  1274. index_2 = i;
  1275. break;
  1276. }
  1277. }
  1278. for (int i = 0; i < strDataTemp.Length; i++)
  1279. {
  1280. ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
  1281. if (i < index_1)
  1282. {
  1283. ConfigParam[2 * i + 4] = (byte)ulDataTemp;
  1284. ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
  1285. }
  1286. else if (i <= index_2)
  1287. {
  1288. ConfigParam[4 * i - 4] = (byte)ulDataTemp;
  1289. ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
  1290. ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
  1291. ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
  1292. }
  1293. else
  1294. {
  1295. ConfigParam[2 * i + 20] = (byte)ulDataTemp;
  1296. ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
  1297. }
  1298. }
  1299. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  1300. }
  1301. catch (Exception)
  1302. {
  1303. timer_1s.Enabled = false;
  1304. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1305. timer_1s.Enabled = true;
  1306. }
  1307. }
  1308. /// <summary>
  1309. /// 读取调试参数
  1310. /// </summary>
  1311. /// <param name="sender"></param>
  1312. /// <param name="e"></param>
  1313. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  1314. {
  1315. richTextBox_DebugParam.Clear();
  1316. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  1317. }
  1318. /// <summary>
  1319. /// 写入调试参数
  1320. /// </summary>
  1321. /// <param name="sender"></param>
  1322. /// <param name="e"></param>
  1323. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  1324. {
  1325. var ConfigParam = new byte[60];
  1326. for (int i = 0; i < 60; i++)
  1327. ConfigParam[i] = 0;
  1328. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1329. ushort uwDataTemp = 0;
  1330. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1331. try
  1332. {
  1333. for (int i = 0; i < strDataTemp.Length; i++)
  1334. {
  1335. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1336. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1337. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1338. }
  1339. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  1340. }
  1341. catch (Exception)
  1342. {
  1343. timer_1s.Enabled = false;
  1344. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1345. timer_1s.Enabled = true;
  1346. }
  1347. }
  1348. /// <summary>
  1349. /// 读取历史
  1350. /// </summary>
  1351. /// <param name="sender"></param>
  1352. /// <param name="e"></param>
  1353. private void button_ReadRecord_Click(object sender, EventArgs e)
  1354. {
  1355. richTextBox_Record.Clear();
  1356. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  1357. }
  1358. /// <summary>
  1359. /// 读取传感器参数
  1360. /// </summary>
  1361. /// <param name="sender"></param>
  1362. /// <param name="e"></param>
  1363. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  1364. {
  1365. richTextBox_SensorParam.Clear();
  1366. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  1367. }
  1368. /// <summary>
  1369. /// 写入力矩传感器标定值
  1370. /// </summary>
  1371. /// <param name="sender"></param>
  1372. /// <param name="e"></param>
  1373. private void button_Write_Cal_Click(object sender, EventArgs e)
  1374. {
  1375. var ConfigParam = new byte[4];
  1376. for (int i = 0; i < 4; i++)
  1377. ConfigParam[i] = 0;
  1378. ushort uwDataTemp = 0;
  1379. try
  1380. {
  1381. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  1382. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  1383. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  1384. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  1385. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  1386. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  1387. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  1388. }
  1389. catch (Exception)
  1390. {
  1391. timer_1s.Enabled = false;
  1392. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1393. timer_1s.Enabled = true;
  1394. }
  1395. }
  1396. /// <summary>
  1397. /// 写入传感器参数
  1398. /// </summary>
  1399. /// <param name="sender"></param>
  1400. /// <param name="e"></param>
  1401. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  1402. {
  1403. var ConfigParam = new byte[14];
  1404. for (int i = 0; i < 14; i++)
  1405. ConfigParam[i] = 0;
  1406. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1407. ushort uwDataTemp = 0;
  1408. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  1409. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1410. int index = 0;
  1411. try
  1412. {
  1413. for (int i = 0; i < strDataTemp.Length; i++)
  1414. {
  1415. if (strDataTemp[i].Split('=')[0] == "踏频传感器一圈脉冲数")
  1416. {
  1417. index = i;
  1418. break;
  1419. }
  1420. }
  1421. for (int i = 0; i < (strDataTemp.Length - index); i++)
  1422. {
  1423. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  1424. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1425. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1426. }
  1427. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  1428. }
  1429. catch (Exception)
  1430. {
  1431. timer_1s.Enabled = false;
  1432. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1433. timer_1s.Enabled = true;
  1434. }
  1435. }
  1436. /// <summary>
  1437. /// 写入型号
  1438. /// </summary>
  1439. /// <param name="sender"></param>
  1440. /// <param name="e"></param>
  1441. private void button_WriteModel_Click(object sender, EventArgs e)
  1442. {
  1443. string Mode = textBox_Model.Text;
  1444. var ModeArray = new byte[16];
  1445. for (ushort i = 0; i < Mode.Length; i++)
  1446. {
  1447. ModeArray[i] = (byte)Mode[i];
  1448. }
  1449. if (Mode.Length < 16)
  1450. {
  1451. ModeArray[Mode.Length] = (byte)'.';
  1452. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  1453. {
  1454. ModeArray[Mode.Length + 1 + i] = 0x20;
  1455. }
  1456. }
  1457. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  1458. }
  1459. /// <summary>
  1460. /// 写入SN
  1461. /// </summary>
  1462. /// <param name="sender"></param>
  1463. /// <param name="e"></param>
  1464. private void button_WriteSN_Click(object sender, EventArgs e)
  1465. {
  1466. string SN = textBox_SN.Text;
  1467. var SNArray = new byte[16];
  1468. for (ushort i = 0; i < SN.Length; i++)
  1469. {
  1470. SNArray[i] = (byte)SN[i];
  1471. }
  1472. if (SN.Length < 16)
  1473. {
  1474. SNArray[SN.Length] = (byte)'.';
  1475. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  1476. {
  1477. SNArray[SN.Length + 1 + i] = 0x20;
  1478. }
  1479. }
  1480. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  1481. }
  1482. /// <summary>
  1483. /// 查询版本信息
  1484. /// </summary>
  1485. /// <param name="sender"></param>
  1486. /// <param name="e"></param>
  1487. private void button_ReadVersion_Click(object sender, EventArgs e)
  1488. {
  1489. textBox_Model.Text = "---";
  1490. textBox_SN.Text = "---";
  1491. textBox_HW.Text = "---";
  1492. textBox_FW.Text = "---";
  1493. textBox_SP.Text = "---";
  1494. textBox_OBC_ReadModel.Text = "---";
  1495. textBox_OBC_ReadSN.Text = "---";
  1496. textBox_OBC_ReadHW.Text = "---";
  1497. textBox_OBC_ReadFW.Text = "---";
  1498. textBox_OBC_ReadSP.Text = "---";
  1499. textBox_FacModeName.Text = "---";
  1500. textBox_FacModeNum.Text = "---";
  1501. textBox_FacModeHW.Text = "---";
  1502. textBox_FacModeFW.Text = "---";
  1503. textBox_FacModeSP.Text = "---";
  1504. Class_Motor_Ver.Mode = "---";
  1505. Class_Motor_Ver.SN = "---";
  1506. Class_Motor_Ver.HW = "---";
  1507. Class_Motor_Ver.FW = "---";
  1508. Class_Motor_Ver.Special = "---";
  1509. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  1510. }
  1511. /// <summary>
  1512. /// 查询自定义1
  1513. /// </summary>
  1514. /// <param name="sender"></param>
  1515. /// <param name="e"></param>
  1516. private void button_ReadUser1_Click(object sender, EventArgs e)
  1517. {
  1518. textBox_User1.Text = "---";
  1519. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  1520. }
  1521. /// <summary>
  1522. /// 查询自定义2
  1523. /// </summary>
  1524. /// <param name="sender"></param>
  1525. /// <param name="e"></param>
  1526. private void button_ReadUser2_Click(object sender, EventArgs e)
  1527. {
  1528. textBox_User2.Text = "---";
  1529. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  1530. }
  1531. /// <summary>
  1532. /// 查询自定义3
  1533. /// </summary>
  1534. /// <param name="sender"></param>
  1535. /// <param name="e"></param>
  1536. private void button_ReadUser3_Click(object sender, EventArgs e)
  1537. {
  1538. textBox_User3.Text = "---";
  1539. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  1540. }
  1541. /// <summary>
  1542. /// 写入自定义字符串1
  1543. /// </summary>
  1544. /// <param name="sender"></param>
  1545. /// <param name="e"></param>
  1546. private void button_WriteUser1_Click(object sender, EventArgs e)
  1547. {
  1548. string User = textBox_User1.Text;
  1549. var UserArray = new byte[16];
  1550. for (ushort i = 0; i < User.Length; i++)
  1551. {
  1552. UserArray[i] = (byte)User[i];
  1553. }
  1554. if (User.Length < 16)
  1555. {
  1556. UserArray[User.Length] = (byte)'.';
  1557. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1558. {
  1559. UserArray[User.Length + 1 + i] = 0x20;
  1560. }
  1561. }
  1562. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  1563. }
  1564. /// <summary>
  1565. /// 写入自定义字符串2
  1566. /// </summary>
  1567. /// <param name="sender"></param>
  1568. /// <param name="e"></param>
  1569. private void button_WriteUser2_Click(object sender, EventArgs e)
  1570. {
  1571. string User = textBox_User2.Text;
  1572. var UserArray = new byte[16];
  1573. for (ushort i = 0; i < User.Length; i++)
  1574. {
  1575. UserArray[i] = (byte)User[i];
  1576. }
  1577. if (User.Length < 16)
  1578. {
  1579. UserArray[User.Length] = (byte)'.';
  1580. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1581. {
  1582. UserArray[User.Length + 1 + i] = 0x20;
  1583. }
  1584. }
  1585. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  1586. }
  1587. /// <summary>
  1588. /// 写入自定义字符串3
  1589. /// </summary>
  1590. /// <param name="sender"></param>
  1591. /// <param name="e"></param>
  1592. private void button_WriteUser3_Click(object sender, EventArgs e)
  1593. {
  1594. string User = textBox_User3.Text;
  1595. var UserArray = new byte[16];
  1596. for (ushort i = 0; i < User.Length; i++)
  1597. {
  1598. UserArray[i] = (byte)User[i];
  1599. }
  1600. if (User.Length < 16)
  1601. {
  1602. UserArray[User.Length] = (byte)'.';
  1603. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1604. {
  1605. UserArray[User.Length + 1 + i] = 0x20;
  1606. }
  1607. }
  1608. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  1609. }
  1610. /// <summary>
  1611. /// 查询生产信息
  1612. /// </summary>
  1613. /// <param name="sender"></param>
  1614. /// <param name="e"></param>
  1615. private void button_ReadMAC_Click(object sender, EventArgs e)
  1616. {
  1617. textBox_MAC.Text = "---";
  1618. textBox_MACAdd.Text = "---";
  1619. textBox_MACDate.Text = "---";
  1620. textBox_PP.Text = "---";
  1621. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  1622. }
  1623. /// <summary>
  1624. /// 写入生产信息
  1625. /// </summary>
  1626. /// <param name="sender"></param>
  1627. /// <param name="e"></param>
  1628. private void button_WriteMac_Click(object sender, EventArgs e)
  1629. {
  1630. var MACArray = new byte[32];
  1631. //填入生产商
  1632. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  1633. {
  1634. MACArray[i] = (byte)textBox_MAC.Text[i];
  1635. }
  1636. if (textBox_MAC.Text.Length < 8)
  1637. {
  1638. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  1639. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  1640. {
  1641. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  1642. }
  1643. }
  1644. //填入生产地
  1645. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  1646. {
  1647. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  1648. }
  1649. if (textBox_MACAdd.Text.Length < 8)
  1650. {
  1651. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  1652. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  1653. {
  1654. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  1655. }
  1656. }
  1657. //填入生产日期
  1658. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  1659. {
  1660. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  1661. }
  1662. if (textBox_MACDate.Text.Length < 8)
  1663. {
  1664. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  1665. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  1666. {
  1667. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  1668. }
  1669. }
  1670. //填入品牌
  1671. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  1672. {
  1673. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  1674. }
  1675. if (textBox_PP.Text.Length < 8)
  1676. {
  1677. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  1678. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  1679. {
  1680. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  1681. }
  1682. }
  1683. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  1684. }
  1685. /// <summary>
  1686. /// 查询密钥
  1687. /// </summary>
  1688. /// <param name="sender"></param>
  1689. /// <param name="e"></param>
  1690. private void button_ReadKey_Click(object sender, EventArgs e)
  1691. {
  1692. textBox_Key.Text = "---";
  1693. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  1694. }
  1695. /// <summary>
  1696. /// 写入校验密钥
  1697. /// </summary>
  1698. /// <param name="sender"></param>
  1699. /// <param name="e"></param>
  1700. private void button_WriteKey_Click(object sender, EventArgs e)
  1701. {
  1702. string Key = textBox_Key.Text;
  1703. var KeyArray = new byte[8];
  1704. if (Key.Length != 8)
  1705. {
  1706. timer_1s.Enabled = false;
  1707. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1708. timer_1s.Enabled = true;
  1709. return;
  1710. }
  1711. for (ushort i = 0; i < Key.Length; i++)
  1712. {
  1713. KeyArray[i] = (byte)Key[i];
  1714. }
  1715. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  1716. }
  1717. /// <summary>
  1718. /// 查询在线检测结果
  1719. /// </summary>
  1720. /// <param name="sender"></param>
  1721. /// <param name="e"></param>
  1722. private void button_ReadOnLine_Click(object sender, EventArgs e)
  1723. {
  1724. textBox_Online.Text = "---";
  1725. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  1726. }
  1727. /// <summary>
  1728. /// 系统清除
  1729. /// </summary>
  1730. /// <param name="sender"></param>
  1731. /// <param name="e"></param>
  1732. private void button_SystemClear_Click(object sender, EventArgs e)
  1733. {
  1734. var Code = new byte[5];
  1735. Code[0] = (byte)'C';
  1736. Code[1] = (byte)'L';
  1737. Code[2] = (byte)'E';
  1738. Code[3] = (byte)'A';
  1739. Code[4] = (byte)'R';
  1740. timer_1s.Enabled = false;
  1741. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1742. {
  1743. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1744. {
  1745. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1746. {
  1747. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  1748. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1749. }
  1750. }
  1751. }
  1752. timer_1s.Enabled = true;
  1753. }
  1754. /// <summary>
  1755. /// 参数还原
  1756. /// </summary>
  1757. /// <param name="sender"></param>
  1758. /// <param name="e"></param>
  1759. private void button_Recovery_Click(object sender, EventArgs e)
  1760. {
  1761. var Code = new byte[8];
  1762. Code[0] = (byte)'R';
  1763. Code[1] = (byte)'E';
  1764. Code[2] = (byte)'C';
  1765. Code[3] = (byte)'O';
  1766. Code[4] = (byte)'V';
  1767. Code[5] = (byte)'E';
  1768. Code[6] = (byte)'R';
  1769. Code[7] = (byte)'Y';
  1770. timer_1s.Enabled = false;
  1771. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1772. {
  1773. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1774. {
  1775. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1776. {
  1777. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  1778. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1779. }
  1780. }
  1781. }
  1782. timer_1s.Enabled = true;
  1783. }
  1784. /// <summary>
  1785. /// 系统复位
  1786. /// </summary>
  1787. /// <param name="sender"></param>
  1788. /// <param name="e"></param>
  1789. private void button_Reset_Click(object sender, EventArgs e)
  1790. {
  1791. var Code = new byte[5];
  1792. Code[0] = (byte)'O';
  1793. Code[1] = (byte)'F';
  1794. Code[2] = (byte)'F';
  1795. Code[3] = (byte)'.';
  1796. Code[4] = (byte)'.';
  1797. timer_1s.Enabled = false;
  1798. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1799. {
  1800. timer_1s.Enabled = true;
  1801. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  1802. PowerOffAckStatus = false;
  1803. Delay_ms(250);
  1804. int TryCnt = 3;
  1805. while ((TryCnt--) >= 0)
  1806. {
  1807. if (!PowerOffAckStatus)
  1808. {
  1809. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  1810. PowerOffAckStatus = false;
  1811. Delay_ms(250);
  1812. }
  1813. else break;
  1814. }
  1815. if (PowerOffAckStatus)
  1816. {
  1817. timer_1s.Enabled = false;
  1818. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  1819. timer_1s.Enabled = true;
  1820. }
  1821. else
  1822. {
  1823. timer_1s.Enabled = false;
  1824. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1825. timer_1s.Enabled = true;
  1826. }
  1827. }
  1828. timer_1s.Enabled = true;
  1829. }
  1830. /// <summary>
  1831. /// 记录清除
  1832. /// </summary>
  1833. /// <param name="sender"></param>
  1834. /// <param name="e"></param>
  1835. private void button_ClearLog_Click(object sender, EventArgs e)
  1836. {
  1837. var Code = new byte[9];
  1838. Code[0] = (byte)'L';
  1839. Code[1] = (byte)'O';
  1840. Code[2] = (byte)'G';
  1841. Code[3] = (byte)' ';
  1842. Code[4] = (byte)'C';
  1843. Code[5] = (byte)'L';
  1844. Code[6] = (byte)'E';
  1845. Code[7] = (byte)'A';
  1846. Code[8] = (byte)'R';
  1847. timer_1s.Enabled = false;
  1848. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1849. {
  1850. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1851. {
  1852. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1853. {
  1854. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  1855. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1856. }
  1857. }
  1858. }
  1859. timer_1s.Enabled = true;
  1860. }
  1861. /// <summary>
  1862. /// 打开系统计算器
  1863. /// </summary>
  1864. /// <param name="sender"></param>
  1865. /// <param name="e"></param>
  1866. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  1867. {
  1868. System.Diagnostics.Process.Start("calc.exe");
  1869. }
  1870. /// <summary>
  1871. ///故障转换和显示
  1872. /// </summary>
  1873. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  1874. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  1875. "",""};
  1876. private string ErrorInfoDisplay(UInt32 Code)
  1877. {
  1878. string Result = "";
  1879. if (Code == 0)
  1880. {
  1881. Result = "无故障";
  1882. }
  1883. else
  1884. {
  1885. for (int i = 0; i < 32; i++)
  1886. {
  1887. if ((Code & 0x01) == 0x01)
  1888. {
  1889. Result += ErrorInfo[i] + " ";
  1890. }
  1891. Code >>= 1;
  1892. }
  1893. }
  1894. return Result;
  1895. }
  1896. /// <summary>
  1897. /// 鼠标滑过故障码显示具体内容
  1898. /// </summary>
  1899. /// <param name="sender"></param>
  1900. /// <param name="e"></param>
  1901. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  1902. {
  1903. // 创建the ToolTip
  1904. ToolTip toolTip1 = new ToolTip();
  1905. // 设置显示样式
  1906. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  1907. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  1908. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  1909. toolTip1.ShowAlways = true;//是否显示提示框
  1910. // 设置伴随的对象.
  1911. string ErrorCode = this.textBox_ErrorCode.Text;
  1912. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  1913. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  1914. }
  1915. /// <summary>
  1916. /// 数据记录
  1917. /// </summary>
  1918. private void DataAutoSave()
  1919. {
  1920. if (记录数据ToolStripMenuItem.Checked == true)
  1921. {
  1922. if (SaveFilename == string.Empty)
  1923. {
  1924. return;
  1925. }
  1926. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_") + " ";
  1927. foreach (Control c in groupBox3.Controls)
  1928. {
  1929. if (c is TextBox)
  1930. {
  1931. SaveData += c.Text + " , ";
  1932. }
  1933. }
  1934. SaveData += "\r\n";
  1935. System.IO.File.AppendAllText(SaveFilename, SaveData);//sb.ToString());
  1936. }
  1937. }
  1938. /// <summary>
  1939. /// 打开或关闭数据记录
  1940. /// </summary>
  1941. /// <param name="sender"></param>
  1942. /// <param name="e"></param>
  1943. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  1944. {
  1945. if (记录数据ToolStripMenuItem.Checked == false)
  1946. {
  1947. if (mySerialProcess.mySerial.IsOpen == true)
  1948. {
  1949. SaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  1950. timer_1s.Enabled = false;
  1951. MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1952. timer_1s.Enabled = true;
  1953. 记录数据ToolStripMenuItem.Checked = true;
  1954. }
  1955. else
  1956. {
  1957. timer_1s.Enabled = false;
  1958. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1959. timer_1s.Enabled = true;
  1960. }
  1961. }
  1962. else
  1963. {
  1964. 记录数据ToolStripMenuItem.Checked = false;
  1965. timer_1s.Enabled = false;
  1966. MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1967. timer_1s.Enabled = true;
  1968. }
  1969. }
  1970. /// <summary>
  1971. /// 仪表启动控制档位开关事件
  1972. /// </summary>
  1973. /// <param name="sender"></param>
  1974. /// <param name="e"></param>
  1975. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  1976. {
  1977. if (checkBox_OBC_StartSetGearSt.Checked == true)
  1978. {
  1979. //检查串口是否打开
  1980. if (!mySerialProcess.mySerial.IsOpen)
  1981. {
  1982. timer_1s.Enabled = false;
  1983. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1984. timer_1s.Enabled = true;
  1985. checkBox_OBC_StartSetGearSt.Checked = false;
  1986. return;
  1987. }
  1988. //检查是否选择档位和打开车灯
  1989. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  1990. {
  1991. timer_1s.Enabled = false;
  1992. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1993. timer_1s.Enabled = true;
  1994. checkBox_OBC_StartSetGearSt.Checked = false;
  1995. return;
  1996. }
  1997. }
  1998. }
  1999. /// <summary>
  2000. /// OBC查询电机用户参数
  2001. /// </summary>
  2002. /// <param name="sender"></param>
  2003. /// <param name="e"></param>
  2004. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  2005. {
  2006. richTextBox_OBC_ReadUserInfo.Clear();
  2007. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  2008. }
  2009. /// <summary>
  2010. /// OBC设置电机用户参数
  2011. /// </summary>
  2012. /// <param name="sender"></param>
  2013. /// <param name="e"></param>
  2014. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  2015. {
  2016. var UserInfoCode = new byte[8];
  2017. for (int i = 0; i < UserInfoCode.Length; i++)
  2018. UserInfoCode[i] = 0;
  2019. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  2020. {
  2021. timer_1s.Enabled = false;
  2022. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2023. timer_1s.Enabled = true;
  2024. return;
  2025. }
  2026. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  2027. {
  2028. timer_1s.Enabled = false;
  2029. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2030. timer_1s.Enabled = true;
  2031. return;
  2032. }
  2033. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  2034. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  2035. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  2036. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  2037. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  2038. }
  2039. /// <summary>
  2040. /// OBC查询电机版本信息
  2041. /// </summary>
  2042. /// <param name="sender"></param>
  2043. /// <param name="e"></param>
  2044. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  2045. {
  2046. textBox_Model.Text = "---";
  2047. textBox_SN.Text = "---";
  2048. textBox_HW.Text = "---";
  2049. textBox_FW.Text = "---";
  2050. textBox_SP.Text = "---";
  2051. textBox_OBC_ReadModel.Text = "---";
  2052. textBox_OBC_ReadSN.Text = "---";
  2053. textBox_OBC_ReadHW.Text = "---";
  2054. textBox_OBC_ReadFW.Text = "---";
  2055. textBox_OBC_ReadSP.Text = "---";
  2056. textBox_FacModeName.Text = "---";
  2057. textBox_FacModeNum.Text = "---";
  2058. textBox_FacModeHW.Text = "---";
  2059. textBox_FacModeFW.Text = "---";
  2060. textBox_FacModeSP.Text = "---";
  2061. Class_Motor_Ver.Mode = "---";
  2062. Class_Motor_Ver.SN = "---";
  2063. Class_Motor_Ver.HW = "---";
  2064. Class_Motor_Ver.FW = "---";
  2065. Class_Motor_Ver.Special = "---";
  2066. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  2067. }
  2068. /// <summary>
  2069. /// OBC读取骑行历史
  2070. /// </summary>
  2071. /// <param name="sender"></param>
  2072. /// <param name="e"></param>
  2073. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  2074. {
  2075. textBox_OBC_TRIP_KM.Text = "";
  2076. textBox_OBC_TRIP_TIME.Text = "";
  2077. textBox_OBC_ODO_KM.Text = "";
  2078. textBox_OBC_ODO_TIME.Text = "";
  2079. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  2080. }
  2081. /// <summary>
  2082. /// OBC清除TRIP里程
  2083. /// </summary>
  2084. /// <param name="sender"></param>
  2085. /// <param name="e"></param>
  2086. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  2087. {
  2088. var Code = new byte[5];
  2089. Code[0] = (byte)'C';
  2090. Code[1] = (byte)'L';
  2091. Code[2] = (byte)'E';
  2092. Code[3] = (byte)'A';
  2093. Code[4] = (byte)'R';
  2094. timer_1s.Enabled = false;
  2095. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2096. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  2097. timer_1s.Enabled = true;
  2098. }
  2099. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  2100. {
  2101. if (checkBox_OBC_StartReadBMS.Checked == true)
  2102. {
  2103. //检查串口是否打开
  2104. if (!mySerialProcess.mySerial.IsOpen)
  2105. {
  2106. timer_1s.Enabled = false;
  2107. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2108. timer_1s.Enabled = true;
  2109. checkBox_OBC_StartReadBMS.Checked = false;
  2110. return;
  2111. }
  2112. }
  2113. }
  2114. /// <summary>
  2115. /// 写入力矩传感器参数
  2116. /// </summary>
  2117. /// <param name="sender"></param>
  2118. /// <param name="e"></param>
  2119. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  2120. {
  2121. var ConfigParam = new byte[46];
  2122. for (int i = 0; i < 14; i++)
  2123. ConfigParam[i] = 0;
  2124. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2125. ushort uwDataTemp = 0;
  2126. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2127. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2128. int index = 0;
  2129. try
  2130. {
  2131. for (int i = 0; i < strDataTemp.Length; i++)
  2132. {
  2133. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  2134. {
  2135. index = i;
  2136. break;
  2137. }
  2138. }
  2139. for (int i = 0; i < (index + 1); i++)
  2140. {
  2141. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2142. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2143. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2144. }
  2145. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  2146. }
  2147. catch (Exception)
  2148. {
  2149. timer_1s.Enabled = false;
  2150. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2151. timer_1s.Enabled = true;
  2152. }
  2153. }
  2154. /// <summary>
  2155. /// 查询存储标志
  2156. /// </summary>
  2157. /// <param name="sender"></param>
  2158. /// <param name="e"></param>
  2159. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  2160. {
  2161. radioButton_EE_SaveYes.Checked = false;
  2162. radioButton_EE_SaveNo.Checked = false;
  2163. radioButton_SIP_SaveYes.Checked = false;
  2164. radioButton_SIP_SaveNo.Checked = false;
  2165. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  2166. }
  2167. /// <summary>
  2168. /// 写入存储标志
  2169. /// </summary>
  2170. /// <param name="sender"></param>
  2171. /// <param name="e"></param>
  2172. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  2173. {
  2174. var SaveFlag = new byte[6];
  2175. for (int i = 0; i < 6; i++)
  2176. SaveFlag[i] = 0;
  2177. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  2178. {
  2179. timer_1s.Enabled = false;
  2180. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2181. timer_1s.Enabled = true;
  2182. return;
  2183. }
  2184. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  2185. {
  2186. timer_1s.Enabled = false;
  2187. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2188. timer_1s.Enabled = true;
  2189. return;
  2190. }
  2191. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  2192. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  2193. SaveFlag[3] = 0;
  2194. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  2195. SaveFlag[5] = 0;
  2196. timer_1s.Enabled = false;
  2197. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2198. {
  2199. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  2200. }
  2201. timer_1s.Enabled = true;
  2202. }
  2203. /// <summary>
  2204. /// 读取指定地址数据
  2205. /// </summary>
  2206. /// <param name="sender"></param>
  2207. /// <param name="e"></param>
  2208. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  2209. {
  2210. var Address = new byte[4];
  2211. UInt32 Address_Begin;
  2212. UInt32 Addres_End;
  2213. richTextBox_RamFlasgData.Clear();
  2214. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2215. {
  2216. timer_1s.Enabled = false;
  2217. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2218. timer_1s.Enabled = true;
  2219. return;
  2220. }
  2221. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2222. {
  2223. timer_1s.Enabled = false;
  2224. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2225. timer_1s.Enabled = true;
  2226. return;
  2227. }
  2228. else
  2229. {
  2230. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2231. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2232. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2233. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2234. if (Addres_End < Address_Begin)
  2235. {
  2236. timer_1s.Enabled = false;
  2237. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2238. timer_1s.Enabled = true;
  2239. return;
  2240. }
  2241. else
  2242. {
  2243. var SendByte = new byte[8];
  2244. SendByte[0] = (byte)(Address_Begin >> 24);
  2245. SendByte[1] = (byte)(Address_Begin >> 16);
  2246. SendByte[2] = (byte)(Address_Begin >> 8);
  2247. SendByte[3] = (byte)(Address_Begin);
  2248. SendByte[4] = (byte)(Addres_End >> 24);
  2249. SendByte[5] = (byte)(Addres_End >> 16);
  2250. SendByte[6] = (byte)(Addres_End >> 8);
  2251. SendByte[7] = (byte)(Addres_End);
  2252. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  2253. }
  2254. }
  2255. }
  2256. /// <summary>
  2257. /// 工作模式选择
  2258. /// </summary>
  2259. /// <param name="sender"></param>
  2260. /// <param name="e"></param>
  2261. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  2262. {
  2263. var RunMode = new byte[1];
  2264. if (comboBox_WorkMode.Text == "配置模式")
  2265. RunMode[0] = 0x01;
  2266. else
  2267. RunMode[0] = 0x00;
  2268. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2269. }
  2270. /// <summary>
  2271. /// 助力档位选择
  2272. /// </summary>
  2273. /// <param name="sender"></param>
  2274. /// <param name="e"></param>
  2275. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  2276. {
  2277. var CtrlCode = new byte[2];
  2278. if (comboBox_GearSt.SelectedIndex == 5)//档位
  2279. CtrlCode[0] = 0x33;
  2280. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  2281. CtrlCode[0] = 0x22;
  2282. else
  2283. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  2284. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  2285. CtrlCode[1] = 0xF1;
  2286. else
  2287. CtrlCode[1] = 0xF0;
  2288. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  2289. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  2290. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  2291. }
  2292. /// <summary>
  2293. /// 仪表档位选择
  2294. /// </summary>
  2295. /// <param name="sender"></param>
  2296. /// <param name="e"></param>
  2297. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  2298. {
  2299. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  2300. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  2301. }
  2302. /// <summary>
  2303. /// 生产模式初始化
  2304. /// </summary>
  2305. /// <param name="sender"></param>
  2306. /// <param name="e"></param>
  2307. private void button_FacModeInit_Click(object sender, EventArgs e)
  2308. {
  2309. var Code = new byte[5];
  2310. Code[0] = (byte)'C';
  2311. Code[1] = (byte)'L';
  2312. Code[2] = (byte)'E';
  2313. Code[3] = (byte)'A';
  2314. Code[4] = (byte)'R';
  2315. timer_1s.Enabled = false;
  2316. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2317. {
  2318. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2319. {
  2320. timer_1s.Enabled = true;
  2321. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  2322. PowerOffAckStatus = false;
  2323. Delay_ms(250);
  2324. int TryCnt = 3;
  2325. while ((TryCnt--) >= 0)
  2326. {
  2327. if (!PowerOffAckStatus)
  2328. {
  2329. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  2330. PowerOffAckStatus = false;
  2331. Delay_ms(250);
  2332. }
  2333. else break;
  2334. }
  2335. if (PowerOffAckStatus)
  2336. {
  2337. timer_1s.Enabled = false;
  2338. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  2339. timer_1s.Enabled = true;
  2340. }
  2341. else
  2342. {
  2343. timer_1s.Enabled = false;
  2344. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2345. timer_1s.Enabled = true;
  2346. }
  2347. timer_1s.Enabled = true;
  2348. }
  2349. }
  2350. timer_1s.Enabled = true;
  2351. //清除历史测试记录
  2352. textBox_FacModeSensorADC0.Text = "";
  2353. textBox_FacModeSensorADC1.Text = "";
  2354. textBox_FacModeSensorADC2.Text = "";
  2355. textBox_FacModeSensorADC3.Text = "";
  2356. textBox_FacModeSensorADC4.Text = "";
  2357. checkBox_FacModeCheckBikeSpeed.Checked = false;
  2358. checkBox_FacModeCheckCadence.Checked = false;
  2359. checkBox_FacModeCheckNTC.Checked = false;
  2360. checkBox_FacModeCheckVol.Checked = false;
  2361. LightSwitchStatus = false;
  2362. MotorRunStatus = false;
  2363. trackBar_FacModeMotorSpeedAdj.Value = 5;
  2364. textBox_FacModeWheelSize.Text = "";
  2365. textBox_FacModeSpeedLimit.Text = "";
  2366. comboBox_FacModeAssist1.SelectedIndex = -1;
  2367. comboBox_FacModeAssist2.SelectedIndex = -1;
  2368. comboBox_FacModeLightVol.SelectedIndex = -1;
  2369. comboBox_FacModeStartMode.SelectedIndex = -1;
  2370. textBox_FacModeStartGain.Text = "";
  2371. textBox_FacModeCircuitK.Text = "";
  2372. textBox_FacModeFltCounter.Text = "";
  2373. textBox_FacModeSpeedLimitTh.Text = "";
  2374. textBox_FacModeSpeedLimitEnd.Text = "";
  2375. textBox_FacModeCadencePer.Text = "";
  2376. textBox_FacModeName.Text = "";
  2377. textBox_FacModeNum.Text = "";
  2378. textBox_FacModeHW.Text = "";
  2379. textBox_FacModeFW.Text = "";
  2380. }
  2381. /// <summary>
  2382. /// 生产模式读取传感器参数
  2383. /// </summary>
  2384. /// <param name="sender"></param>
  2385. /// <param name="e"></param>
  2386. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  2387. {
  2388. richTextBox_SensorParam.Clear();
  2389. textBox_FacModeSensorADC0.Text = "";
  2390. textBox_FacModeSensorADC1.Text = "";
  2391. textBox_FacModeSensorADC2.Text = "";
  2392. textBox_FacModeSensorADC3.Text = "";
  2393. textBox_FacModeSensorADC4.Text = "";
  2394. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2395. }
  2396. /// <summary>
  2397. /// 生产模式传感器标定1
  2398. /// </summary>
  2399. /// <param name="sender"></param>
  2400. /// <param name="e"></param>
  2401. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  2402. {
  2403. var ConfigParam = new byte[4];
  2404. for (int i = 0; i < 4; i++)
  2405. ConfigParam[i] = 0;
  2406. ushort uwDataTemp = 0;
  2407. try
  2408. {
  2409. uwDataTemp = 1;//负载序号
  2410. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2411. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2412. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  2413. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2414. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2415. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2416. Delay_ms(200);
  2417. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2418. }
  2419. catch (Exception)
  2420. {
  2421. timer_1s.Enabled = false;
  2422. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2423. timer_1s.Enabled = true;
  2424. }
  2425. }
  2426. /// <summary>
  2427. /// 生产模式传感器标定2
  2428. /// </summary>
  2429. /// <param name="sender"></param>
  2430. /// <param name="e"></param>
  2431. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  2432. {
  2433. var ConfigParam = new byte[4];
  2434. for (int i = 0; i < 4; i++)
  2435. ConfigParam[i] = 0;
  2436. ushort uwDataTemp = 0;
  2437. try
  2438. {
  2439. uwDataTemp = 2;//负载序号
  2440. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2441. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2442. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  2443. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2444. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2445. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2446. Delay_ms(200);
  2447. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2448. }
  2449. catch (Exception)
  2450. {
  2451. timer_1s.Enabled = false;
  2452. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2453. timer_1s.Enabled = true;
  2454. }
  2455. }
  2456. /// <summary>
  2457. /// 生产模式传感器标定3
  2458. /// </summary>
  2459. /// <param name="sender"></param>
  2460. /// <param name="e"></param>
  2461. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  2462. {
  2463. var ConfigParam = new byte[4];
  2464. for (int i = 0; i < 4; i++)
  2465. ConfigParam[i] = 0;
  2466. ushort uwDataTemp = 0;
  2467. try
  2468. {
  2469. uwDataTemp = 3;//负载序号
  2470. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2471. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2472. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  2473. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2474. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2475. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2476. Delay_ms(200);
  2477. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2478. }
  2479. catch (Exception)
  2480. {
  2481. timer_1s.Enabled = false;
  2482. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2483. timer_1s.Enabled = true;
  2484. }
  2485. }
  2486. /// <summary>
  2487. /// 生产模式传感器标定3
  2488. /// </summary>
  2489. /// <param name="sender"></param>
  2490. /// <param name="e"></param>
  2491. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  2492. {
  2493. var ConfigParam = new byte[4];
  2494. for (int i = 0; i < 4; i++)
  2495. ConfigParam[i] = 0;
  2496. ushort uwDataTemp = 0;
  2497. try
  2498. {
  2499. uwDataTemp = 4;//负载序号
  2500. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2501. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2502. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  2503. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2504. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2505. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2506. Delay_ms(200);
  2507. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2508. }
  2509. catch (Exception)
  2510. {
  2511. timer_1s.Enabled = false;
  2512. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2513. timer_1s.Enabled = true;
  2514. }
  2515. }
  2516. /// <summary>
  2517. /// 生产模式采集按钮
  2518. /// </summary>
  2519. /// <param name="sender"></param>
  2520. /// <param name="e"></param>
  2521. private void button_FacModeWorkMode_Click(object sender, EventArgs e)
  2522. {
  2523. var RunMode = new byte[1];
  2524. if (button_FacModeWorkMode.Text == "开始")
  2525. {
  2526. RunMode[0] = 0x01;
  2527. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
  2528. {
  2529. button_FacModeWorkMode.Text = "停止";
  2530. button_FacModeWorkMode.BackColor = Color.Yellow;
  2531. }
  2532. }
  2533. else if (button_FacModeWorkMode.Text == "停止")
  2534. {
  2535. RunMode[0] = 0x00;
  2536. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
  2537. {
  2538. button_FacModeWorkMode.Text = "开始";
  2539. button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2540. }
  2541. }
  2542. }
  2543. /// <summary>
  2544. /// 生产模式开关灯
  2545. /// </summary>
  2546. /// <param name="sender"></param>
  2547. /// <param name="e"></param>
  2548. bool LightSwitchStatus = false;
  2549. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  2550. {
  2551. var CtrlCode = new byte[2];
  2552. CtrlCode[0] = 0x00;
  2553. if (LightSwitchStatus)
  2554. {
  2555. CtrlCode[1] = 0xF0;
  2556. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  2557. }
  2558. else
  2559. {
  2560. CtrlCode[1] = 0xF1;
  2561. button_FacModeLightSW.BackColor = Color.Yellow;
  2562. }
  2563. if(mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  2564. {
  2565. LightSwitchStatus = !LightSwitchStatus;
  2566. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  2567. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  2568. }
  2569. }
  2570. /// <summary>
  2571. /// 生产模式电机控制
  2572. /// </summary>
  2573. /// <param name="sender"></param>
  2574. /// <param name="e"></param>
  2575. bool MotorRunStatus = false;
  2576. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  2577. {
  2578. string DebugDefaultInfo = "整体运行模式=4, 位置获取模式=1, 采样模式=2, 旋转方向=1, 定位电流=1000, 拖拽电压=18, 拖拽电流=1000, 拖拽频率=20, 加速斜率=500, 减速斜率=100, 转速环控制器带宽=15, 转速环控制器m=4, 电流环控制器带宽=300, 电流环控制器m=1, 磁链观测器带宽=10, 磁链观测器m=10, 锁相环带宽=150, 锁相环m=2, 惯量=300, PWM 最大占空比=900, PWM七段式切五段式阈值=700, 功率限幅值=6500, 功率Error=500, 功率限幅Kp=20, 功率限幅Ki=3000";
  2579. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2580. var ConfigParam = new byte[60];
  2581. for (int i = 0; i < 60; i++)
  2582. ConfigParam[i] = 0;
  2583. ConfigParam[0] = 0x00;
  2584. ushort uwDataTemp = 0;
  2585. if (!MotorRunStatus) //停止状态
  2586. {
  2587. //设置电机系列
  2588. if (radioButton_FacModeDriverCity.Checked == true)
  2589. {
  2590. strDataTemp[0] = "整体运行模式=3";
  2591. strDataTemp[3] = "旋转方向=1";
  2592. strDataTemp[18] = "惯量=300";
  2593. }
  2594. else if (radioButton_FacModeDriverMtb.Checked == true)
  2595. {
  2596. strDataTemp[0] = "整体运行模式=3";
  2597. strDataTemp[3] = "旋转方向=0";
  2598. strDataTemp[18] = "惯量=500";
  2599. }
  2600. else
  2601. {
  2602. timer_1s.Enabled = false;
  2603. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2604. timer_1s.Enabled = true;
  2605. return;
  2606. }
  2607. //设置带载类型
  2608. if (空载ToolStripMenuItem.Checked == true)
  2609. {
  2610. strDataTemp[10] = "转速环控制器带宽=3";
  2611. }
  2612. else if (带载ToolStripMenuItem.Checked == true)
  2613. {
  2614. strDataTemp[10] = "转速环控制器带宽=15";
  2615. }
  2616. else
  2617. {
  2618. timer_1s.Enabled = false;
  2619. MessageBox.Show("请选择带载类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2620. timer_1s.Enabled = true;
  2621. return;
  2622. }
  2623. //发送数据
  2624. try
  2625. {
  2626. for (int i = 0; i < strDataTemp.Length; i++)
  2627. {
  2628. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2629. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2630. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2631. }
  2632. if(!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  2633. return;
  2634. }
  2635. catch (Exception)
  2636. {
  2637. timer_1s.Enabled = false;
  2638. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2639. timer_1s.Enabled = true;
  2640. }
  2641. //设置转速百分比100%
  2642. trackBar_FacModeMotorSpeedAdj.Value = 100;
  2643. MotorRunStatus = !MotorRunStatus;
  2644. button_FacModeMotorRun.BackColor = Color.Yellow;
  2645. //电机进入配置模式
  2646. var RunMode = new byte[1];
  2647. RunMode[0] = 0x01;
  2648. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2649. button_FacModeWorkMode.Text = "停止";
  2650. button_FacModeWorkMode.BackColor = Color.Yellow;
  2651. }
  2652. else //运转状态
  2653. {
  2654. //设置电机调试参数
  2655. if (radioButton_FacModeDriverCity.Checked == true)
  2656. {
  2657. strDataTemp[0] = "整体运行模式=4";
  2658. strDataTemp[3] = "旋转方向=1";
  2659. strDataTemp[10] = "转速环控制器带宽=15";
  2660. strDataTemp[18] = "惯量=300";
  2661. }
  2662. else if (radioButton_FacModeDriverMtb.Checked == true)
  2663. {
  2664. strDataTemp[0] = "整体运行模式=5";
  2665. strDataTemp[3] = "旋转方向=0";
  2666. strDataTemp[10] = "转速环控制器带宽=15";
  2667. strDataTemp[18] = "惯量=500";
  2668. }
  2669. else
  2670. {
  2671. timer_1s.Enabled = false;
  2672. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2673. timer_1s.Enabled = true;
  2674. return;
  2675. }
  2676. try
  2677. {
  2678. for (int i = 0; i < strDataTemp.Length; i++)
  2679. {
  2680. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2681. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2682. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2683. }
  2684. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  2685. return;
  2686. }
  2687. catch (Exception)
  2688. {
  2689. timer_1s.Enabled = false;
  2690. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2691. timer_1s.Enabled = true;
  2692. }
  2693. //设置转速百分比2%
  2694. trackBar_FacModeMotorSpeedAdj.Value = 2;
  2695. MotorRunStatus = !MotorRunStatus;
  2696. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2697. //电机退出配置模式
  2698. var RunMode = new byte[1];
  2699. RunMode[0] = 0x00;
  2700. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2701. button_FacModeWorkMode.Text = "开始";
  2702. button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2703. }
  2704. }
  2705. /// <summary>
  2706. /// 生产模式转速调节
  2707. /// </summary>
  2708. /// <param name="sender"></param>
  2709. /// <param name="e"></param>
  2710. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  2711. {
  2712. //转速百分比更新
  2713. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  2714. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  2715. //设置转速百分比
  2716. var Data = new byte[1];
  2717. Data[0] = (byte)trackBar_FacModeMotorSpeedAdj.Value;
  2718. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  2719. }
  2720. /// <summary>
  2721. /// 生产模式读取整车参数
  2722. /// </summary>
  2723. /// <param name="sender"></param>
  2724. /// <param name="e"></param>
  2725. private void button_FacModeBikeParaRead_Click(object sender, EventArgs e)
  2726. {
  2727. textBox_FacModeWheelSize.Text = "";
  2728. textBox_FacModeSpeedLimit.Text = "";
  2729. comboBox_FacModeAssist1.SelectedIndex = -1;
  2730. comboBox_FacModeAssist2.SelectedIndex = -1;
  2731. comboBox_FacModeLightVol.SelectedIndex = -1;
  2732. comboBox_FacModeStartMode.SelectedIndex = -1;
  2733. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2734. }
  2735. /// <summary>
  2736. /// 生产模式写入整车参数
  2737. /// </summary>
  2738. /// <param name="sender"></param>
  2739. /// <param name="e"></param>
  2740. private void button_FacModeBikeParaSet_Click(object sender, EventArgs e)
  2741. {
  2742. string BikeDefaultInfo = "轮胎周长=219, 电控传动比=35, 助力最大限速=25, 推行模式限速=6, 前牙盘T数=38, 后牙盘T数=11, 助力方案1=341, 助力方案2=682, 前后灯电压=6, 轮胎周长微调=0, 启动模式=2, 自动关机时间=15";
  2743. var ConfigParam = new byte[28];
  2744. for (int i = 0; i < 28; i++)
  2745. ConfigParam[i] = 0;
  2746. ConfigParam[0] = (byte)(0x01);
  2747. ushort uwDataTemp = 0;
  2748. string[] strDataTemp = BikeDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2749. try
  2750. {
  2751. for (int i = 0; i < strDataTemp.Length; i++)
  2752. {
  2753. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2754. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2755. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2756. }
  2757. //周长
  2758. uwDataTemp = Convert.ToUInt16(textBox_FacModeWheelSize.Text);
  2759. ConfigParam[2] = (byte)uwDataTemp;
  2760. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2761. //限速
  2762. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimit.Text);
  2763. ConfigParam[6] = (byte)uwDataTemp;
  2764. ConfigParam[7] = (byte)(uwDataTemp >> 8);
  2765. //助力方案1
  2766. if (comboBox_FacModeAssist1.SelectedIndex == 0) uwDataTemp = 0;
  2767. else if (comboBox_FacModeAssist1.SelectedIndex == 1) uwDataTemp = 341;
  2768. else if (comboBox_FacModeAssist1.SelectedIndex == 2) uwDataTemp = 682;
  2769. else
  2770. {
  2771. timer_1s.Enabled = false;
  2772. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2773. timer_1s.Enabled = true;
  2774. return;
  2775. }
  2776. ConfigParam[14] = (byte)uwDataTemp;
  2777. ConfigParam[15] = (byte)(uwDataTemp >> 8);
  2778. //助力方案2
  2779. if(comboBox_FacModeAssist2.SelectedIndex == 0) uwDataTemp = 0;
  2780. else if (comboBox_FacModeAssist2.SelectedIndex == 1) uwDataTemp = 341;
  2781. else if (comboBox_FacModeAssist2.SelectedIndex == 2) uwDataTemp = 682;
  2782. else
  2783. {
  2784. timer_1s.Enabled = false;
  2785. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2786. timer_1s.Enabled = true;
  2787. return;
  2788. }
  2789. ConfigParam[16] = (byte)uwDataTemp;
  2790. ConfigParam[17] = (byte)(uwDataTemp >> 8);
  2791. //灯压
  2792. if(comboBox_FacModeLightVol.SelectedIndex == 0) uwDataTemp = 6;
  2793. else if (comboBox_FacModeLightVol.SelectedIndex == 1) uwDataTemp = 12;
  2794. else
  2795. {
  2796. timer_1s.Enabled = false;
  2797. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2798. timer_1s.Enabled = true;
  2799. return;
  2800. }
  2801. ConfigParam[18] = (byte)uwDataTemp;
  2802. ConfigParam[19] = (byte)(uwDataTemp >> 8);
  2803. //启动模式
  2804. if (comboBox_FacModeStartMode.SelectedIndex == 0) uwDataTemp = 1;
  2805. else if (comboBox_FacModeStartMode.SelectedIndex == 2) uwDataTemp = 3;
  2806. else uwDataTemp = 2;
  2807. ConfigParam[22] = (byte)uwDataTemp;
  2808. ConfigParam[23] = (byte)(uwDataTemp >> 8);
  2809. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2810. }
  2811. catch (Exception)
  2812. {
  2813. timer_1s.Enabled = false;
  2814. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2815. timer_1s.Enabled = true;
  2816. }
  2817. }
  2818. /// <summary>
  2819. /// 生产模式读取助力参数
  2820. /// </summary>
  2821. /// <param name="sender"></param>
  2822. /// <param name="e"></param>
  2823. private void button_FacModeAssistParaRead_Click(object sender, EventArgs e)
  2824. {
  2825. var ConfigParam = new byte[4];
  2826. textBox_FacModeStartGain.Text = "";
  2827. textBox_FacModeCircuitK.Text = "";
  2828. textBox_FacModeFltCounter.Text = "";
  2829. textBox_FacModeSpeedLimitTh.Text ="";
  2830. textBox_FacModeSpeedLimitEnd.Text = "";
  2831. textBox_FacModeCadencePer.Text = "";
  2832. ConfigParam[0] = (byte)(1 & 0xFF);
  2833. ConfigParam[1] = (byte)(1 >> 8);
  2834. ConfigParam[2] = (byte)(1 & 0xFF);
  2835. ConfigParam[3] = (byte)(1 >> 8);
  2836. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2837. }
  2838. /// <summary>
  2839. /// 生产模式写入助力参数
  2840. /// </summary>
  2841. /// <param name="sender"></param>
  2842. /// <param name="e"></param>
  2843. private void button_FacModeAssistParaSet_Click(object sender, EventArgs e)
  2844. {
  2845. 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";
  2846. var ConfigParam = new byte[80];
  2847. for (int i = 0; i < 80; i++)
  2848. ConfigParam[i] = 0;
  2849. ConfigParam[0] = (byte)(0x01);
  2850. ushort uwDataTemp = 0;
  2851. ulong ulDataTemp = 0;
  2852. int index_1 = 0, index_2 = 0;
  2853. string[] strDataTemp = AssistDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2854. try
  2855. {
  2856. //因数据类型不同,预处理
  2857. for (int i = 0; i < strDataTemp.Length; i++)
  2858. {
  2859. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2860. {
  2861. index_1 = i;
  2862. break;
  2863. }
  2864. }
  2865. for (int i = 0; i < strDataTemp.Length; i++)
  2866. {
  2867. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2868. {
  2869. index_2 = i;
  2870. break;
  2871. }
  2872. }
  2873. for (int i = 0; i < strDataTemp.Length; i++)
  2874. {
  2875. ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
  2876. if (i < index_1)
  2877. {
  2878. ConfigParam[2 * i + 4] = (byte)ulDataTemp;
  2879. ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
  2880. }
  2881. else if (i <= index_2)
  2882. {
  2883. ConfigParam[4 * i - 4] = (byte)ulDataTemp;
  2884. ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
  2885. ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
  2886. ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
  2887. }
  2888. else
  2889. {
  2890. ConfigParam[2 * i + 20] = (byte)ulDataTemp;
  2891. ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
  2892. }
  2893. }
  2894. //零速增益
  2895. uwDataTemp = Convert.ToUInt16(textBox_FacModeStartGain.Text);
  2896. ConfigParam[4] = (byte)uwDataTemp;
  2897. ConfigParam[5] = (byte)(uwDataTemp >> 8);
  2898. //电流阶梯
  2899. uwDataTemp = Convert.ToUInt16(textBox_FacModeCircuitK.Text);
  2900. ConfigParam[48] = (byte)uwDataTemp;
  2901. ConfigParam[49] = (byte)(uwDataTemp >> 8);
  2902. //滤波脉冲
  2903. uwDataTemp = Convert.ToUInt16(textBox_FacModeFltCounter.Text);
  2904. ConfigParam[52] = (byte)uwDataTemp;
  2905. ConfigParam[53] = (byte)(uwDataTemp >> 8);
  2906. //限速启动
  2907. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitTh.Text);
  2908. ConfigParam[58] = (byte)uwDataTemp;
  2909. ConfigParam[59] = (byte)(uwDataTemp >> 8);
  2910. //限速停止
  2911. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitEnd.Text);
  2912. ConfigParam[60] = (byte)uwDataTemp;
  2913. ConfigParam[61] = (byte)(uwDataTemp >> 8);
  2914. //踏频占比
  2915. uwDataTemp = Convert.ToUInt16(textBox_FacModeCadencePer.Text);
  2916. ConfigParam[62] = (byte)uwDataTemp;
  2917. ConfigParam[63] = (byte)(uwDataTemp >> 8);
  2918. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2919. }
  2920. catch (Exception)
  2921. {
  2922. timer_1s.Enabled = false;
  2923. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2924. timer_1s.Enabled = true;
  2925. }
  2926. }
  2927. /// <summary>
  2928. /// 生产模式写入型号
  2929. /// </summary>
  2930. /// <param name="sender"></param>
  2931. /// <param name="e"></param>
  2932. private void button_FacModeSetName_Click(object sender, EventArgs e)
  2933. {
  2934. string Mode = textBox_FacModeName.Text;
  2935. var ModeArray = new byte[16];
  2936. for (ushort i = 0; i < Mode.Length; i++)
  2937. {
  2938. ModeArray[i] = (byte)Mode[i];
  2939. }
  2940. if (Mode.Length < 16)
  2941. {
  2942. ModeArray[Mode.Length] = (byte)'.';
  2943. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2944. {
  2945. ModeArray[Mode.Length + 1 + i] = 0x20;
  2946. }
  2947. }
  2948. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2949. }
  2950. /// <summary>
  2951. /// 生产模式写入SN
  2952. /// </summary>
  2953. /// <param name="sender"></param>
  2954. /// <param name="e"></param>
  2955. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  2956. {
  2957. string SN = textBox_FacModeNum.Text;
  2958. var SNArray = new byte[16];
  2959. for (ushort i = 0; i < SN.Length; i++)
  2960. {
  2961. SNArray[i] = (byte)SN[i];
  2962. }
  2963. if (SN.Length < 16)
  2964. {
  2965. SNArray[SN.Length] = (byte)'.';
  2966. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2967. {
  2968. SNArray[SN.Length + 1 + i] = 0x20;
  2969. }
  2970. }
  2971. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2972. }
  2973. /// <summary>
  2974. /// 生产模式读取版本信息
  2975. /// </summary>
  2976. /// <param name="sender"></param>
  2977. /// <param name="e"></param>
  2978. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  2979. {
  2980. textBox_Model.Text = "---";
  2981. textBox_SN.Text = "---";
  2982. textBox_HW.Text = "---";
  2983. textBox_FW.Text = "---";
  2984. textBox_SP.Text = "---";
  2985. textBox_OBC_ReadModel.Text = "---";
  2986. textBox_OBC_ReadSN.Text = "---";
  2987. textBox_OBC_ReadHW.Text = "---";
  2988. textBox_OBC_ReadFW.Text = "---";
  2989. textBox_OBC_ReadSP.Text = "---";
  2990. textBox_FacModeName.Text = "---";
  2991. textBox_FacModeNum.Text = "---";
  2992. textBox_FacModeHW.Text = "---";
  2993. textBox_FacModeFW.Text = "---";
  2994. textBox_FacModeSP.Text = "---";
  2995. Class_Motor_Ver.Mode = "---";
  2996. Class_Motor_Ver.SN = "---";
  2997. Class_Motor_Ver.HW = "---";
  2998. Class_Motor_Ver.FW = "---";
  2999. Class_Motor_Ver.Special = "---";
  3000. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3001. }
  3002. /// <summary>
  3003. /// 生产模式写入生产信息
  3004. /// </summary>
  3005. /// <param name="sender"></param>
  3006. /// <param name="e"></param>
  3007. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  3008. {
  3009. var MACArray = new byte[32];
  3010. string MacDefaultInfo = "TTIUM";
  3011. string MacAddDefaultInfo = "WUHAN";
  3012. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  3013. string MacPPDefaultInfo = "MM_MC1";
  3014. //填入生产商
  3015. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  3016. {
  3017. MACArray[i] = (byte)MacDefaultInfo[i];
  3018. }
  3019. if (MacDefaultInfo.Length < 8)
  3020. {
  3021. MACArray[MacDefaultInfo.Length] = (byte)'.';
  3022. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  3023. {
  3024. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  3025. }
  3026. }
  3027. //填入生产地
  3028. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  3029. {
  3030. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  3031. }
  3032. if (MacAddDefaultInfo.Length < 8)
  3033. {
  3034. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  3035. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  3036. {
  3037. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  3038. }
  3039. }
  3040. //填入生产日期
  3041. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  3042. {
  3043. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  3044. }
  3045. if (MacDateDefaultInfo.Length < 8)
  3046. {
  3047. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  3048. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  3049. {
  3050. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  3051. }
  3052. }
  3053. //填入产品标识
  3054. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  3055. {
  3056. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  3057. }
  3058. if (MacPPDefaultInfo.Length < 8)
  3059. {
  3060. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  3061. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  3062. {
  3063. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  3064. }
  3065. }
  3066. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3067. }
  3068. /// <summary>
  3069. /// 生产模式保存测试页面
  3070. /// </summary>
  3071. /// <param name="sender"></param>
  3072. /// <param name="e"></param>
  3073. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  3074. {
  3075. //查询传感器
  3076. richTextBox_SensorParam.Clear();
  3077. textBox_FacModeSensorADC0.Text = "";
  3078. textBox_FacModeSensorADC1.Text = "";
  3079. textBox_FacModeSensorADC2.Text = "";
  3080. textBox_FacModeSensorADC3.Text = "";
  3081. textBox_FacModeSensorADC4.Text = "";
  3082. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) return;
  3083. Delay_ms(100);
  3084. //读取一次电机信息
  3085. var CtrlCode = new byte[2];
  3086. CtrlCode[0] = 0x00;
  3087. CtrlCode[1] = 0xF0;
  3088. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) return;
  3089. Delay_ms(100);
  3090. //读取一次整车参数
  3091. textBox_FacModeWheelSize.Text = "";
  3092. textBox_FacModeSpeedLimit.Text = "";
  3093. comboBox_FacModeAssist1.SelectedIndex = -1;
  3094. comboBox_FacModeAssist2.SelectedIndex = -1;
  3095. comboBox_FacModeLightVol.SelectedIndex = -1;
  3096. comboBox_FacModeStartMode.SelectedIndex = -1;
  3097. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) return;
  3098. Delay_ms(100);
  3099. //读取一次助力参数
  3100. var ConfigParam = new byte[4];
  3101. textBox_FacModeStartGain.Text = "";
  3102. textBox_FacModeCircuitK.Text = "";
  3103. textBox_FacModeFltCounter.Text = "";
  3104. textBox_FacModeSpeedLimitTh.Text = "";
  3105. textBox_FacModeSpeedLimitEnd.Text = "";
  3106. textBox_FacModeCadencePer.Text = "";
  3107. ConfigParam[0] = (byte)(1 & 0xFF);
  3108. ConfigParam[1] = (byte)(1 >> 8);
  3109. ConfigParam[2] = (byte)(1 & 0xFF);
  3110. ConfigParam[3] = (byte)(1 >> 8);
  3111. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) return;
  3112. Delay_ms(100);
  3113. //读取一次版本信息
  3114. textBox_Model.Text = "---";
  3115. textBox_SN.Text = "---";
  3116. textBox_HW.Text = "---";
  3117. textBox_FW.Text = "---";
  3118. textBox_OBC_ReadModel.Text = "---";
  3119. textBox_OBC_ReadSN.Text = "---";
  3120. textBox_OBC_ReadHW.Text = "---";
  3121. textBox_OBC_ReadFW.Text = "---";
  3122. textBox_FacModeName.Text = "---";
  3123. textBox_FacModeNum.Text = "---";
  3124. textBox_FacModeHW.Text = "---";
  3125. textBox_FacModeFW.Text = "---";
  3126. Class_Motor_Ver.Mode = "---";
  3127. Class_Motor_Ver.SN = "---";
  3128. Class_Motor_Ver.HW = "---";
  3129. Class_Motor_Ver.FW = "---";
  3130. Class_Motor_Ver.Special = "---";
  3131. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) return;
  3132. Delay_ms(100);
  3133. //提示检查
  3134. timer_1s.Enabled = false;
  3135. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  3136. {
  3137. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3138. timer_1s.Enabled = true;
  3139. return;
  3140. }
  3141. timer_1s.Enabled = true;
  3142. Delay_ms(200);
  3143. //保存页面
  3144. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  3145. Graphics g = Graphics.FromImage(bit);
  3146. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  3147. SaveFileDialog sf = new SaveFileDialog();
  3148. sf.Title = "页面保存";
  3149. sf.FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_页面存储" + ".png";
  3150. sf.Filter = "图片|*.png";
  3151. timer_1s.Enabled = false;
  3152. if (sf.ShowDialog() == DialogResult.OK)
  3153. {
  3154. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  3155. }
  3156. timer_1s.Enabled = true;
  3157. }
  3158. /// <summary>
  3159. /// 工具箱页面保存
  3160. /// </summary>
  3161. /// <param name="sender"></param>
  3162. /// <param name="e"></param>
  3163. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  3164. {
  3165. //保存页面
  3166. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  3167. Graphics g = Graphics.FromImage(bit);
  3168. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  3169. SaveFileDialog sf = new SaveFileDialog();
  3170. sf.Title = "页面保存";
  3171. sf.FileName = "MotorInfo_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  3172. sf.Filter = "图片|*.png";
  3173. timer_1s.Enabled = false;
  3174. if (sf.ShowDialog() == DialogResult.OK)
  3175. {
  3176. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  3177. }
  3178. timer_1s.Enabled = true;
  3179. }
  3180. /// <summary>
  3181. /// 生产模式关机
  3182. /// </summary>
  3183. /// <param name="sender"></param>
  3184. /// <param name="e"></param>
  3185. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  3186. {
  3187. var Code = new byte[5];
  3188. Code[0] = (byte)'O';
  3189. Code[1] = (byte)'F';
  3190. Code[2] = (byte)'F';
  3191. Code[3] = (byte)'.';
  3192. Code[4] = (byte)'.';
  3193. timer_1s.Enabled = false;
  3194. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3195. {
  3196. timer_1s.Enabled = true;
  3197. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  3198. PowerOffAckStatus = false;
  3199. Delay_ms(250);
  3200. int TryCnt = 3;
  3201. while ((TryCnt--) >= 0)
  3202. {
  3203. if (!PowerOffAckStatus)
  3204. {
  3205. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  3206. PowerOffAckStatus = false;
  3207. Delay_ms(250);
  3208. }
  3209. else break;
  3210. }
  3211. if (PowerOffAckStatus)
  3212. {
  3213. timer_1s.Enabled = false;
  3214. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3215. timer_1s.Enabled = true;
  3216. }
  3217. else
  3218. {
  3219. timer_1s.Enabled = false;
  3220. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3221. timer_1s.Enabled = true;
  3222. }
  3223. }
  3224. timer_1s.Enabled = true;
  3225. }
  3226. //仪表电源键按下
  3227. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  3228. {
  3229. var Code = new byte[2];
  3230. Code[0] = 0;
  3231. Code[1] = 0b00100000;
  3232. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3233. }
  3234. /// <summary>
  3235. /// 仪表加键按下
  3236. /// </summary>
  3237. /// <param name="sender"></param>
  3238. /// <param name="e"></param>
  3239. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  3240. {
  3241. var Code = new byte[2];
  3242. Code[0] = 0;
  3243. Code[1] = 0b00010000;
  3244. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3245. }
  3246. /// <summary>
  3247. /// 仪表减键按下
  3248. /// </summary>
  3249. /// <param name="sender"></param>
  3250. /// <param name="e"></param>
  3251. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  3252. {
  3253. var Code = new byte[2];
  3254. Code[0] = 0;
  3255. Code[1] = 0b00001000;
  3256. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3257. }
  3258. /// <summary>
  3259. /// 仪表Walk键按下
  3260. /// </summary>
  3261. /// <param name="sender"></param>
  3262. /// <param name="e"></param>
  3263. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  3264. {
  3265. var Code = new byte[2];
  3266. Code[0] = 0;
  3267. Code[1] = 0b00000100;
  3268. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3269. }
  3270. /// <summary>
  3271. /// 仪表Light键按下
  3272. /// </summary>
  3273. /// <param name="sender"></param>
  3274. /// <param name="e"></param>
  3275. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  3276. {
  3277. var Code = new byte[2];
  3278. Code[0] = 0;
  3279. Code[1] = 0b00000010;
  3280. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3281. }
  3282. /// <summary>
  3283. /// 仪表Set键按下
  3284. /// </summary>
  3285. /// <param name="sender"></param>
  3286. /// <param name="e"></param>
  3287. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  3288. {
  3289. var Code = new byte[2];
  3290. Code[0] = 0;
  3291. Code[1] = 0b00000001;
  3292. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3293. }
  3294. private void 空载ToolStripMenuItem_Click(object sender, EventArgs e)
  3295. {
  3296. 空载ToolStripMenuItem.Checked = true;
  3297. 带载ToolStripMenuItem.Checked = false;
  3298. }
  3299. private void 带载ToolStripMenuItem_Click(object sender, EventArgs e)
  3300. {
  3301. 空载ToolStripMenuItem.Checked = false;
  3302. 带载ToolStripMenuItem.Checked = true;
  3303. }
  3304. }
  3305. }