Form1.cs 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297
  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. #endregion
  27. public Form1()
  28. {
  29. InitializeComponent();
  30. }
  31. private void Form1_Load(object sender, System.EventArgs e)
  32. {
  33. //页面初始化
  34. label_BuildTime.Text= "编译时间:"+ System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
  35. //下拉控件初始值设定
  36. comboBox_WorkMode.SelectedIndex = 0;
  37. comboBox_GearSt.SelectedIndex = 0;
  38. comboBox_LightSwitch.SelectedIndex = 1;
  39. comboBox_OBC_SetGearST.SelectedIndex = 0;
  40. comboBox_OBC_LightSw.SelectedIndex = 1;
  41. comboBox_AssistTorque.SelectedIndex = 0;
  42. comboBox_AssistCadence.SelectedIndex = 0;
  43. //combobox事件定义
  44. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  45. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  46. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  47. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  48. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  49. //端口设置
  50. mySerialProcess.Init();
  51. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  52. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  53. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
  54. //创建线程,定时解析数据
  55. Thread th = new Thread(Task_SerialProcess);
  56. th.IsBackground = true;
  57. th.Start();
  58. }
  59. #region 串口数据解析线程
  60. /// <summary>
  61. /// 串口数据解析线程
  62. /// </summary>
  63. private void Task_SerialProcess()
  64. {
  65. //创建定时器,定时读取串口数据
  66. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  67. timer_ReadSerial.Enabled = true;
  68. timer_ReadSerial.Interval = 20;
  69. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  70. timer_ReadSerial.Start();
  71. while (true)
  72. {
  73. Thread.Sleep(1);
  74. };
  75. }
  76. /// <summary>
  77. /// 串口解析定时器
  78. /// </summary>
  79. /// <param name="sender"></param>
  80. /// <param name="e"></param>
  81. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  82. {
  83. //串口解析
  84. Serial_process(mySerialProcess.buffer);
  85. }
  86. #endregion
  87. #region 数据解析
  88. public void Serial_process(List<byte> buffer)
  89. {
  90. byte DataNum = 0; //记录每条命令数据段的长度
  91. ushort PackageID, Cmd;
  92. byte[] Data = new byte[1024];
  93. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  94. {
  95. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  96. {
  97. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  98. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  99. {
  100. int CmdLen = buffer[5];
  101. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  102. buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
  103. while (CmdLen > 0) //读取命令段
  104. {
  105. Cmd = (ushort)(buffer[0] * 256 + buffer[1]);
  106. DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
  107. if (DataNum <= (CmdLen - 2))
  108. {
  109. for (int i = 0; i < DataNum; i++)
  110. {
  111. Data[i] = buffer[i + 2];
  112. }
  113. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  114. buffer.RemoveRange(0, DataNum);//移除处理过的数据段
  115. CmdLen -= (DataNum + 2);
  116. if (CmdLen < 2)
  117. {
  118. buffer.RemoveRange(0, CmdLen + 2);
  119. return;
  120. }
  121. }
  122. else
  123. {
  124. buffer.RemoveRange(0, CmdLen + 11);
  125. }
  126. }
  127. }
  128. else
  129. {
  130. buffer.RemoveAt(0);//ID不对
  131. }
  132. }
  133. else
  134. {
  135. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  136. }
  137. }
  138. }
  139. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  140. {
  141. int DataTemp;
  142. ushort uData16;
  143. unchecked
  144. {
  145. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  146. }
  147. #region 解析发送给CDL的指令
  148. if (ID == 0x7FF)
  149. {
  150. switch (CmdTemp)
  151. {
  152. case 0x1100://
  153. {
  154. unchecked
  155. {
  156. this.Invoke((EventHandler)(delegate
  157. {
  158. //CDL连接成功
  159. mySerialProcess.CDL_Online_Flag = true;
  160. MessageBox.Show("连接成功!", "提示");
  161. }));
  162. }
  163. break;
  164. }
  165. default: break;
  166. }
  167. }
  168. #endregion
  169. #region 解析电机的命令
  170. else if ((ID == 0x715) || (ID == 0x710))
  171. {
  172. switch (CmdTemp)
  173. {
  174. case 0x1020://电机运行信息
  175. {
  176. unchecked
  177. {
  178. this.Invoke((EventHandler)(delegate
  179. {
  180. MC_RunInfo_Refresh = true;
  181. //车速
  182. DataTemp = (int)(Data[1] * 256 + Data[0]);
  183. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  184. //输出转速
  185. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  186. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  187. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  188. Class_MotorSpeed.Data = DataTemp;
  189. //电功率
  190. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  191. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp * 2) + " W";
  192. //母线电压
  193. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  194. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  195. //母线电流
  196. DataTemp = (ushort)(Data[9] * 256 + Data[8]);
  197. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  198. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  199. Class_CurrentData.Data = DataTemp;
  200. //踏频
  201. DataTemp = (ushort)(Data[10]);
  202. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  203. //踩踏力矩
  204. DataTemp = (ushort)(Data[11]);
  205. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  206. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  207. Class_TorqueData.Data = DataTemp;
  208. //踩踏方向
  209. DataTemp = (ushort)(Data[12]);
  210. if (DataTemp == 0)
  211. {
  212. textBox_RunInfo_Dir.Text = "正向";
  213. }
  214. else if (DataTemp == 1)
  215. {
  216. textBox_RunInfo_Dir.Text = "反向";
  217. }
  218. else if (DataTemp == 2)
  219. {
  220. textBox_RunInfo_Dir.Text = "停止";
  221. }
  222. //助力档位
  223. DataTemp = (ushort)(Data[13]);
  224. if (DataTemp == 0x33)
  225. {
  226. textBox_RunInfo_GearSt.Text = "SMART";
  227. //comboBox_GearSt.SelectedIndex = 5;
  228. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  229. }
  230. else if (DataTemp == 0x22)
  231. {
  232. textBox_RunInfo_GearSt.Text = "WALK";
  233. //comboBox_GearSt.SelectedIndex = 6;
  234. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  235. }
  236. else
  237. {
  238. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  239. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  240. //comboBox_GearSt.SelectedIndex = DataTemp;
  241. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  242. }
  243. //大灯状态
  244. DataTemp = (ushort)(Data[14]);
  245. if (DataTemp == 0xF0)
  246. {
  247. textBox_RunInfo_LightSwitch.Text = "OFF";
  248. //comboBox_LightSwitch.SelectedIndex = 1;
  249. //comboBox_OBC_LightSw.SelectedIndex = 1;
  250. }
  251. else if (DataTemp == 0xF1)
  252. {
  253. textBox_RunInfo_LightSwitch.Text = "ON";
  254. //comboBox_LightSwitch.SelectedIndex = 0;
  255. //comboBox_OBC_LightSw.SelectedIndex = 0;
  256. }
  257. //剩余电量
  258. DataTemp = (ushort)(Data[15]);
  259. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  260. //剩余续航里程
  261. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  262. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  263. {
  264. textBox_RunInfo_Range.Text = "---";
  265. }
  266. else
  267. {
  268. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  269. }
  270. //预留,空2bytes
  271. //平均功耗
  272. DataTemp = (ushort)(Data[20]);
  273. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  274. //PCB温度
  275. DataTemp = (ushort)(Data[21]);
  276. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40));
  277. //绕组温度
  278. DataTemp = (ushort)(Data[22]);
  279. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40));
  280. //MCU温度
  281. DataTemp = (ushort)(Data[23]);
  282. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40));
  283. //单次里程
  284. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  285. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  286. //单次时间
  287. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  288. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  289. //数据保存
  290. DataAutoSave();
  291. }));
  292. }
  293. break;
  294. }
  295. case 0x1104://故障码
  296. {
  297. unchecked
  298. {
  299. this.Invoke((EventHandler)(delegate
  300. {
  301. MC_ErrorCode_Refresh = true;
  302. textBox_ErrorCode.Text =
  303. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  304. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  305. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  306. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  307. "H";
  308. }));
  309. }
  310. break;
  311. }
  312. case 0xA903://反馈指令
  313. {
  314. unchecked
  315. {
  316. this.Invoke((EventHandler)(delegate
  317. {
  318. timer_1s.Enabled = false;
  319. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  320. timer_1s.Enabled = true;
  321. }));
  322. }
  323. break;
  324. }
  325. case 0xB226://马达参数
  326. {
  327. unchecked
  328. {
  329. this.Invoke((EventHandler)(delegate
  330. {
  331. richTextBox_MotorParam.Clear();
  332. for (int i = 0; i < myParams.MotorParma.Count; i++)
  333. {
  334. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  335. }
  336. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  337. }));
  338. }
  339. break;
  340. }
  341. case 0xB31A://整车信息
  342. {
  343. unchecked
  344. {
  345. this.Invoke((EventHandler)(delegate
  346. {
  347. richTextBox_BikeParam.Clear();
  348. for (int i = 0; i < myParams.BikeParma.Count; i++)
  349. {
  350. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  351. }
  352. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  353. }));
  354. }
  355. break;
  356. }
  357. case 0xB420://控制器参数
  358. {
  359. unchecked
  360. {
  361. this.Invoke((EventHandler)(delegate
  362. {
  363. richTextBox_ControlParam.Clear();
  364. for (int i = 0; i < myParams.ControlParma.Count; i++)
  365. {
  366. richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  367. }
  368. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  369. }));
  370. }
  371. break;
  372. }
  373. case 0xB528://传感器参数
  374. {
  375. unchecked
  376. {
  377. this.Invoke((EventHandler)(delegate
  378. {
  379. richTextBox_SensorParam.Clear();
  380. for (int i = 0; i < myParams.SensorParam.Count; i++)
  381. {
  382. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  383. }
  384. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  385. }));
  386. }
  387. break;
  388. }
  389. case 0xB64C://助力参数
  390. {
  391. unchecked
  392. {
  393. this.Invoke((EventHandler)(delegate
  394. {
  395. richTextBox_AssistParam.Clear();
  396. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  397. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  398. for (int i = 0; i < myParams.AssistParam.Count; i++)
  399. {
  400. if (i < index_1) //数据占用2bytes
  401. {
  402. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  403. }
  404. else if (i <= index_2) //数据占用4bytes
  405. {
  406. 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]) + ", ");
  407. }
  408. else //数据占用2bytes
  409. {
  410. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString(Data[2 * i + 17] * 256 + Data[2 * i + 16]) + ", ");
  411. }
  412. }
  413. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  414. }));
  415. }
  416. break;
  417. }
  418. case 0xB74C://历史记录
  419. {
  420. unchecked
  421. {
  422. this.Invoke((EventHandler)(delegate
  423. {
  424. richTextBox_Record.Clear();
  425. for (int i = 0; i < myParams.Record.Count; i++)
  426. {
  427. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  428. }
  429. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  430. }));
  431. }
  432. break;
  433. }
  434. case 0xB83A://调试参数
  435. {
  436. unchecked
  437. {
  438. this.Invoke((EventHandler)(delegate
  439. {
  440. richTextBox_DebugParam.Clear();
  441. for (int i = 0; i < myParams.DebugParam.Count; i++)
  442. {
  443. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  444. }
  445. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  446. }));
  447. }
  448. break;
  449. }
  450. case 0xB904://存储标志
  451. {
  452. unchecked
  453. {
  454. this.Invoke((EventHandler)(delegate
  455. {
  456. ushort Flag = 0;
  457. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  458. if (Flag == 0)
  459. {
  460. radioButton_EE_SaveNo.Checked = true;
  461. radioButton_EE_SaveYes.Checked = false;
  462. }
  463. else
  464. {
  465. radioButton_EE_SaveNo.Checked = false;
  466. radioButton_EE_SaveYes.Checked = true;
  467. }
  468. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  469. if (Flag == 0)
  470. {
  471. radioButton_SIP_SaveNo.Checked = true;
  472. radioButton_SIP_SaveYes.Checked = false;
  473. }
  474. else
  475. {
  476. radioButton_SIP_SaveNo.Checked = false;
  477. radioButton_SIP_SaveYes.Checked = true;
  478. }
  479. }));
  480. }
  481. break;
  482. }
  483. case 0x1240://电机版本信息
  484. {
  485. unchecked
  486. {
  487. this.Invoke((EventHandler)(delegate
  488. {
  489. //电机型号
  490. textBox_Model.Text = "";
  491. textBox_OBC_ReadModel.Text = "";
  492. for (ushort i = 0; i < 16; i++)
  493. {
  494. if (Data[i] == 0x2E)
  495. {
  496. break;
  497. }
  498. textBox_Model.Text += ((char)Data[i]).ToString();
  499. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  500. }
  501. Class_Motor_Ver.Mode = textBox_Model.Text;
  502. //电机SN
  503. textBox_SN.Text = "";
  504. textBox_OBC_ReadSN.Text = "";
  505. for (ushort i = 0; i < 16; i++)
  506. {
  507. if (Data[16 + i] == 0x2E)
  508. {
  509. break;
  510. }
  511. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  512. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  513. }
  514. Class_Motor_Ver.SN = textBox_SN.Text;
  515. //电机HW
  516. textBox_HW.Text = "";
  517. textBox_OBC_ReadHW.Text = "";
  518. for (ushort i = 0; i < 16; i++)
  519. {
  520. if (Data[32 + i] == 0x2E)
  521. {
  522. break;
  523. }
  524. textBox_HW.Text += ((char)Data[32 + i]).ToString();
  525. textBox_OBC_ReadHW.Text += ((char)Data[32 + i]).ToString();
  526. }
  527. Class_Motor_Ver.HW = textBox_HW.Text;
  528. //电机FW
  529. textBox_FW.Text = "";
  530. textBox_OBC_ReadFW.Text = "";
  531. for (ushort i = 0; i < 16; i++)
  532. {
  533. if (Data[48 + i] == 0x2E)
  534. {
  535. break;
  536. }
  537. if (Data[48 + i] == 'r')
  538. {
  539. Data[48 + i] = (byte)'.';
  540. }
  541. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  542. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  543. }
  544. Class_Motor_Ver.FW = textBox_FW.Text;
  545. }));
  546. }
  547. break;
  548. }
  549. case 0xA610://自定义1
  550. {
  551. unchecked
  552. {
  553. this.Invoke((EventHandler)(delegate
  554. {
  555. textBox_User1.Text = "";
  556. for (ushort i = 0; i < 16; i++)
  557. {
  558. if (Data[i] == 0x2E)
  559. {
  560. break;
  561. }
  562. textBox_User1.Text += ((char)Data[i]).ToString();
  563. }
  564. }));
  565. }
  566. break;
  567. }
  568. case 0xA710://自定义2
  569. {
  570. unchecked
  571. {
  572. this.Invoke((EventHandler)(delegate
  573. {
  574. textBox_User2.Text = "";
  575. for (ushort i = 0; i < 16; i++)
  576. {
  577. if (Data[i] == 0x2E)
  578. {
  579. break;
  580. }
  581. textBox_User2.Text += ((char)Data[i]).ToString();
  582. }
  583. }));
  584. }
  585. break;
  586. }
  587. case 0xA810://自定义1
  588. {
  589. unchecked
  590. {
  591. this.Invoke((EventHandler)(delegate
  592. {
  593. textBox_User3.Text = "";
  594. for (ushort i = 0; i < 16; i++)
  595. {
  596. if (Data[i] == 0x2E)
  597. {
  598. break;
  599. }
  600. textBox_User3.Text += ((char)Data[i]).ToString();
  601. }
  602. }));
  603. }
  604. break;
  605. }
  606. case 0xA520://生产信息
  607. {
  608. unchecked
  609. {
  610. this.Invoke((EventHandler)(delegate
  611. {
  612. //生产商
  613. textBox_MAC.Text = "";
  614. for (ushort i = 0; i < 8; i++)
  615. {
  616. if (Data[i] == 0x2E)
  617. {
  618. break;
  619. }
  620. textBox_MAC.Text += ((char)Data[i]).ToString();
  621. }
  622. //生产地
  623. textBox_MACAdd.Text = "";
  624. for (ushort i = 0; i < 8; i++)
  625. {
  626. if (Data[8 + i] == 0x2E)
  627. {
  628. break;
  629. }
  630. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  631. }
  632. //生产日期
  633. textBox_MACDate.Text = "";
  634. for (ushort i = 0; i < 8; i++)
  635. {
  636. if (Data[16 + i] == 0x2E)
  637. {
  638. break;
  639. }
  640. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  641. }
  642. //品牌信息
  643. textBox_PP.Text = "";
  644. for (ushort i = 0; i < 8; i++)
  645. {
  646. if (Data[24 + i] == 0x2E)
  647. {
  648. break;
  649. }
  650. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  651. }
  652. }));
  653. }
  654. break;
  655. }
  656. case 0xA408://密钥
  657. {
  658. unchecked
  659. {
  660. this.Invoke((EventHandler)(delegate
  661. {
  662. textBox_Key.Text = "";
  663. for (ushort i = 0; i < 8; i++)
  664. {
  665. textBox_Key.Text += ((char)Data[i]).ToString();
  666. }
  667. }));
  668. }
  669. break;
  670. }
  671. case 0x1401://在线检测结果
  672. {
  673. unchecked
  674. {
  675. this.Invoke((EventHandler)(delegate
  676. {
  677. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  678. }));
  679. }
  680. break;
  681. }
  682. case 0x1510://骑行历史信息
  683. {
  684. unchecked
  685. {
  686. this.Invoke((EventHandler)(delegate
  687. {
  688. long DataTemp32;
  689. //ODO里程
  690. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  691. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  692. //ODO时间
  693. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  694. if (DataTemp32 >= 60 * 100000)
  695. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  696. else
  697. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  698. //TRIP里程
  699. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  700. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  701. //TRIP时间
  702. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  703. if (DataTemp32 >= 60 * 100000)
  704. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  705. else
  706. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  707. }));
  708. }
  709. break;
  710. }
  711. default:
  712. {
  713. unchecked
  714. {
  715. if ((CmdTemp & 0xFF00) == 0xAB00) //返回指定地址存储器数据
  716. {
  717. this.Invoke((EventHandler)(delegate
  718. {
  719. long ByteNum = 0;
  720. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  721. for (int i = 0; i < ByteNum; i++)
  722. {
  723. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  724. }
  725. }));
  726. }
  727. }
  728. break;
  729. }
  730. }
  731. }
  732. #endregion
  733. #region 解析BMS广播的命令
  734. else if (ID == 0x720)
  735. {
  736. switch (CmdTemp)
  737. {
  738. case 0x1010://BMS运行信息
  739. {
  740. unchecked
  741. {
  742. this.Invoke((EventHandler)(delegate
  743. {
  744. BMS_RunInfo_Refresh = true;
  745. richTextBox_OBC_BMS_RunInfo.Clear();
  746. //电压
  747. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  748. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  749. //电流
  750. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  751. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  752. //剩余容量
  753. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  754. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  755. //满充容量
  756. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  757. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mV" + "\r\n");
  758. //电芯温度
  759. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  760. //剩余电量
  761. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  762. //电池状态
  763. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  764. //SOH
  765. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
  766. }));
  767. }
  768. break;
  769. }
  770. default: break;
  771. }
  772. }
  773. #endregion
  774. #region 解析电机发送OBC的命令
  775. else if (ID == 0x713)
  776. {
  777. switch (CmdTemp)
  778. {
  779. case 0x5408://电机用户参数
  780. {
  781. unchecked
  782. {
  783. this.Invoke((EventHandler)(delegate
  784. {
  785. richTextBox_OBC_ReadUserInfo.Clear();
  786. //默认周长
  787. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  788. //启动模式
  789. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  790. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  791. //限速
  792. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  793. //周长微调
  794. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  795. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  796. //助力方案
  797. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  798. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  799. //关机时间
  800. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  801. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  802. }));
  803. }
  804. break;
  805. }
  806. case 0x5303://电机应答反馈
  807. {
  808. unchecked
  809. {
  810. this.Invoke((EventHandler)(delegate
  811. {
  812. timer_1s.Enabled = false;
  813. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  814. timer_1s.Enabled = true;
  815. }));
  816. }
  817. break;
  818. }
  819. default: break;
  820. }
  821. }
  822. #endregion
  823. }
  824. #endregion
  825. /// <summary>
  826. /// 端口连接事件
  827. /// </summary>
  828. /// <param name="sender"></param>
  829. /// <param name="e"></param>
  830. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  831. {
  832. bool result = false;
  833. if (连接ToolStripMenuItem.Text == "连接")
  834. {
  835. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text);
  836. if (result)
  837. {
  838. toolStripComboBox_ComNum.Enabled = false;
  839. toolStripComboBox_Baudrate.Enabled = false;
  840. 刷新ToolStripMenuItem.Enabled = false;
  841. 连接ToolStripMenuItem.Text = "断开";
  842. 连接ToolStripMenuItem.Checked = true;
  843. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  844. }
  845. }
  846. else if (连接ToolStripMenuItem.Text == "断开")
  847. {
  848. checkBox_OBC_StartSetGearSt.Checked = false;
  849. mySerialProcess.SerialClose();
  850. toolStripComboBox_ComNum.Enabled = true;
  851. toolStripComboBox_Baudrate.Enabled = true;
  852. 刷新ToolStripMenuItem.Enabled = true;
  853. 连接ToolStripMenuItem.Text = "连接";
  854. 连接ToolStripMenuItem.Checked = false;
  855. label_COM_Sta.Text = "连接状态:未连接";
  856. }
  857. }
  858. /// <summary>
  859. /// 端口号刷新事件
  860. /// </summary>
  861. /// <param name="sender"></param>
  862. /// <param name="e"></param>
  863. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  864. {
  865. toolStripComboBox_ComNum.Items.Clear();
  866. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  867. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  868. }
  869. /// <summary>
  870. /// 转速调节事件
  871. /// </summary>
  872. /// <param name="sender"></param>
  873. /// <param name="e"></param>
  874. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  875. {
  876. var Data = new byte[1];
  877. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  878. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  879. }
  880. /// <summary>
  881. /// 存储标志修改事件
  882. /// </summary>
  883. /// <param name="sender"></param>
  884. /// <param name="e"></param>
  885. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  886. {
  887. 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
  888. }
  889. /// <summary>
  890. /// 1s定时器
  891. /// </summary>
  892. /// <param name="sender"></param>
  893. /// <param name="e"></param>
  894. private void timer_1s_Tick(object sender, EventArgs e)
  895. {
  896. //时间更新
  897. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString();
  898. //MC_Runinfo超时清除
  899. if (MC_RunInfo_Refresh == false)
  900. {
  901. MC_RunInfo_Refresh_Cnt++;
  902. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  903. {
  904. MC_RunInfo_Clear();
  905. MC_RunInfo_Refresh_Cnt = 0;
  906. }
  907. }
  908. else
  909. {
  910. MC_RunInfo_Refresh_Cnt = 0;
  911. }
  912. MC_RunInfo_Refresh = false;
  913. //BMS_RunInfo超时清除
  914. if (BMS_RunInfo_Refresh == false)
  915. {
  916. BMS_RunInfo_Refresh_Cnt++;
  917. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  918. {
  919. richTextBox_OBC_BMS_RunInfo.Clear();
  920. BMS_RunInfo_Refresh_Cnt = 0;
  921. }
  922. }
  923. else
  924. {
  925. BMS_RunInfo_Refresh_Cnt = 0;
  926. }
  927. BMS_RunInfo_Refresh = false;
  928. //故障码超时清除
  929. if (MC_ErrorCode_Refresh == false)
  930. {
  931. MC_ErrorCode_Refresh_Cnt++;
  932. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  933. {
  934. textBox_ErrorCode.Text = "---";
  935. MC_ErrorCode_Refresh_Cnt = 0;
  936. }
  937. }
  938. else
  939. {
  940. MC_ErrorCode_Refresh_Cnt = 0;
  941. }
  942. MC_ErrorCode_Refresh = false;
  943. //CDL连接超时
  944. #if false
  945. if (mySerialProcess.CDL_Online_Flag == false)
  946. {
  947. mySerialProcess.CDL_OnlineCheck_Cnt++;
  948. if (mySerialProcess.CDL_OnlineCheck_Cnt > 3)//3s
  949. {
  950. timer_1s.Enabled = false;
  951. MessageBox.Show("连接失败!", "提示");
  952. timer_1s.Enabled = true;
  953. //关闭串口
  954. mySerialProcess.SerialClose();
  955. toolStripComboBox_ComNum.Enabled = true;
  956. toolStripComboBox_Baudrate.Enabled = true;
  957. 刷新ToolStripMenuItem.Enabled = true;
  958. 连接ToolStripMenuItem.Text = "连接";
  959. 连接ToolStripMenuItem.Checked = false;
  960. label_COM_Sta.Text = "连接状态:未连接";
  961. }
  962. }
  963. #endif
  964. //OBC定时发送设置档位
  965. if (checkBox_OBC_StartSetGearSt.Checked == true)
  966. {
  967. var CtrlCode = new byte[2];
  968. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  969. CtrlCode[0] = 0x33;
  970. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  971. CtrlCode[0] = 0x22;
  972. else
  973. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  974. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  975. CtrlCode[1] = 0xF1;
  976. else
  977. CtrlCode[1] = 0xF0;
  978. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  979. {
  980. checkBox_OBC_StartSetGearSt.Checked = false;
  981. }
  982. }
  983. //OBC定时发送查询电池
  984. if (checkBox_OBC_StartReadBMS.Checked == true)
  985. {
  986. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  987. {
  988. checkBox_OBC_StartReadBMS.Checked = false;
  989. }
  990. }
  991. }
  992. /// <summary>
  993. /// 运行信息清除
  994. /// </summary>
  995. private void MC_RunInfo_Clear()
  996. {
  997. foreach (Control c in groupBox2.Controls)
  998. {
  999. if ((c is TextBox))
  1000. {
  1001. if(c.Name != textBox_ErrorCode.ToString())
  1002. c.Text = "---";
  1003. }
  1004. }
  1005. }
  1006. /// <summary>
  1007. /// 读取马达参数
  1008. /// </summary>
  1009. /// <param name="sender"></param>
  1010. /// <param name="e"></param>
  1011. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  1012. {
  1013. richTextBox_MotorParam.Clear();
  1014. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  1015. }
  1016. /// <summary>
  1017. /// 写入马达参数
  1018. /// </summary>
  1019. /// <param name="sender"></param>
  1020. /// <param name="e"></param>
  1021. private void button_Write_Click(object sender, EventArgs e)
  1022. {
  1023. var ConfigParam = new byte[40];
  1024. for (int i = 0; i < 40; i++)
  1025. ConfigParam[i] = 0;
  1026. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1027. ushort uwDataTemp = 0;
  1028. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
  1029. try
  1030. {
  1031. for (int i = 0; i < strDataTemp.Length; i++)
  1032. {
  1033. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1034. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1035. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1036. }
  1037. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  1038. }
  1039. catch (Exception)
  1040. {
  1041. timer_1s.Enabled = false;
  1042. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1043. timer_1s.Enabled = true;
  1044. }
  1045. }
  1046. /// <summary>
  1047. /// 读取整车信息
  1048. /// </summary>
  1049. /// <param name="sender"></param>
  1050. /// <param name="e"></param>
  1051. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  1052. {
  1053. richTextBox_BikeParam.Clear();
  1054. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  1055. }
  1056. /// <summary>
  1057. /// 写入整车信息
  1058. /// </summary>
  1059. /// <param name="sender"></param>
  1060. /// <param name="e"></param>
  1061. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  1062. {
  1063. var ConfigParam = new byte[28];
  1064. for (int i = 0; i < 28; i++)
  1065. ConfigParam[i] = 0;
  1066. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1067. ushort uwDataTemp = 0;
  1068. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1069. try
  1070. {
  1071. for (int i = 0; i < strDataTemp.Length; i++)
  1072. {
  1073. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1074. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1075. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1076. }
  1077. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  1078. }
  1079. catch (Exception)
  1080. {
  1081. timer_1s.Enabled = false;
  1082. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1083. timer_1s.Enabled = true;
  1084. }
  1085. }
  1086. /// <summary>
  1087. /// 读取控制器参数
  1088. /// </summary>
  1089. /// <param name="sender"></param>
  1090. /// <param name="e"></param>
  1091. private void button_ReadControlParam_Click(object sender, EventArgs e)
  1092. {
  1093. richTextBox_ControlParam.Clear();
  1094. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  1095. }
  1096. /// <summary>
  1097. /// 写入控制器参数
  1098. /// </summary>
  1099. /// <param name="sender"></param>
  1100. /// <param name="e"></param>
  1101. private void button_WriteControlParam_Click(object sender, EventArgs e)
  1102. {
  1103. var ConfigParam = new byte[34];
  1104. for (int i = 0; i < 34; i++)
  1105. ConfigParam[i] = 0;
  1106. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1107. ushort uwDataTemp = 0;
  1108. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1109. try
  1110. {
  1111. for (int i = 0; i < strDataTemp.Length; i++)
  1112. {
  1113. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1114. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1115. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1116. }
  1117. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  1118. }
  1119. catch (Exception)
  1120. {
  1121. timer_1s.Enabled = false;
  1122. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1123. timer_1s.Enabled = true;
  1124. }
  1125. }
  1126. /// <summary>
  1127. /// 读取助力参数
  1128. /// </summary>
  1129. /// <param name="sender"></param>
  1130. /// <param name="e"></param>
  1131. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  1132. {
  1133. var ConfigParam = new byte[4];
  1134. int AssistNum = 0;
  1135. try
  1136. {
  1137. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  1138. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  1139. ConfigParam[1] = (byte)(AssistNum >> 8);
  1140. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  1141. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  1142. ConfigParam[3] = (byte)(AssistNum >> 8);
  1143. richTextBox_AssistParam.Clear();
  1144. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  1145. }
  1146. catch (Exception)
  1147. {
  1148. timer_1s.Enabled = false;
  1149. MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  1150. timer_1s.Enabled = true;
  1151. }
  1152. }
  1153. /// <summary>
  1154. /// 写入助力参数
  1155. /// </summary>
  1156. /// <param name="sender"></param>
  1157. /// <param name="e"></param>
  1158. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  1159. {
  1160. var ConfigParam = new byte[80];
  1161. for (int i = 0; i < 80; i++)
  1162. ConfigParam[i] = 0;
  1163. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1164. ulong ulDataTemp = 0;
  1165. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1166. int index_1 = 0, index_2 = 0;
  1167. try
  1168. {
  1169. for (int i = 0; i < strDataTemp.Length; i++)
  1170. {
  1171. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  1172. {
  1173. index_1 = i;
  1174. break;
  1175. }
  1176. }
  1177. for (int i = 0; i < strDataTemp.Length; i++)
  1178. {
  1179. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  1180. {
  1181. index_2 = i;
  1182. break;
  1183. }
  1184. }
  1185. for (int i = 0; i < strDataTemp.Length; i++)
  1186. {
  1187. ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
  1188. if (i < index_1)
  1189. {
  1190. ConfigParam[2 * i + 4] = (byte)ulDataTemp;
  1191. ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
  1192. }
  1193. else if (i <= index_2)
  1194. {
  1195. ConfigParam[4 * i - 4] = (byte)ulDataTemp;
  1196. ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
  1197. ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
  1198. ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
  1199. }
  1200. else
  1201. {
  1202. ConfigParam[2 * i + 20] = (byte)ulDataTemp;
  1203. ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
  1204. }
  1205. }
  1206. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  1207. }
  1208. catch (Exception)
  1209. {
  1210. timer_1s.Enabled = false;
  1211. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1212. timer_1s.Enabled = true;
  1213. }
  1214. }
  1215. /// <summary>
  1216. /// 读取调试参数
  1217. /// </summary>
  1218. /// <param name="sender"></param>
  1219. /// <param name="e"></param>
  1220. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  1221. {
  1222. richTextBox_DebugParam.Clear();
  1223. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  1224. }
  1225. /// <summary>
  1226. /// 写入调试参数
  1227. /// </summary>
  1228. /// <param name="sender"></param>
  1229. /// <param name="e"></param>
  1230. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  1231. {
  1232. var ConfigParam = new byte[60];
  1233. for (int i = 0; i < 60; i++)
  1234. ConfigParam[i] = 0;
  1235. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1236. ushort uwDataTemp = 0;
  1237. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1238. try
  1239. {
  1240. for (int i = 0; i < strDataTemp.Length; i++)
  1241. {
  1242. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1243. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1244. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1245. }
  1246. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  1247. }
  1248. catch (Exception)
  1249. {
  1250. timer_1s.Enabled = false;
  1251. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1252. timer_1s.Enabled = true;
  1253. }
  1254. }
  1255. /// <summary>
  1256. /// 读取历史
  1257. /// </summary>
  1258. /// <param name="sender"></param>
  1259. /// <param name="e"></param>
  1260. private void button_ReadRecord_Click(object sender, EventArgs e)
  1261. {
  1262. richTextBox_Record.Clear();
  1263. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  1264. }
  1265. /// <summary>
  1266. /// 读取传感器参数
  1267. /// </summary>
  1268. /// <param name="sender"></param>
  1269. /// <param name="e"></param>
  1270. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  1271. {
  1272. richTextBox_SensorParam.Clear();
  1273. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  1274. }
  1275. /// <summary>
  1276. /// 写入力矩传感器标定值
  1277. /// </summary>
  1278. /// <param name="sender"></param>
  1279. /// <param name="e"></param>
  1280. private void button_Write_Cal_Click(object sender, EventArgs e)
  1281. {
  1282. var ConfigParam = new byte[4];
  1283. for (int i = 0; i < 4; i++)
  1284. ConfigParam[i] = 0;
  1285. ushort uwDataTemp = 0;
  1286. try
  1287. {
  1288. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  1289. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  1290. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  1291. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  1292. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  1293. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  1294. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  1295. }
  1296. catch (Exception)
  1297. {
  1298. timer_1s.Enabled = false;
  1299. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1300. timer_1s.Enabled = true;
  1301. }
  1302. }
  1303. /// <summary>
  1304. /// 写入传感器参数
  1305. /// </summary>
  1306. /// <param name="sender"></param>
  1307. /// <param name="e"></param>
  1308. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  1309. {
  1310. var ConfigParam = new byte[14];
  1311. for (int i = 0; i < 14; i++)
  1312. ConfigParam[i] = 0;
  1313. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1314. ushort uwDataTemp = 0;
  1315. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  1316. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1317. int index = 0;
  1318. try
  1319. {
  1320. for (int i = 0; i < strDataTemp.Length; i++)
  1321. {
  1322. if (strDataTemp[i].Split('=')[0] == "踏频传感器一圈脉冲数")
  1323. {
  1324. index = i;
  1325. break;
  1326. }
  1327. }
  1328. for (int i = 0; i < (strDataTemp.Length - index); i++)
  1329. {
  1330. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  1331. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1332. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1333. }
  1334. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  1335. }
  1336. catch (Exception)
  1337. {
  1338. timer_1s.Enabled = false;
  1339. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1340. timer_1s.Enabled = true;
  1341. }
  1342. }
  1343. /// <summary>
  1344. /// 写入型号
  1345. /// </summary>
  1346. /// <param name="sender"></param>
  1347. /// <param name="e"></param>
  1348. private void button_WriteModel_Click(object sender, EventArgs e)
  1349. {
  1350. string Mode = textBox_Model.Text;
  1351. var ModeArray = new byte[16];
  1352. for (ushort i = 0; i < Mode.Length; i++)
  1353. {
  1354. ModeArray[i] = (byte)Mode[i];
  1355. }
  1356. if (Mode.Length < 16)
  1357. {
  1358. ModeArray[Mode.Length] = (byte)'.';
  1359. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  1360. {
  1361. ModeArray[Mode.Length + 1 + i] = 0x20;
  1362. }
  1363. }
  1364. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  1365. }
  1366. /// <summary>
  1367. /// 写入SN
  1368. /// </summary>
  1369. /// <param name="sender"></param>
  1370. /// <param name="e"></param>
  1371. private void button_WriteSN_Click(object sender, EventArgs e)
  1372. {
  1373. string SN = textBox_SN.Text;
  1374. var SNArray = new byte[16];
  1375. for (ushort i = 0; i < SN.Length; i++)
  1376. {
  1377. SNArray[i] = (byte)SN[i];
  1378. }
  1379. if (SN.Length < 16)
  1380. {
  1381. SNArray[SN.Length] = (byte)'.';
  1382. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  1383. {
  1384. SNArray[SN.Length + 1 + i] = 0x20;
  1385. }
  1386. }
  1387. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  1388. }
  1389. /// <summary>
  1390. /// 查询版本信息
  1391. /// </summary>
  1392. /// <param name="sender"></param>
  1393. /// <param name="e"></param>
  1394. private void button_ReadVersion_Click(object sender, EventArgs e)
  1395. {
  1396. textBox_Model.Text = "---";
  1397. textBox_SN.Text = "---";
  1398. textBox_HW.Text = "---";
  1399. textBox_FW.Text = "---";
  1400. textBox_OBC_ReadModel.Text = "---";
  1401. textBox_OBC_ReadSN.Text = "---";
  1402. textBox_OBC_ReadHW.Text = "---";
  1403. textBox_OBC_ReadFW.Text = "---";
  1404. Class_Motor_Ver.Mode = "---";
  1405. Class_Motor_Ver.SN = "---";
  1406. Class_Motor_Ver.HW = "---";
  1407. Class_Motor_Ver.FW = "---";
  1408. Class_Motor_Ver.Special = "---";
  1409. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  1410. }
  1411. /// <summary>
  1412. /// 查询自定义1
  1413. /// </summary>
  1414. /// <param name="sender"></param>
  1415. /// <param name="e"></param>
  1416. private void button_ReadUser1_Click(object sender, EventArgs e)
  1417. {
  1418. textBox_User1.Text = "---";
  1419. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  1420. }
  1421. /// <summary>
  1422. /// 查询自定义2
  1423. /// </summary>
  1424. /// <param name="sender"></param>
  1425. /// <param name="e"></param>
  1426. private void button_ReadUser2_Click(object sender, EventArgs e)
  1427. {
  1428. textBox_User2.Text = "---";
  1429. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  1430. }
  1431. /// <summary>
  1432. /// 查询自定义3
  1433. /// </summary>
  1434. /// <param name="sender"></param>
  1435. /// <param name="e"></param>
  1436. private void button_ReadUser3_Click(object sender, EventArgs e)
  1437. {
  1438. textBox_User3.Text = "---";
  1439. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  1440. }
  1441. /// <summary>
  1442. /// 写入自定义字符串1
  1443. /// </summary>
  1444. /// <param name="sender"></param>
  1445. /// <param name="e"></param>
  1446. private void button_WriteUser1_Click(object sender, EventArgs e)
  1447. {
  1448. string User = textBox_User1.Text;
  1449. var UserArray = new byte[16];
  1450. for (ushort i = 0; i < User.Length; i++)
  1451. {
  1452. UserArray[i] = (byte)User[i];
  1453. }
  1454. if (User.Length < 16)
  1455. {
  1456. UserArray[User.Length] = (byte)'.';
  1457. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1458. {
  1459. UserArray[User.Length + 1 + i] = 0x20;
  1460. }
  1461. }
  1462. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  1463. }
  1464. /// <summary>
  1465. /// 写入自定义字符串2
  1466. /// </summary>
  1467. /// <param name="sender"></param>
  1468. /// <param name="e"></param>
  1469. private void button_WriteUser2_Click(object sender, EventArgs e)
  1470. {
  1471. string User = textBox_User2.Text;
  1472. var UserArray = new byte[16];
  1473. for (ushort i = 0; i < User.Length; i++)
  1474. {
  1475. UserArray[i] = (byte)User[i];
  1476. }
  1477. if (User.Length < 16)
  1478. {
  1479. UserArray[User.Length] = (byte)'.';
  1480. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1481. {
  1482. UserArray[User.Length + 1 + i] = 0x20;
  1483. }
  1484. }
  1485. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  1486. }
  1487. /// <summary>
  1488. /// 写入自定义字符串3
  1489. /// </summary>
  1490. /// <param name="sender"></param>
  1491. /// <param name="e"></param>
  1492. private void button_WriteUser3_Click(object sender, EventArgs e)
  1493. {
  1494. string User = textBox_User3.Text;
  1495. var UserArray = new byte[16];
  1496. for (ushort i = 0; i < User.Length; i++)
  1497. {
  1498. UserArray[i] = (byte)User[i];
  1499. }
  1500. if (User.Length < 16)
  1501. {
  1502. UserArray[User.Length] = (byte)'.';
  1503. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1504. {
  1505. UserArray[User.Length + 1 + i] = 0x20;
  1506. }
  1507. }
  1508. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  1509. }
  1510. /// <summary>
  1511. /// 查询生产信息
  1512. /// </summary>
  1513. /// <param name="sender"></param>
  1514. /// <param name="e"></param>
  1515. private void button_ReadMAC_Click(object sender, EventArgs e)
  1516. {
  1517. textBox_MAC.Text = "---";
  1518. textBox_MACAdd.Text = "---";
  1519. textBox_MACDate.Text = "---";
  1520. textBox_PP.Text = "---";
  1521. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  1522. }
  1523. /// <summary>
  1524. /// 写入生产信息
  1525. /// </summary>
  1526. /// <param name="sender"></param>
  1527. /// <param name="e"></param>
  1528. private void button_WriteMac_Click(object sender, EventArgs e)
  1529. {
  1530. var MACArray = new byte[32];
  1531. //填入生产商
  1532. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  1533. {
  1534. MACArray[i] = (byte)textBox_MAC.Text[i];
  1535. }
  1536. if (textBox_MAC.Text.Length < 8)
  1537. {
  1538. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  1539. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  1540. {
  1541. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  1542. }
  1543. }
  1544. //填入生产地
  1545. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  1546. {
  1547. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  1548. }
  1549. if (textBox_MACAdd.Text.Length < 8)
  1550. {
  1551. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  1552. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  1553. {
  1554. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  1555. }
  1556. }
  1557. //填入生产日期
  1558. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  1559. {
  1560. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  1561. }
  1562. if (textBox_MACDate.Text.Length < 8)
  1563. {
  1564. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  1565. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  1566. {
  1567. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  1568. }
  1569. }
  1570. //填入品牌
  1571. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  1572. {
  1573. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  1574. }
  1575. if (textBox_PP.Text.Length < 8)
  1576. {
  1577. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  1578. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  1579. {
  1580. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  1581. }
  1582. }
  1583. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  1584. }
  1585. /// <summary>
  1586. /// 查询密钥
  1587. /// </summary>
  1588. /// <param name="sender"></param>
  1589. /// <param name="e"></param>
  1590. private void button_ReadKey_Click(object sender, EventArgs e)
  1591. {
  1592. textBox_Key.Text = "---";
  1593. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  1594. }
  1595. /// <summary>
  1596. /// 写入校验密钥
  1597. /// </summary>
  1598. /// <param name="sender"></param>
  1599. /// <param name="e"></param>
  1600. private void button_WriteKey_Click(object sender, EventArgs e)
  1601. {
  1602. string Key = textBox_Key.Text;
  1603. var KeyArray = new byte[8];
  1604. if (Key.Length != 8)
  1605. {
  1606. timer_1s.Enabled = false;
  1607. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1608. timer_1s.Enabled = true;
  1609. return;
  1610. }
  1611. for (ushort i = 0; i < Key.Length; i++)
  1612. {
  1613. KeyArray[i] = (byte)Key[i];
  1614. }
  1615. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  1616. }
  1617. /// <summary>
  1618. /// 查询在线检测结果
  1619. /// </summary>
  1620. /// <param name="sender"></param>
  1621. /// <param name="e"></param>
  1622. private void button_ReadOnLine_Click(object sender, EventArgs e)
  1623. {
  1624. textBox_Online.Text = "---";
  1625. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  1626. }
  1627. /// <summary>
  1628. /// 系统清除
  1629. /// </summary>
  1630. /// <param name="sender"></param>
  1631. /// <param name="e"></param>
  1632. private void button_SystemClear_Click(object sender, EventArgs e)
  1633. {
  1634. var Code = new byte[5];
  1635. Code[0] = (byte)'C';
  1636. Code[1] = (byte)'L';
  1637. Code[2] = (byte)'E';
  1638. Code[3] = (byte)'A';
  1639. Code[4] = (byte)'R';
  1640. timer_1s.Enabled = false;
  1641. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1642. {
  1643. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1644. {
  1645. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1646. {
  1647. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  1648. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1649. }
  1650. }
  1651. }
  1652. timer_1s.Enabled = true;
  1653. }
  1654. /// <summary>
  1655. /// 参数还原
  1656. /// </summary>
  1657. /// <param name="sender"></param>
  1658. /// <param name="e"></param>
  1659. private void button_Recovery_Click(object sender, EventArgs e)
  1660. {
  1661. var Code = new byte[8];
  1662. Code[0] = (byte)'R';
  1663. Code[1] = (byte)'E';
  1664. Code[2] = (byte)'C';
  1665. Code[3] = (byte)'O';
  1666. Code[4] = (byte)'V';
  1667. Code[5] = (byte)'E';
  1668. Code[6] = (byte)'R';
  1669. Code[7] = (byte)'Y';
  1670. timer_1s.Enabled = false;
  1671. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1672. {
  1673. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1674. {
  1675. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1676. {
  1677. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  1678. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1679. }
  1680. }
  1681. }
  1682. timer_1s.Enabled = true;
  1683. }
  1684. /// <summary>
  1685. /// 系统复位
  1686. /// </summary>
  1687. /// <param name="sender"></param>
  1688. /// <param name="e"></param>
  1689. private void button_Reset_Click(object sender, EventArgs e)
  1690. {
  1691. var Code = new byte[5];
  1692. Code[0] = (byte)'R';
  1693. Code[1] = (byte)'E';
  1694. Code[2] = (byte)'S';
  1695. Code[3] = (byte)'E';
  1696. Code[4] = (byte)'T';
  1697. timer_1s.Enabled = false;
  1698. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1699. {
  1700. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  1701. }
  1702. timer_1s.Enabled = true;
  1703. }
  1704. /// <summary>
  1705. /// 记录清除
  1706. /// </summary>
  1707. /// <param name="sender"></param>
  1708. /// <param name="e"></param>
  1709. private void button_ClearLog_Click(object sender, EventArgs e)
  1710. {
  1711. var Code = new byte[9];
  1712. Code[0] = (byte)'L';
  1713. Code[1] = (byte)'O';
  1714. Code[2] = (byte)'G';
  1715. Code[3] = (byte)' ';
  1716. Code[4] = (byte)'C';
  1717. Code[5] = (byte)'L';
  1718. Code[6] = (byte)'E';
  1719. Code[7] = (byte)'A';
  1720. Code[8] = (byte)'R';
  1721. timer_1s.Enabled = false;
  1722. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1723. {
  1724. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1725. {
  1726. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1727. {
  1728. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  1729. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1730. }
  1731. }
  1732. }
  1733. timer_1s.Enabled = true;
  1734. }
  1735. /// <summary>
  1736. /// 打开系统计算器
  1737. /// </summary>
  1738. /// <param name="sender"></param>
  1739. /// <param name="e"></param>
  1740. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  1741. {
  1742. System.Diagnostics.Process.Start("calc.exe");
  1743. }
  1744. /// <summary>
  1745. ///故障转换和显示
  1746. /// </summary>
  1747. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  1748. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  1749. "",""};
  1750. private string ErrorInfoDisplay(UInt32 Code)
  1751. {
  1752. string Result = "";
  1753. if (Code == 0)
  1754. {
  1755. Result = "无故障";
  1756. }
  1757. else
  1758. {
  1759. for (int i = 0; i < 32; i++)
  1760. {
  1761. if ((Code & 0x01) == 0x01)
  1762. {
  1763. Result += ErrorInfo[i] + " ";
  1764. }
  1765. Code >>= 1;
  1766. }
  1767. }
  1768. return Result;
  1769. }
  1770. /// <summary>
  1771. /// 鼠标滑过故障码显示具体内容
  1772. /// </summary>
  1773. /// <param name="sender"></param>
  1774. /// <param name="e"></param>
  1775. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  1776. {
  1777. // 创建the ToolTip
  1778. ToolTip toolTip1 = new ToolTip();
  1779. // 设置显示样式
  1780. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  1781. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  1782. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  1783. toolTip1.ShowAlways = true;//是否显示提示框
  1784. // 设置伴随的对象.
  1785. string ErrorCode = this.textBox_ErrorCode.Text;
  1786. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  1787. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  1788. }
  1789. /// <summary>
  1790. /// 数据记录
  1791. /// </summary>
  1792. private void DataAutoSave()
  1793. {
  1794. if (记录数据ToolStripMenuItem.Checked == true)
  1795. {
  1796. if (SaveFilename == string.Empty)
  1797. {
  1798. return;
  1799. }
  1800. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_") + " ";
  1801. foreach (Control c in groupBox3.Controls)
  1802. {
  1803. if (c is TextBox)
  1804. {
  1805. SaveData += c.Text + " , ";
  1806. }
  1807. }
  1808. SaveData += "\r\n";
  1809. System.IO.File.AppendAllText(SaveFilename, SaveData);//sb.ToString());
  1810. }
  1811. }
  1812. /// <summary>
  1813. /// 打开或关闭数据记录
  1814. /// </summary>
  1815. /// <param name="sender"></param>
  1816. /// <param name="e"></param>
  1817. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  1818. {
  1819. if (记录数据ToolStripMenuItem.Checked == false)
  1820. {
  1821. if (mySerialProcess.mySerial.IsOpen == true)
  1822. {
  1823. SaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  1824. timer_1s.Enabled = false;
  1825. MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1826. timer_1s.Enabled = true;
  1827. 记录数据ToolStripMenuItem.Checked = true;
  1828. }
  1829. else
  1830. {
  1831. timer_1s.Enabled = false;
  1832. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1833. timer_1s.Enabled = true;
  1834. }
  1835. }
  1836. else
  1837. {
  1838. 记录数据ToolStripMenuItem.Checked = false;
  1839. timer_1s.Enabled = false;
  1840. MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1841. timer_1s.Enabled = true;
  1842. }
  1843. }
  1844. /// <summary>
  1845. /// 仪表启动控制档位开关事件
  1846. /// </summary>
  1847. /// <param name="sender"></param>
  1848. /// <param name="e"></param>
  1849. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  1850. {
  1851. if (checkBox_OBC_StartSetGearSt.Checked == true)
  1852. {
  1853. //检查串口是否打开
  1854. if (!mySerialProcess.mySerial.IsOpen)
  1855. {
  1856. timer_1s.Enabled = false;
  1857. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1858. timer_1s.Enabled = true;
  1859. checkBox_OBC_StartSetGearSt.Checked = false;
  1860. return;
  1861. }
  1862. //检查是否选择档位和打开车灯
  1863. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  1864. {
  1865. timer_1s.Enabled = false;
  1866. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1867. timer_1s.Enabled = true;
  1868. checkBox_OBC_StartSetGearSt.Checked = false;
  1869. return;
  1870. }
  1871. }
  1872. }
  1873. /// <summary>
  1874. /// OBC查询电机用户参数
  1875. /// </summary>
  1876. /// <param name="sender"></param>
  1877. /// <param name="e"></param>
  1878. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  1879. {
  1880. richTextBox_OBC_ReadUserInfo.Clear();
  1881. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  1882. }
  1883. /// <summary>
  1884. /// OBC设置电机用户参数
  1885. /// </summary>
  1886. /// <param name="sender"></param>
  1887. /// <param name="e"></param>
  1888. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  1889. {
  1890. var UserInfoCode = new byte[8];
  1891. for (int i = 0; i < UserInfoCode.Length; i++)
  1892. UserInfoCode[i] = 0;
  1893. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  1894. {
  1895. timer_1s.Enabled = false;
  1896. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1897. timer_1s.Enabled = true;
  1898. return;
  1899. }
  1900. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  1901. {
  1902. timer_1s.Enabled = false;
  1903. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1904. timer_1s.Enabled = true;
  1905. return;
  1906. }
  1907. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  1908. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  1909. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  1910. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  1911. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  1912. }
  1913. /// <summary>
  1914. /// OBC查询电机版本信息
  1915. /// </summary>
  1916. /// <param name="sender"></param>
  1917. /// <param name="e"></param>
  1918. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  1919. {
  1920. textBox_Model.Text = "---";
  1921. textBox_SN.Text = "---";
  1922. textBox_HW.Text = "---";
  1923. textBox_FW.Text = "---";
  1924. textBox_OBC_ReadModel.Text = "---";
  1925. textBox_OBC_ReadSN.Text = "---";
  1926. textBox_OBC_ReadHW.Text = "---";
  1927. textBox_OBC_ReadFW.Text = "---";
  1928. Class_Motor_Ver.Mode = "---";
  1929. Class_Motor_Ver.SN = "---";
  1930. Class_Motor_Ver.HW = "---";
  1931. Class_Motor_Ver.FW = "---";
  1932. Class_Motor_Ver.Special = "---";
  1933. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  1934. }
  1935. /// <summary>
  1936. /// OBC读取骑行历史
  1937. /// </summary>
  1938. /// <param name="sender"></param>
  1939. /// <param name="e"></param>
  1940. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  1941. {
  1942. textBox_OBC_TRIP_KM.Text = "";
  1943. textBox_OBC_TRIP_TIME.Text = "";
  1944. textBox_OBC_ODO_KM.Text = "";
  1945. textBox_OBC_ODO_TIME.Text = "";
  1946. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  1947. }
  1948. /// <summary>
  1949. /// OBC清除TRIP里程
  1950. /// </summary>
  1951. /// <param name="sender"></param>
  1952. /// <param name="e"></param>
  1953. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  1954. {
  1955. var Code = new byte[5];
  1956. Code[0] = (byte)'C';
  1957. Code[1] = (byte)'L';
  1958. Code[2] = (byte)'E';
  1959. Code[3] = (byte)'A';
  1960. Code[4] = (byte)'R';
  1961. timer_1s.Enabled = false;
  1962. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1963. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  1964. timer_1s.Enabled = true;
  1965. }
  1966. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  1967. {
  1968. if (checkBox_OBC_StartReadBMS.Checked == true)
  1969. {
  1970. //检查串口是否打开
  1971. if (!mySerialProcess.mySerial.IsOpen)
  1972. {
  1973. timer_1s.Enabled = false;
  1974. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1975. timer_1s.Enabled = true;
  1976. checkBox_OBC_StartReadBMS.Checked = false;
  1977. return;
  1978. }
  1979. }
  1980. }
  1981. /// <summary>
  1982. /// 写入力矩传感器参数
  1983. /// </summary>
  1984. /// <param name="sender"></param>
  1985. /// <param name="e"></param>
  1986. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  1987. {
  1988. var ConfigParam = new byte[46];
  1989. for (int i = 0; i < 14; i++)
  1990. ConfigParam[i] = 0;
  1991. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1992. ushort uwDataTemp = 0;
  1993. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  1994. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1995. int index = 0;
  1996. try
  1997. {
  1998. for (int i = 0; i < strDataTemp.Length; i++)
  1999. {
  2000. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  2001. {
  2002. index = i;
  2003. break;
  2004. }
  2005. }
  2006. for (int i = 0; i < (index + 1); i++)
  2007. {
  2008. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2009. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2010. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2011. }
  2012. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  2013. }
  2014. catch (Exception)
  2015. {
  2016. timer_1s.Enabled = false;
  2017. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2018. timer_1s.Enabled = true;
  2019. }
  2020. }
  2021. /// <summary>
  2022. /// 查询存储标志
  2023. /// </summary>
  2024. /// <param name="sender"></param>
  2025. /// <param name="e"></param>
  2026. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  2027. {
  2028. radioButton_EE_SaveYes.Checked = false;
  2029. radioButton_EE_SaveNo.Checked = false;
  2030. radioButton_SIP_SaveYes.Checked = false;
  2031. radioButton_SIP_SaveNo.Checked = false;
  2032. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  2033. }
  2034. /// <summary>
  2035. /// 写入存储标志
  2036. /// </summary>
  2037. /// <param name="sender"></param>
  2038. /// <param name="e"></param>
  2039. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  2040. {
  2041. var SaveFlag = new byte[6];
  2042. for (int i = 0; i < 6; i++)
  2043. SaveFlag[i] = 0;
  2044. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  2045. {
  2046. timer_1s.Enabled = false;
  2047. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2048. timer_1s.Enabled = true;
  2049. return;
  2050. }
  2051. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  2052. {
  2053. timer_1s.Enabled = false;
  2054. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2055. timer_1s.Enabled = true;
  2056. return;
  2057. }
  2058. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  2059. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  2060. SaveFlag[3] = 0;
  2061. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  2062. SaveFlag[5] = 0;
  2063. timer_1s.Enabled = false;
  2064. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2065. {
  2066. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  2067. }
  2068. timer_1s.Enabled = true;
  2069. }
  2070. /// <summary>
  2071. /// 读取指定地址数据
  2072. /// </summary>
  2073. /// <param name="sender"></param>
  2074. /// <param name="e"></param>
  2075. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  2076. {
  2077. var Address = new byte[4];
  2078. UInt32 Address_Begin;
  2079. UInt32 Addres_End;
  2080. richTextBox_RamFlasgData.Clear();
  2081. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2082. {
  2083. timer_1s.Enabled = false;
  2084. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2085. timer_1s.Enabled = true;
  2086. return;
  2087. }
  2088. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2089. {
  2090. timer_1s.Enabled = false;
  2091. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2092. timer_1s.Enabled = true;
  2093. return;
  2094. }
  2095. else
  2096. {
  2097. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2098. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2099. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2100. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2101. if (Addres_End < Address_Begin)
  2102. {
  2103. timer_1s.Enabled = false;
  2104. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2105. timer_1s.Enabled = true;
  2106. return;
  2107. }
  2108. else
  2109. {
  2110. var SendByte = new byte[8];
  2111. SendByte[0] = (byte)(Address_Begin >> 24);
  2112. SendByte[1] = (byte)(Address_Begin >> 16);
  2113. SendByte[2] = (byte)(Address_Begin >> 8);
  2114. SendByte[3] = (byte)(Address_Begin);
  2115. SendByte[4] = (byte)(Addres_End >> 24);
  2116. SendByte[5] = (byte)(Addres_End >> 16);
  2117. SendByte[6] = (byte)(Addres_End >> 8);
  2118. SendByte[7] = (byte)(Addres_End);
  2119. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  2120. }
  2121. }
  2122. }
  2123. /// <summary>
  2124. /// 工作模式选择
  2125. /// </summary>
  2126. /// <param name="sender"></param>
  2127. /// <param name="e"></param>
  2128. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  2129. {
  2130. var RunMode = new byte[1];
  2131. if (comboBox_WorkMode.Text == "配置模式")
  2132. RunMode[0] = 0x01;
  2133. else
  2134. RunMode[0] = 0x00;
  2135. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2136. }
  2137. /// <summary>
  2138. /// 助力档位选择
  2139. /// </summary>
  2140. /// <param name="sender"></param>
  2141. /// <param name="e"></param>
  2142. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  2143. {
  2144. var CtrlCode = new byte[2];
  2145. if (comboBox_GearSt.SelectedIndex == 5)//档位
  2146. CtrlCode[0] = 0x33;
  2147. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  2148. CtrlCode[0] = 0x22;
  2149. else
  2150. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  2151. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  2152. CtrlCode[1] = 0xF1;
  2153. else
  2154. CtrlCode[1] = 0xF0;
  2155. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  2156. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  2157. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  2158. }
  2159. /// <summary>
  2160. /// 仪表档位选择
  2161. /// </summary>
  2162. /// <param name="sender"></param>
  2163. /// <param name="e"></param>
  2164. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  2165. {
  2166. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  2167. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  2168. }
  2169. }
  2170. }