Form1.cs 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  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. #endregion
  24. public Form1()
  25. {
  26. InitializeComponent();
  27. }
  28. private void Form1_Load(object sender, System.EventArgs e)
  29. {
  30. //页面初始化
  31. label_BuildTime.Text= "编译时间:"+ System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
  32. //端口设置
  33. mySerialProcess.Init();
  34. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  35. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  36. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
  37. //创建线程,定时解析数据
  38. Thread th = new Thread(Task_SerialProcess);
  39. th.IsBackground = true;
  40. th.Start();
  41. }
  42. #region 串口数据解析线程
  43. /// <summary>
  44. /// 串口数据解析线程
  45. /// </summary>
  46. private void Task_SerialProcess()
  47. {
  48. //创建定时器,定时读取串口数据
  49. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  50. timer_ReadSerial.Enabled = true;
  51. timer_ReadSerial.Interval = 20;
  52. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  53. timer_ReadSerial.Start();
  54. while (true)
  55. {
  56. Thread.Sleep(1);
  57. };
  58. }
  59. /// <summary>
  60. /// 串口解析定时器
  61. /// </summary>
  62. /// <param name="sender"></param>
  63. /// <param name="e"></param>
  64. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  65. {
  66. //串口解析
  67. Serial_process(mySerialProcess.buffer);
  68. }
  69. #endregion
  70. #region 数据解析
  71. public void Serial_process(List<byte> buffer)
  72. {
  73. byte DataNum = 0; //记录每条命令数据段的长度
  74. ushort PackageID, Cmd;
  75. byte[] Data = new byte[1024];
  76. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  77. {
  78. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  79. {
  80. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  81. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF))
  82. {
  83. int CmdLen = buffer[5];
  84. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  85. buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
  86. while (CmdLen > 0) //读取命令段
  87. {
  88. Cmd = (ushort)(buffer[0] * 256 + buffer[1]);
  89. DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
  90. if (DataNum <= (CmdLen - 2))
  91. {
  92. for (int i = 0; i < DataNum; i++)
  93. {
  94. Data[i] = buffer[i + 2];
  95. }
  96. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  97. buffer.RemoveRange(0, DataNum);//移除处理过的数据段
  98. CmdLen -= (DataNum + 2);
  99. if (CmdLen < 2)
  100. {
  101. buffer.RemoveRange(0, CmdLen + 2);
  102. return;
  103. }
  104. }
  105. else
  106. {
  107. buffer.RemoveRange(0, CmdLen + 11);
  108. }
  109. }
  110. }
  111. else
  112. {
  113. buffer.RemoveAt(0);//ID不对
  114. }
  115. }
  116. else
  117. {
  118. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  119. }
  120. }
  121. }
  122. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  123. {
  124. int DataTemp;
  125. unchecked
  126. {
  127. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  128. }
  129. #region 解析发送给CDL的指令
  130. if (ID == 0x7FF)
  131. {
  132. switch (CmdTemp)
  133. {
  134. case 0x1100://TE APP版本信息
  135. {
  136. unchecked
  137. {
  138. this.Invoke((EventHandler)(delegate
  139. {
  140. //CDL连接成功
  141. mySerialProcess.CDL_Online_Flag = true;
  142. MessageBox.Show("连接成功!", "提示");
  143. //显示其它界面
  144. foreach (Control c in this.Controls)
  145. {
  146. if (c is GroupBox)
  147. {
  148. if (c != groupBox1)
  149. {
  150. c.Visible = true;
  151. }
  152. }
  153. }
  154. }));
  155. }
  156. break;
  157. }
  158. default: break;
  159. }
  160. }
  161. #endregion
  162. #region 解析电机的命令
  163. else if ((ID == 0x715) || (ID == 0x710))
  164. {
  165. switch (CmdTemp)
  166. {
  167. case 0x1020://电机运行信息
  168. {
  169. unchecked
  170. {
  171. this.Invoke((EventHandler)(delegate
  172. {
  173. MC_RunInfo_Refresh = true;
  174. //车速
  175. DataTemp = (int)(Data[1] * 256 + Data[0]);
  176. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  177. //输出转速
  178. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  179. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  180. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  181. Class_MotorSpeed.Data = DataTemp;
  182. //电功率
  183. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  184. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp * 2) + " W";
  185. //母线电压
  186. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  187. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  188. //母线电流
  189. DataTemp = (ushort)(Data[9] * 256 + Data[8]);
  190. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  191. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  192. Class_CurrentData.Data = DataTemp;
  193. //踏频
  194. DataTemp = (ushort)(Data[10]);
  195. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  196. //踩踏力矩
  197. DataTemp = (ushort)(Data[11]);
  198. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  199. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  200. Class_TorqueData.Data = DataTemp;
  201. //踩踏方向
  202. DataTemp = (ushort)(Data[12]);
  203. if (DataTemp == 0)
  204. {
  205. textBox_RunInfo_Dir.Text = "正向";
  206. }
  207. else if (DataTemp == 1)
  208. {
  209. textBox_RunInfo_Dir.Text = "反向";
  210. }
  211. else if (DataTemp == 2)
  212. {
  213. textBox_RunInfo_Dir.Text = "停止";
  214. }
  215. //助力档位
  216. DataTemp = (ushort)(Data[13]);
  217. if (DataTemp == 0x22)
  218. {
  219. textBox_RunInfo_GearSt.Text = "Walk";
  220. comboBox_GearSt.SelectedIndex = 6;
  221. }
  222. else
  223. {
  224. textBox_RunInfo_GearSt.Text = Convert.ToString(DataTemp);
  225. comboBox_GearSt.SelectedIndex = DataTemp;
  226. }
  227. //大灯状态
  228. DataTemp = (ushort)(Data[14]);
  229. if (DataTemp == 0xF0)
  230. {
  231. textBox_RunInfo_LightSwitch.Text = "OFF";
  232. comboBox_LightSwitch.SelectedIndex = 1;
  233. }
  234. else if (DataTemp == 0xF1)
  235. {
  236. textBox_RunInfo_LightSwitch.Text = "ON";
  237. comboBox_LightSwitch.SelectedIndex = 0;
  238. }
  239. //剩余电量
  240. DataTemp = (ushort)(Data[15]);
  241. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  242. //剩余续航里程
  243. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  244. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  245. {
  246. textBox_RunInfo_Range.Text = "---";
  247. }
  248. else
  249. {
  250. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  251. }
  252. //预留,空2bytes
  253. //平均功耗
  254. DataTemp = (ushort)(Data[20]);
  255. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  256. //PCB温度
  257. DataTemp = (ushort)(Data[21]);
  258. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40));
  259. //绕组温度
  260. DataTemp = (ushort)(Data[22]);
  261. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40));
  262. //MCU温度
  263. DataTemp = (ushort)(Data[23]);
  264. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40));
  265. //单次里程
  266. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  267. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  268. //单次时间
  269. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  270. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  271. //数据保存
  272. DataAutoSave();
  273. }));
  274. }
  275. break;
  276. }
  277. case 0x1104://故障码
  278. {
  279. unchecked
  280. {
  281. this.Invoke((EventHandler)(delegate
  282. {
  283. MC_ErrorCode_Refresh = true;
  284. textBox_ErrorCode.Text =
  285. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  286. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  287. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  288. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  289. "H";
  290. }));
  291. }
  292. break;
  293. }
  294. case 0xA903://反馈指令
  295. {
  296. unchecked
  297. {
  298. this.Invoke((EventHandler)(delegate
  299. {
  300. timer_1s.Enabled = false;
  301. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  302. timer_1s.Enabled = true;
  303. }));
  304. }
  305. break;
  306. }
  307. case 0xB226://马达参数
  308. {
  309. unchecked
  310. {
  311. this.Invoke((EventHandler)(delegate
  312. {
  313. richTextBox_MotorParam.Clear();
  314. for (int i = 0; i < myParams.MotorParma.Count; i++)
  315. {
  316. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  317. }
  318. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  319. }));
  320. }
  321. break;
  322. }
  323. case 0xB318://整车信息
  324. {
  325. unchecked
  326. {
  327. this.Invoke((EventHandler)(delegate
  328. {
  329. richTextBox_BikeParam.Clear();
  330. for (int i = 0; i < myParams.BikeParma.Count; i++)
  331. {
  332. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  333. }
  334. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  335. }));
  336. }
  337. break;
  338. }
  339. case 0xB420://控制器参数
  340. {
  341. unchecked
  342. {
  343. this.Invoke((EventHandler)(delegate
  344. {
  345. richTextBox_ControlParam.Clear();
  346. for (int i = 0; i < myParams.ControlParma.Count; i++)
  347. {
  348. richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  349. }
  350. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  351. }));
  352. }
  353. break;
  354. }
  355. case 0xB528://传感器参数
  356. {
  357. unchecked
  358. {
  359. this.Invoke((EventHandler)(delegate
  360. {
  361. richTextBox_SensorParam.Clear();
  362. for (int i = 0; i < myParams.SensorParam.Count; i++)
  363. {
  364. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  365. }
  366. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  367. }));
  368. }
  369. break;
  370. }
  371. case 0xB64C://助力参数
  372. {
  373. unchecked
  374. {
  375. this.Invoke((EventHandler)(delegate
  376. {
  377. richTextBox_AssistParam.Clear();
  378. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  379. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  380. for (int i = 0; i < myParams.AssistParam.Count; i++)
  381. {
  382. if (i < index_1) //数据占用2bytes
  383. {
  384. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  385. }
  386. else if (i <= index_2) //数据占用4bytes
  387. {
  388. 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]) + ", ");
  389. }
  390. else //数据占用2bytes
  391. {
  392. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString(Data[2 * i + 17] * 256 + Data[2 * i + 16]) + ", ");
  393. }
  394. }
  395. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  396. }));
  397. }
  398. break;
  399. }
  400. case 0xB74C://历史记录
  401. {
  402. unchecked
  403. {
  404. this.Invoke((EventHandler)(delegate
  405. {
  406. richTextBox_Record.Clear();
  407. for (int i = 0; i < myParams.Record.Count; i++)
  408. {
  409. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  410. }
  411. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  412. }));
  413. }
  414. break;
  415. }
  416. case 0xB832://调试参数
  417. {
  418. unchecked
  419. {
  420. this.Invoke((EventHandler)(delegate
  421. {
  422. richTextBox_DebugParam.Clear();
  423. for (int i = 0; i < myParams.DebugParam.Count; i++)
  424. {
  425. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  426. }
  427. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  428. }));
  429. }
  430. break;
  431. }
  432. case 0x1240://电机版本信息
  433. {
  434. unchecked
  435. {
  436. this.Invoke((EventHandler)(delegate
  437. {
  438. //电机型号
  439. textBox_Model.Text = "";
  440. for (ushort i = 0; i < 16; i++)
  441. {
  442. if (Data[i] == 0x2E)
  443. {
  444. break;
  445. }
  446. textBox_Model.Text += ((char)Data[i]).ToString();
  447. }
  448. Class_Motor_Ver.Mode = textBox_Model.Text;
  449. //电机SN
  450. textBox_SN.Text = "";
  451. for (ushort i = 0; i < 16; i++)
  452. {
  453. if (Data[16 + i] == 0x2E)
  454. {
  455. break;
  456. }
  457. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  458. }
  459. Class_Motor_Ver.SN = textBox_SN.Text;
  460. //电机HW
  461. textBox_HW.Text = "";
  462. for (ushort i = 0; i < 10; i++)
  463. {
  464. if (Data[32 + i] == 0x2E)
  465. {
  466. break;
  467. }
  468. textBox_HW.Text += ((char)Data[32 + i]).ToString();
  469. }
  470. Class_Motor_Ver.HW = textBox_HW.Text;
  471. //电机FW
  472. textBox_FW.Text = "";
  473. for (ushort i = 0; i < 16; i++)
  474. {
  475. if (Data[48 + i] == 0x2E)
  476. {
  477. break;
  478. }
  479. if (Data[48 + i] == 'r')
  480. {
  481. Data[48 + i] = (byte)'.';
  482. }
  483. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  484. }
  485. Class_Motor_Ver.FW = textBox_FW.Text;
  486. }));
  487. }
  488. break;
  489. }
  490. case 0xA610://自定义1
  491. {
  492. unchecked
  493. {
  494. this.Invoke((EventHandler)(delegate
  495. {
  496. textBox_User1.Text = "";
  497. for (ushort i = 0; i < 16; i++)
  498. {
  499. if (Data[i] == 0x2E)
  500. {
  501. break;
  502. }
  503. textBox_User1.Text += ((char)Data[i]).ToString();
  504. }
  505. }));
  506. }
  507. break;
  508. }
  509. case 0xA710://自定义2
  510. {
  511. unchecked
  512. {
  513. this.Invoke((EventHandler)(delegate
  514. {
  515. textBox_User2.Text = "";
  516. for (ushort i = 0; i < 16; i++)
  517. {
  518. if (Data[i] == 0x2E)
  519. {
  520. break;
  521. }
  522. textBox_User2.Text += ((char)Data[i]).ToString();
  523. }
  524. }));
  525. }
  526. break;
  527. }
  528. case 0xA810://自定义1
  529. {
  530. unchecked
  531. {
  532. this.Invoke((EventHandler)(delegate
  533. {
  534. textBox_User3.Text = "";
  535. for (ushort i = 0; i < 16; i++)
  536. {
  537. if (Data[i] == 0x2E)
  538. {
  539. break;
  540. }
  541. textBox_User3.Text += ((char)Data[i]).ToString();
  542. }
  543. }));
  544. }
  545. break;
  546. }
  547. case 0xA520://生产信息
  548. {
  549. unchecked
  550. {
  551. this.Invoke((EventHandler)(delegate
  552. {
  553. //生产商
  554. textBox_MAC.Text = "";
  555. for (ushort i = 0; i < 8; i++)
  556. {
  557. if (Data[i] == 0x2E)
  558. {
  559. break;
  560. }
  561. textBox_MAC.Text += ((char)Data[i]).ToString();
  562. }
  563. //生产地
  564. textBox_MACAdd.Text = "";
  565. for (ushort i = 0; i < 8; i++)
  566. {
  567. if (Data[8 + i] == 0x2E)
  568. {
  569. break;
  570. }
  571. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  572. }
  573. //生产日期
  574. textBox_MACDate.Text = "";
  575. for (ushort i = 0; i < 8; i++)
  576. {
  577. if (Data[16 + i] == 0x2E)
  578. {
  579. break;
  580. }
  581. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  582. }
  583. //品牌信息
  584. textBox_PP.Text = "";
  585. for (ushort i = 0; i < 8; i++)
  586. {
  587. if (Data[24 + i] == 0x2E)
  588. {
  589. break;
  590. }
  591. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  592. }
  593. }));
  594. }
  595. break;
  596. }
  597. case 0xA408://密钥
  598. {
  599. unchecked
  600. {
  601. this.Invoke((EventHandler)(delegate
  602. {
  603. textBox_Key.Text = "";
  604. for (ushort i = 0; i < 8; i++)
  605. {
  606. textBox_Key.Text += ((char)Data[i]).ToString();
  607. }
  608. }));
  609. }
  610. break;
  611. }
  612. case 0x1401://在线检测结果
  613. {
  614. unchecked
  615. {
  616. this.Invoke((EventHandler)(delegate
  617. {
  618. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper()+"H";
  619. }));
  620. }
  621. break;
  622. }
  623. default:break;
  624. }
  625. }
  626. #endregion
  627. }
  628. #endregion
  629. /// <summary>
  630. /// 端口连接事件
  631. /// </summary>
  632. /// <param name="sender"></param>
  633. /// <param name="e"></param>
  634. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  635. {
  636. bool result = false;
  637. if (连接ToolStripMenuItem.Text == "连接")
  638. {
  639. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text);
  640. if (result)
  641. {
  642. toolStripComboBox_ComNum.Enabled = false;
  643. toolStripComboBox_Baudrate.Enabled = false;
  644. 刷新ToolStripMenuItem.Enabled = false;
  645. 连接ToolStripMenuItem.Text = "断开";
  646. 连接ToolStripMenuItem.Checked = true;
  647. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  648. }
  649. }
  650. else if (连接ToolStripMenuItem.Text == "断开")
  651. {
  652. result = mySerialProcess.SerialClose();
  653. if (result)
  654. {
  655. toolStripComboBox_ComNum.Enabled = true;
  656. toolStripComboBox_Baudrate.Enabled = true;
  657. 刷新ToolStripMenuItem.Enabled = true;
  658. 连接ToolStripMenuItem.Text = "连接";
  659. 连接ToolStripMenuItem.Checked = false;
  660. label_COM_Sta.Text = "连接状态:未连接";
  661. }
  662. }
  663. }
  664. /// <summary>
  665. /// 端口号刷新事件
  666. /// </summary>
  667. /// <param name="sender"></param>
  668. /// <param name="e"></param>
  669. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  670. {
  671. toolStripComboBox_ComNum.Items.Clear();
  672. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  673. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  674. }
  675. /// <summary>
  676. /// 转速调节事件
  677. /// </summary>
  678. /// <param name="sender"></param>
  679. /// <param name="e"></param>
  680. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  681. {
  682. var Data = new byte[1];
  683. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  684. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  685. }
  686. /// <summary>
  687. /// 存储标志修改事件
  688. /// </summary>
  689. /// <param name="sender"></param>
  690. /// <param name="e"></param>
  691. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  692. {
  693. 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
  694. }
  695. /// <summary>
  696. /// 1s定时器
  697. /// </summary>
  698. /// <param name="sender"></param>
  699. /// <param name="e"></param>
  700. private void timer_1s_Tick(object sender, EventArgs e)
  701. {
  702. //时间更新
  703. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString();
  704. //MC_Runinfo超时清除
  705. if (MC_RunInfo_Refresh == false)
  706. {
  707. MC_RunInfo_Refresh_Cnt++;
  708. if (MC_RunInfo_Refresh_Cnt > 3)
  709. {
  710. MC_RunInfo_Clear();
  711. MC_RunInfo_Refresh_Cnt = 0;
  712. }
  713. }
  714. else
  715. {
  716. MC_RunInfo_Refresh_Cnt = 0;
  717. }
  718. MC_RunInfo_Refresh = false;
  719. //故障码超时清除
  720. if (MC_ErrorCode_Refresh == false)
  721. {
  722. MC_ErrorCode_Refresh_Cnt++;
  723. if (MC_ErrorCode_Refresh_Cnt > 50)
  724. {
  725. textBox_ErrorCode.Text = "---";
  726. MC_ErrorCode_Refresh_Cnt = 0;
  727. }
  728. }
  729. else
  730. {
  731. MC_ErrorCode_Refresh_Cnt = 0;
  732. }
  733. MC_ErrorCode_Refresh = false;
  734. //CDL连接超时
  735. #if false
  736. if (mySerialProcess.CDL_Online_Flag == false)
  737. {
  738. mySerialProcess.CDL_OnlineCheck_Cnt++;
  739. if (mySerialProcess.CDL_OnlineCheck_Cnt > 3)
  740. {
  741. timer_1s.Enabled = false;
  742. MessageBox.Show("连接失败!", "提示");
  743. timer_1s.Enabled = true;
  744. //关闭串口
  745. mySerialProcess.SerialClose();
  746. toolStripComboBox_ComNum.Enabled = true;
  747. toolStripComboBox_Baudrate.Enabled = true;
  748. 刷新ToolStripMenuItem.Enabled = true;
  749. 连接ToolStripMenuItem.Text = "连接";
  750. 连接ToolStripMenuItem.Checked = false;
  751. label_COM_Sta.Text = "连接状态:未连接";
  752. }
  753. }
  754. #endif
  755. }
  756. /// <summary>
  757. /// 运行信息清除
  758. /// </summary>
  759. private void MC_RunInfo_Clear()
  760. {
  761. foreach (Control c in groupBox2.Controls)
  762. {
  763. if ((c is TextBox))
  764. {
  765. if(c.Name != textBox_ErrorCode.ToString())
  766. c.Text = "---";
  767. }
  768. }
  769. }
  770. /// <summary>
  771. /// 读取马达参数
  772. /// </summary>
  773. /// <param name="sender"></param>
  774. /// <param name="e"></param>
  775. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  776. {
  777. richTextBox_MotorParam.Clear();
  778. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  779. }
  780. /// <summary>
  781. /// 写入马达参数
  782. /// </summary>
  783. /// <param name="sender"></param>
  784. /// <param name="e"></param>
  785. private void button_Write_Click(object sender, EventArgs e)
  786. {
  787. var ConfigParam = new byte[40];
  788. for (int i = 0; i < 40; i++)
  789. ConfigParam[i] = 0;
  790. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  791. ushort uwDataTemp = 0;
  792. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
  793. try
  794. {
  795. for (int i = 0; i < strDataTemp.Length; i++)
  796. {
  797. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  798. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  799. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  800. }
  801. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  802. }
  803. catch (Exception)
  804. {
  805. timer_1s.Enabled = false;
  806. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  807. timer_1s.Enabled = true;
  808. }
  809. }
  810. /// <summary>
  811. /// 读取整车信息
  812. /// </summary>
  813. /// <param name="sender"></param>
  814. /// <param name="e"></param>
  815. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  816. {
  817. richTextBox_BikeParam.Clear();
  818. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  819. }
  820. /// <summary>
  821. /// 写入整车信息
  822. /// </summary>
  823. /// <param name="sender"></param>
  824. /// <param name="e"></param>
  825. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  826. {
  827. var ConfigParam = new byte[26];
  828. for (int i = 0; i < 26; i++)
  829. ConfigParam[i] = 0;
  830. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  831. ushort uwDataTemp = 0;
  832. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  833. try
  834. {
  835. for (int i = 0; i < strDataTemp.Length; i++)
  836. {
  837. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  838. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  839. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  840. }
  841. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1A, ConfigParam);
  842. }
  843. catch (Exception)
  844. {
  845. timer_1s.Enabled = false;
  846. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  847. timer_1s.Enabled = true;
  848. }
  849. }
  850. /// <summary>
  851. /// 读取控制器参数
  852. /// </summary>
  853. /// <param name="sender"></param>
  854. /// <param name="e"></param>
  855. private void button_ReadControlParam_Click(object sender, EventArgs e)
  856. {
  857. richTextBox_ControlParam.Clear();
  858. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  859. }
  860. /// <summary>
  861. /// 写入控制器参数
  862. /// </summary>
  863. /// <param name="sender"></param>
  864. /// <param name="e"></param>
  865. private void button_WriteControlParam_Click(object sender, EventArgs e)
  866. {
  867. var ConfigParam = new byte[34];
  868. for (int i = 0; i < 34; i++)
  869. ConfigParam[i] = 0;
  870. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  871. ushort uwDataTemp = 0;
  872. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  873. try
  874. {
  875. for (int i = 0; i < strDataTemp.Length; i++)
  876. {
  877. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  878. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  879. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  880. }
  881. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  882. }
  883. catch (Exception)
  884. {
  885. timer_1s.Enabled = false;
  886. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  887. timer_1s.Enabled = true;
  888. }
  889. }
  890. /// <summary>
  891. /// 读取助力参数
  892. /// </summary>
  893. /// <param name="sender"></param>
  894. /// <param name="e"></param>
  895. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  896. {
  897. var ConfigParam = new byte[4];
  898. int AssistNum = 0;
  899. try
  900. {
  901. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  902. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  903. ConfigParam[1] = (byte)(AssistNum >> 8);
  904. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  905. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  906. ConfigParam[3] = (byte)(AssistNum >> 8);
  907. richTextBox_AssistParam.Clear();
  908. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  909. }
  910. catch (Exception)
  911. {
  912. timer_1s.Enabled = false;
  913. MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  914. timer_1s.Enabled = true;
  915. }
  916. }
  917. /// <summary>
  918. /// 写入助力参数
  919. /// </summary>
  920. /// <param name="sender"></param>
  921. /// <param name="e"></param>
  922. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  923. {
  924. var ConfigParam = new byte[80];
  925. for (int i = 0; i < 80; i++)
  926. ConfigParam[i] = 0;
  927. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  928. ulong ulDataTemp = 0;
  929. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  930. int index_1 = 0, index_2 = 0;
  931. try
  932. {
  933. for (int i = 0; i < strDataTemp.Length; i++)
  934. {
  935. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  936. {
  937. index_1 = i;
  938. break;
  939. }
  940. }
  941. for (int i = 0; i < strDataTemp.Length; i++)
  942. {
  943. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  944. {
  945. index_2 = i;
  946. break;
  947. }
  948. }
  949. for (int i = 0; i < strDataTemp.Length; i++)
  950. {
  951. ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
  952. if (i < index_1)
  953. {
  954. ConfigParam[2 * i + 4] = (byte)ulDataTemp;
  955. ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
  956. }
  957. else if (i <= index_2)
  958. {
  959. ConfigParam[4 * i - 4] = (byte)ulDataTemp;
  960. ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
  961. ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
  962. ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
  963. }
  964. else
  965. {
  966. ConfigParam[2 * i + 20] = (byte)ulDataTemp;
  967. ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
  968. }
  969. }
  970. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  971. }
  972. catch (Exception)
  973. {
  974. timer_1s.Enabled = false;
  975. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  976. timer_1s.Enabled = true;
  977. }
  978. }
  979. /// <summary>
  980. /// 读取调试参数
  981. /// </summary>
  982. /// <param name="sender"></param>
  983. /// <param name="e"></param>
  984. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  985. {
  986. richTextBox_DebugParam.Clear();
  987. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  988. }
  989. /// <summary>
  990. /// 写入调试参数
  991. /// </summary>
  992. /// <param name="sender"></param>
  993. /// <param name="e"></param>
  994. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  995. {
  996. var ConfigParam = new byte[52];
  997. for (int i = 0; i < 52; i++)
  998. ConfigParam[i] = 0;
  999. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1000. ushort uwDataTemp = 0;
  1001. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1002. try
  1003. {
  1004. for (int i = 0; i < strDataTemp.Length; i++)
  1005. {
  1006. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1007. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1008. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1009. }
  1010. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4634, ConfigParam);
  1011. }
  1012. catch (Exception)
  1013. {
  1014. timer_1s.Enabled = false;
  1015. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1016. timer_1s.Enabled = true;
  1017. }
  1018. }
  1019. /// <summary>
  1020. /// 读取历史
  1021. /// </summary>
  1022. /// <param name="sender"></param>
  1023. /// <param name="e"></param>
  1024. private void button_ReadRecord_Click(object sender, EventArgs e)
  1025. {
  1026. richTextBox_Record.Clear();
  1027. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  1028. }
  1029. /// <summary>
  1030. /// 读取传感器参数
  1031. /// </summary>
  1032. /// <param name="sender"></param>
  1033. /// <param name="e"></param>
  1034. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  1035. {
  1036. richTextBox_SensorParam.Clear();
  1037. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  1038. }
  1039. /// <summary>
  1040. /// 写入力矩传感器标定值
  1041. /// </summary>
  1042. /// <param name="sender"></param>
  1043. /// <param name="e"></param>
  1044. private void button_Write_Cal_Click(object sender, EventArgs e)
  1045. {
  1046. var ConfigParam = new byte[4];
  1047. for (int i = 0; i < 4; i++)
  1048. ConfigParam[i] = 0;
  1049. ushort uwDataTemp = 0;
  1050. try
  1051. {
  1052. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  1053. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  1054. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  1055. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  1056. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  1057. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  1058. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  1059. }
  1060. catch (Exception)
  1061. {
  1062. timer_1s.Enabled = false;
  1063. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1064. timer_1s.Enabled = true;
  1065. }
  1066. }
  1067. /// <summary>
  1068. /// 写入传感器参数
  1069. /// </summary>
  1070. /// <param name="sender"></param>
  1071. /// <param name="e"></param>
  1072. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  1073. {
  1074. var ConfigParam = new byte[14];
  1075. for (int i = 0; i < 14; i++)
  1076. ConfigParam[i] = 0;
  1077. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1078. ushort uwDataTemp = 0;
  1079. //传感器参数只写入最后2项
  1080. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(richTextBox_SensorParam.Text.LastIndexOf(", ", richTextBox_SensorParam.Text.LastIndexOf(", ") - 1) + 2);
  1081. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1082. try
  1083. {
  1084. for (int i = 0; i < strDataTemp.Length; i++)
  1085. {
  1086. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1087. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1088. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1089. }
  1090. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  1091. }
  1092. catch (Exception)
  1093. {
  1094. timer_1s.Enabled = false;
  1095. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1096. timer_1s.Enabled = true;
  1097. }
  1098. }
  1099. /// <summary>
  1100. /// 写入型号
  1101. /// </summary>
  1102. /// <param name="sender"></param>
  1103. /// <param name="e"></param>
  1104. private void button_WriteModel_Click(object sender, EventArgs e)
  1105. {
  1106. string Mode = textBox_Model.Text;
  1107. var ModeArray = new byte[16];
  1108. for (ushort i = 0; i < Mode.Length; i++)
  1109. {
  1110. ModeArray[i] = (byte)Mode[i];
  1111. }
  1112. if (Mode.Length < 16)
  1113. {
  1114. ModeArray[Mode.Length] = (byte)'.';
  1115. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  1116. {
  1117. ModeArray[Mode.Length + 1 + i] = 0x20;
  1118. }
  1119. }
  1120. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  1121. }
  1122. /// <summary>
  1123. /// 写入SN
  1124. /// </summary>
  1125. /// <param name="sender"></param>
  1126. /// <param name="e"></param>
  1127. private void button_WriteSN_Click(object sender, EventArgs e)
  1128. {
  1129. string SN = textBox_SN.Text;
  1130. var SNArray = new byte[16];
  1131. for (ushort i = 0; i < SN.Length; i++)
  1132. {
  1133. SNArray[i] = (byte)SN[i];
  1134. }
  1135. if (SN.Length < 16)
  1136. {
  1137. SNArray[SN.Length] = (byte)'.';
  1138. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  1139. {
  1140. SNArray[SN.Length + 1 + i] = 0x20;
  1141. }
  1142. }
  1143. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  1144. }
  1145. /// <summary>
  1146. /// 查询版本信息
  1147. /// </summary>
  1148. /// <param name="sender"></param>
  1149. /// <param name="e"></param>
  1150. private void button_ReadVersion_Click(object sender, EventArgs e)
  1151. {
  1152. textBox_Model.Text = "---";
  1153. textBox_SN.Text = "---";
  1154. textBox_HW.Text = "---";
  1155. textBox_FW.Text = "---";
  1156. Class_Motor_Ver.Mode = "---";
  1157. Class_Motor_Ver.SN = "---";
  1158. Class_Motor_Ver.HW = "---";
  1159. Class_Motor_Ver.FW = "---";
  1160. Class_Motor_Ver.Special = "---";
  1161. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  1162. }
  1163. /// <summary>
  1164. /// 查询自定义1
  1165. /// </summary>
  1166. /// <param name="sender"></param>
  1167. /// <param name="e"></param>
  1168. private void button_ReadUser1_Click(object sender, EventArgs e)
  1169. {
  1170. textBox_User1.Text = "---";
  1171. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  1172. }
  1173. /// <summary>
  1174. /// 查询自定义2
  1175. /// </summary>
  1176. /// <param name="sender"></param>
  1177. /// <param name="e"></param>
  1178. private void button_ReadUser2_Click(object sender, EventArgs e)
  1179. {
  1180. textBox_User2.Text = "---";
  1181. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  1182. }
  1183. /// <summary>
  1184. /// 查询自定义3
  1185. /// </summary>
  1186. /// <param name="sender"></param>
  1187. /// <param name="e"></param>
  1188. private void button_ReadUser3_Click(object sender, EventArgs e)
  1189. {
  1190. textBox_User3.Text = "---";
  1191. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  1192. }
  1193. /// <summary>
  1194. /// 写入自定义字符串1
  1195. /// </summary>
  1196. /// <param name="sender"></param>
  1197. /// <param name="e"></param>
  1198. private void button_WriteUser1_Click(object sender, EventArgs e)
  1199. {
  1200. string User = textBox_User1.Text;
  1201. var UserArray = new byte[16];
  1202. for (ushort i = 0; i < User.Length; i++)
  1203. {
  1204. UserArray[i] = (byte)User[i];
  1205. }
  1206. if (User.Length < 16)
  1207. {
  1208. UserArray[User.Length] = (byte)'.';
  1209. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1210. {
  1211. UserArray[User.Length + 1 + i] = 0x20;
  1212. }
  1213. }
  1214. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  1215. }
  1216. /// <summary>
  1217. /// 写入自定义字符串2
  1218. /// </summary>
  1219. /// <param name="sender"></param>
  1220. /// <param name="e"></param>
  1221. private void button_WriteUser2_Click(object sender, EventArgs e)
  1222. {
  1223. string User = textBox_User2.Text;
  1224. var UserArray = new byte[16];
  1225. for (ushort i = 0; i < User.Length; i++)
  1226. {
  1227. UserArray[i] = (byte)User[i];
  1228. }
  1229. if (User.Length < 16)
  1230. {
  1231. UserArray[User.Length] = (byte)'.';
  1232. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1233. {
  1234. UserArray[User.Length + 1 + i] = 0x20;
  1235. }
  1236. }
  1237. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  1238. }
  1239. /// <summary>
  1240. /// 写入自定义字符串3
  1241. /// </summary>
  1242. /// <param name="sender"></param>
  1243. /// <param name="e"></param>
  1244. private void button_WriteUser3_Click(object sender, EventArgs e)
  1245. {
  1246. string User = textBox_User3.Text;
  1247. var UserArray = new byte[16];
  1248. for (ushort i = 0; i < User.Length; i++)
  1249. {
  1250. UserArray[i] = (byte)User[i];
  1251. }
  1252. if (User.Length < 16)
  1253. {
  1254. UserArray[User.Length] = (byte)'.';
  1255. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1256. {
  1257. UserArray[User.Length + 1 + i] = 0x20;
  1258. }
  1259. }
  1260. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  1261. }
  1262. /// <summary>
  1263. /// 查询生产信息
  1264. /// </summary>
  1265. /// <param name="sender"></param>
  1266. /// <param name="e"></param>
  1267. private void button_ReadMAC_Click(object sender, EventArgs e)
  1268. {
  1269. textBox_MAC.Text = "---";
  1270. textBox_MACAdd.Text = "---";
  1271. textBox_MACDate.Text = "---";
  1272. textBox_PP.Text = "---";
  1273. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  1274. }
  1275. /// <summary>
  1276. /// 写入生产信息
  1277. /// </summary>
  1278. /// <param name="sender"></param>
  1279. /// <param name="e"></param>
  1280. private void button_WriteMac_Click(object sender, EventArgs e)
  1281. {
  1282. var MACArray = new byte[32];
  1283. //填入生产商
  1284. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  1285. {
  1286. MACArray[i] = (byte)textBox_MAC.Text[i];
  1287. }
  1288. if (textBox_MAC.Text.Length < 8)
  1289. {
  1290. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  1291. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  1292. {
  1293. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  1294. }
  1295. }
  1296. //填入生产地
  1297. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  1298. {
  1299. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  1300. }
  1301. if (textBox_MACAdd.Text.Length < 8)
  1302. {
  1303. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  1304. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  1305. {
  1306. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  1307. }
  1308. }
  1309. //填入生产日期
  1310. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  1311. {
  1312. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  1313. }
  1314. if (textBox_MACDate.Text.Length < 8)
  1315. {
  1316. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  1317. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  1318. {
  1319. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  1320. }
  1321. }
  1322. //填入品牌
  1323. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  1324. {
  1325. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  1326. }
  1327. if (textBox_PP.Text.Length < 8)
  1328. {
  1329. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  1330. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  1331. {
  1332. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  1333. }
  1334. }
  1335. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  1336. }
  1337. /// <summary>
  1338. /// 查询密钥
  1339. /// </summary>
  1340. /// <param name="sender"></param>
  1341. /// <param name="e"></param>
  1342. private void button_ReadKey_Click(object sender, EventArgs e)
  1343. {
  1344. textBox_Key.Text = "---";
  1345. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  1346. }
  1347. /// <summary>
  1348. /// 写入校验密钥
  1349. /// </summary>
  1350. /// <param name="sender"></param>
  1351. /// <param name="e"></param>
  1352. private void button_WriteKey_Click(object sender, EventArgs e)
  1353. {
  1354. string Key = textBox_Key.Text;
  1355. var KeyArray = new byte[8];
  1356. if (Key.Length != 8)
  1357. {
  1358. timer_1s.Enabled = false;
  1359. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1360. timer_1s.Enabled = true;
  1361. return;
  1362. }
  1363. for (ushort i = 0; i < Key.Length; i++)
  1364. {
  1365. KeyArray[i] = (byte)Key[i];
  1366. }
  1367. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  1368. }
  1369. /// <summary>
  1370. /// 查询在线检测结果
  1371. /// </summary>
  1372. /// <param name="sender"></param>
  1373. /// <param name="e"></param>
  1374. private void button_ReadOnLine_Click(object sender, EventArgs e)
  1375. {
  1376. textBox_Online.Text = "---";
  1377. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  1378. }
  1379. /// <summary>
  1380. /// 系统清除
  1381. /// </summary>
  1382. /// <param name="sender"></param>
  1383. /// <param name="e"></param>
  1384. private void button_SystemClear_Click(object sender, EventArgs e)
  1385. {
  1386. var Code = new byte[5];
  1387. Code[0] = (byte)'C';
  1388. Code[1] = (byte)'L';
  1389. Code[2] = (byte)'E';
  1390. Code[3] = (byte)'A';
  1391. Code[4] = (byte)'R';
  1392. timer_1s.Enabled = false;
  1393. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1394. {
  1395. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1396. {
  1397. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1398. {
  1399. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  1400. }
  1401. }
  1402. }
  1403. timer_1s.Enabled = true;
  1404. }
  1405. /// <summary>
  1406. /// 参数还原
  1407. /// </summary>
  1408. /// <param name="sender"></param>
  1409. /// <param name="e"></param>
  1410. private void button_Recovery_Click(object sender, EventArgs e)
  1411. {
  1412. var Code = new byte[8];
  1413. Code[0] = (byte)'R';
  1414. Code[1] = (byte)'E';
  1415. Code[2] = (byte)'C';
  1416. Code[3] = (byte)'O';
  1417. Code[4] = (byte)'V';
  1418. Code[5] = (byte)'E';
  1419. Code[6] = (byte)'R';
  1420. Code[7] = (byte)'Y';
  1421. timer_1s.Enabled = false;
  1422. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1423. {
  1424. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1425. {
  1426. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1427. {
  1428. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  1429. }
  1430. }
  1431. }
  1432. timer_1s.Enabled = true;
  1433. }
  1434. /// <summary>
  1435. /// 系统复位
  1436. /// </summary>
  1437. /// <param name="sender"></param>
  1438. /// <param name="e"></param>
  1439. private void button_Reset_Click(object sender, EventArgs e)
  1440. {
  1441. var Code = new byte[5];
  1442. Code[0] = (byte)'R';
  1443. Code[1] = (byte)'E';
  1444. Code[2] = (byte)'S';
  1445. Code[3] = (byte)'E';
  1446. Code[4] = (byte)'T';
  1447. timer_1s.Enabled = false;
  1448. if (MessageBox.Show("系统将重启", "确认重启?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1449. {
  1450. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  1451. }
  1452. timer_1s.Enabled = true;
  1453. }
  1454. /// <summary>
  1455. /// 记录清除
  1456. /// </summary>
  1457. /// <param name="sender"></param>
  1458. /// <param name="e"></param>
  1459. private void button_ClearLog_Click(object sender, EventArgs e)
  1460. {
  1461. var Code = new byte[9];
  1462. Code[0] = (byte)'L';
  1463. Code[1] = (byte)'O';
  1464. Code[2] = (byte)'G';
  1465. Code[3] = (byte)' ';
  1466. Code[4] = (byte)'C';
  1467. Code[5] = (byte)'L';
  1468. Code[6] = (byte)'E';
  1469. Code[7] = (byte)'A';
  1470. Code[8] = (byte)'R';
  1471. timer_1s.Enabled = false;
  1472. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1473. {
  1474. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1475. {
  1476. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1477. {
  1478. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  1479. }
  1480. }
  1481. }
  1482. timer_1s.Enabled = true;
  1483. }
  1484. /// <summary>
  1485. /// 打开系统计算器
  1486. /// </summary>
  1487. /// <param name="sender"></param>
  1488. /// <param name="e"></param>
  1489. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  1490. {
  1491. System.Diagnostics.Process.Start("calc.exe");
  1492. }
  1493. /// <summary>
  1494. ///故障转换和显示
  1495. /// </summary>
  1496. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  1497. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  1498. "",""};
  1499. private string ErrorInfoDisplay(UInt32 Code)
  1500. {
  1501. string Result = "";
  1502. if (Code == 0)
  1503. {
  1504. Result = "无故障";
  1505. }
  1506. else
  1507. {
  1508. for (int i = 0; i < 32; i++)
  1509. {
  1510. if ((Code & 0x01) == 0x01)
  1511. {
  1512. Result += ErrorInfo[i] + " ";
  1513. }
  1514. Code >>= 1;
  1515. }
  1516. }
  1517. return Result;
  1518. }
  1519. /// <summary>
  1520. /// 鼠标滑过故障码显示具体内容
  1521. /// </summary>
  1522. /// <param name="sender"></param>
  1523. /// <param name="e"></param>
  1524. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  1525. {
  1526. // 创建the ToolTip
  1527. ToolTip toolTip1 = new ToolTip();
  1528. // 设置显示样式
  1529. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  1530. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  1531. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  1532. toolTip1.ShowAlways = true;//是否显示提示框
  1533. // 设置伴随的对象.
  1534. string ErrorCode = this.textBox_ErrorCode.Text;
  1535. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  1536. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  1537. }
  1538. /// <summary>
  1539. /// 数据记录
  1540. /// </summary>
  1541. private void DataAutoSave()
  1542. {
  1543. if (记录数据ToolStripMenuItem.Checked == true)
  1544. {
  1545. if (SaveFilename == string.Empty)
  1546. {
  1547. return;
  1548. }
  1549. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_") + " ";
  1550. foreach (Control c in groupBox3.Controls)
  1551. {
  1552. if (c is TextBox)
  1553. {
  1554. SaveData += c.Text + " , ";
  1555. }
  1556. }
  1557. SaveData += "\r\n";
  1558. System.IO.File.AppendAllText(SaveFilename, SaveData);//sb.ToString());
  1559. }
  1560. }
  1561. /// <summary>
  1562. /// 打开或关闭数据记录
  1563. /// </summary>
  1564. /// <param name="sender"></param>
  1565. /// <param name="e"></param>
  1566. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  1567. {
  1568. if (记录数据ToolStripMenuItem.Checked == false)
  1569. {
  1570. if (mySerialProcess.mySerial.IsOpen == true)
  1571. {
  1572. SaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  1573. timer_1s.Enabled = false;
  1574. MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1575. timer_1s.Enabled = true;
  1576. 记录数据ToolStripMenuItem.Checked = true;
  1577. }
  1578. else
  1579. {
  1580. timer_1s.Enabled = false;
  1581. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1582. timer_1s.Enabled = true;
  1583. }
  1584. }
  1585. else
  1586. {
  1587. 记录数据ToolStripMenuItem.Checked = false;
  1588. timer_1s.Enabled = false;
  1589. MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1590. timer_1s.Enabled = true;
  1591. }
  1592. }
  1593. /// <summary>
  1594. /// 修改写入的助力力矩曲线编号
  1595. /// </summary>
  1596. /// <param name="sender"></param>
  1597. /// <param name="e"></param>
  1598. private void comboBox_AssistTorque_SelectionChangeCommitted(object sender, EventArgs e)
  1599. {
  1600. try
  1601. {
  1602. int DataNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  1603. int index_1 = richTextBox_AssistParam.Text.IndexOf("助力转矩曲线编号=") + "助力转矩曲线编号=".Length;
  1604. int index_2 = richTextBox_AssistParam.Text.IndexOf("助力踏频曲线编号");
  1605. richTextBox_AssistParam.Select(index_1, index_2 - index_1);
  1606. richTextBox_AssistParam.SelectedText = Convert.ToString(DataNum) + ", ";
  1607. }
  1608. catch (Exception)
  1609. {
  1610. timer_1s.Enabled = false;
  1611. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1612. timer_1s.Enabled = true;
  1613. }
  1614. }
  1615. /// <summary>
  1616. /// 修改写入的助力踏频曲线编号
  1617. /// </summary>
  1618. /// <param name="sender"></param>
  1619. /// <param name="e"></param>
  1620. private void comboBox_AssistCadence_SelectionChangeCommitted(object sender, EventArgs e)
  1621. {
  1622. try
  1623. {
  1624. int DataNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  1625. int index_1 = richTextBox_AssistParam.Text.IndexOf("助力踏频曲线编号=") + "助力踏频曲线编号=".Length;
  1626. int index_2 = richTextBox_AssistParam.Text.IndexOf("转矩曲线.a");
  1627. richTextBox_AssistParam.Select(index_1, index_2 - index_1);
  1628. richTextBox_AssistParam.SelectedText = Convert.ToString(DataNum) + ", ";
  1629. }
  1630. catch (Exception)
  1631. {
  1632. timer_1s.Enabled = false;
  1633. MessageBox.Show("数据格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1634. timer_1s.Enabled = true;
  1635. }
  1636. }
  1637. /// <summary>
  1638. /// 工作模式选择事件
  1639. /// </summary>
  1640. /// <param name="sender"></param>
  1641. /// <param name="e"></param>
  1642. private void comboBox_WorkMode_SelectionChangeCommitted(object sender, EventArgs e)
  1643. {
  1644. var RunMode = new byte[1];
  1645. if (comboBox_WorkMode.Text == "配置模式")
  1646. RunMode[0] = 0x01;
  1647. else
  1648. RunMode[0] = 0x00;
  1649. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  1650. }
  1651. /// <summary>
  1652. /// 助力档位选择事件
  1653. /// </summary>
  1654. /// <param name="sender"></param>
  1655. /// <param name="e"></param>
  1656. private void comboBox_GearSt_SelectionChangeCommitted(object sender, EventArgs e)
  1657. {
  1658. var CtrlCode = new byte[2];
  1659. if (comboBox_GearSt.SelectedIndex == 6)//档位
  1660. CtrlCode[0] = 0x22;
  1661. else
  1662. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  1663. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  1664. CtrlCode[1] = 0xF1;
  1665. else
  1666. CtrlCode[1] = 0xF0;
  1667. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  1668. }
  1669. }
  1670. }