GenerateParams.cs 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.Remoting.Messaging;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using static System.Net.WebRequestMethods;
  17. namespace Welling_Motor_Debug_Tool
  18. {
  19. public partial class GenerateParams : Form
  20. {
  21. //存储路径文件
  22. LocalInfo localInfo = new LocalInfo();
  23. //服务器配置
  24. string IP, Port, User, PassWD, ModelPath, CfgPath;
  25. //FTP
  26. ftp myFtp = new ftp();
  27. //高级参数修改标志
  28. bool WriteLockStatus = true;
  29. public GenerateParams()
  30. {
  31. InitializeComponent();
  32. }
  33. private void button_NoteRead_Click(object sender, EventArgs e)
  34. {
  35. //检查本地文件删除
  36. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  37. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  38. //下载远程文件
  39. myFtp.DownloadFile("/Note/Note.txt", localInfo.LocalPath);
  40. //显示文件
  41. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.NoteFileName);
  42. string sLine = "";
  43. ArrayList arrText = new ArrayList();//创建一个动态数组
  44. while (sLine != null)
  45. {
  46. sLine = objReader.ReadLine();
  47. arrText.Add(sLine);
  48. }
  49. objReader.Close();
  50. richTextBox_Note.Clear();
  51. foreach (string sOutput in arrText)
  52. {
  53. richTextBox_Note.AppendText(sOutput + "\r\n");
  54. }
  55. richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1);
  56. }
  57. private void button_NoteWrite_Click(object sender, EventArgs e)
  58. {
  59. //检查本地并删除
  60. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  61. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  62. //保存
  63. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, richTextBox_Note.Text);
  64. //上传服务器
  65. if (!myFtp.DirectoryExist("/", "Note"))
  66. myFtp.MakeDir("/Note");
  67. bool result = myFtp.UploadFile(localInfo.LocalPath + localInfo.NoteFileName, "/Note");
  68. if (result)
  69. MessageBox.Show("上传完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  70. else
  71. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  72. }
  73. private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  74. {
  75. //选中备忘录时自动读取更新
  76. if (tabControl1.SelectedIndex == 2)
  77. {
  78. //检查本地文件删除
  79. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  80. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  81. //下载远程文件
  82. myFtp.DownloadFile("/Note/Note.txt", localInfo.LocalPath);
  83. //显示文件
  84. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.NoteFileName);
  85. string sLine = "";
  86. ArrayList arrText = new ArrayList();//创建一个动态数组
  87. while (sLine != null)
  88. {
  89. sLine = objReader.ReadLine();
  90. arrText.Add(sLine);
  91. }
  92. objReader.Close();
  93. richTextBox_Note.Clear();
  94. foreach (string sOutput in arrText)
  95. {
  96. richTextBox_Note.AppendText(sOutput + "\r\n");
  97. }
  98. richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1);
  99. }
  100. //高级参数只读
  101. richTextBox_AdvanceParams.ReadOnly = true;
  102. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  103. WriteLockStatus = true;
  104. }
  105. private void radioButton_MIGIC_Click(object sender, EventArgs e)
  106. {
  107. textBox_ProductTag.Text = "MM_MC1";
  108. comboBox_SysRunMode.Items.Clear();
  109. comboBox_SysRunMode.Items.Add("CITY");
  110. comboBox_SysRunMode.Items.Add("MTB");
  111. }
  112. private void radioButton_HUB_Click(object sender, EventArgs e)
  113. {
  114. textBox_ProductTag.Text = "GF_250_1";
  115. comboBox_SysRunMode.Items.Clear();
  116. comboBox_SysRunMode.Items.Add("踏频");
  117. comboBox_SysRunMode.Items.Add("力矩");
  118. }
  119. private void comboBox_SysRunMode_Click(object sender, EventArgs e)
  120. {
  121. if ((radioButton_MIGIC.Checked | radioButton_HUB.Checked) == false)
  122. {
  123. MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  124. }
  125. }
  126. private void button_ChangeModelFile_Click(object sender, EventArgs e)
  127. {
  128. string DataFileName = "";
  129. string FileInfo = "";
  130. if (comboBox_ModelFile.SelectedIndex == -1)
  131. {
  132. MessageBox.Show("未选择模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  133. return;
  134. }
  135. if (MessageBox.Show("确认修改模板?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  136. {
  137. return;
  138. }
  139. //填写文件名
  140. DataFileName = comboBox_ModelFile.Text;
  141. //分割参数更新参数内容
  142. string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
  143. try
  144. {
  145. //更新信息
  146. do
  147. {
  148. //建立字典,存放并获取每个命令的行号
  149. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  150. DicRowNum.Add("[整车参数]", 0);
  151. DicRowNum.Add("[控制参数]", 0);
  152. DicRowNum.Add("[助力参数]", 0);
  153. DicRowNum.Add("[调试参数]", 0);
  154. DicRowNum.Add("[生产信息]", 0);
  155. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  156. foreach (KeyValuePair<string, int> item in __dict)
  157. {
  158. for (int i = 0; i < lines.Length; i++)
  159. {
  160. if (lines[i].Contains(item.Key))
  161. {
  162. DicRowNum[item.Key] = i;
  163. break;
  164. }
  165. }
  166. }
  167. //遍历更新
  168. foreach (string index in DicRowNum.Keys)
  169. {
  170. int rowNum = DicRowNum[index]; //行号
  171. switch (index)
  172. {
  173. case "[整车参数]":
  174. {
  175. //轮胎周长
  176. lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text;
  177. //转把限速
  178. lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text;
  179. //推行限速
  180. lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text;
  181. //前牙盘
  182. lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text;
  183. //后牙盘
  184. lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text;
  185. //前后灯参数
  186. int LightParams = 0x0000;
  187. if (comboBox_BikeVolF.SelectedIndex == 0)
  188. LightParams |= 0x0006;
  189. else if (comboBox_BikeVolF.SelectedIndex == 1)
  190. LightParams |= 0x000C;
  191. else
  192. {
  193. MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  194. return;
  195. }
  196. if (comboBox_BikeVolB.SelectedIndex == 0)
  197. LightParams |= 0x0600;
  198. else if (comboBox_BikeVolB.SelectedIndex == 1)
  199. LightParams |= 0x0C00;
  200. else
  201. {
  202. MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  203. return;
  204. }
  205. if (comboBox_BikeModeB.SelectedIndex >= 0)
  206. LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12);
  207. else
  208. {
  209. MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  210. return;
  211. }
  212. lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString();
  213. //启动模式
  214. lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString();
  215. //开机延迟
  216. int PowerTime = 0;
  217. PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text);
  218. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8);
  219. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12);
  220. lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString();
  221. break;
  222. }
  223. case "[控制参数]":
  224. {
  225. //峰值电流
  226. lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text;
  227. //过压保护
  228. lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text;
  229. //欠压保护
  230. lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text;
  231. break;
  232. }
  233. case "[助力参数]":
  234. {
  235. //限速起始
  236. lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text;
  237. //限速结束
  238. lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text;
  239. break;
  240. }
  241. case "[调试参数]":
  242. {
  243. //运行模式
  244. lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString();
  245. //旋转方向
  246. lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString();
  247. //功率限幅
  248. lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text;
  249. break;
  250. }
  251. case "[生产信息]":
  252. {
  253. //生产商
  254. lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text;
  255. //生产地
  256. lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text;
  257. //生产日期
  258. lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text;
  259. //产品标识
  260. lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text;
  261. break;
  262. }
  263. default: break;
  264. }
  265. }
  266. } while (false);
  267. //参数更新
  268. richTextBox_AdvanceParams.Clear();
  269. for (int i = 0; i < lines.Length; i++)
  270. {
  271. richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n");
  272. }
  273. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1);
  274. }
  275. catch (System.Exception)
  276. {
  277. MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK);
  278. return;
  279. }
  280. //获取模板文本信息写入文件
  281. FileInfo = richTextBox_AdvanceParams.Text;
  282. if (FileInfo == string.Empty)
  283. {
  284. MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  285. return;
  286. }
  287. System.IO.File.WriteAllText(DataFileName, FileInfo);
  288. //模板文件上传服务器
  289. if (myFtp.CheckFtp() == true)
  290. {
  291. //删除远程文件
  292. myFtp.DeleteFile("/ParamsMode/" + DataFileName);
  293. //上传文件
  294. bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode");
  295. if (result1 == true)
  296. {
  297. MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  298. }
  299. else
  300. {
  301. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  302. }
  303. }
  304. else
  305. {
  306. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  307. }
  308. System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName);
  309. }
  310. private void button_DeletModelFile_Click(object sender, EventArgs e)
  311. {
  312. if (comboBox_ModelFile.SelectedIndex == -1)
  313. {
  314. MessageBox.Show("未选择模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  315. }
  316. else
  317. {
  318. Login loginForm = new Login();
  319. loginForm.ShowDialog();
  320. if (loginForm.textBox_Passwd.Text == loginForm.UserAccount[loginForm.comboBox_User.Text])//检验模式所有用户支持
  321. {
  322. if (!loginForm.comboBox_User.Text.Contains("工程参数配置"))
  323. {
  324. MessageBox.Show("权限不支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  325. return;
  326. }
  327. }
  328. else
  329. {
  330. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  331. return;
  332. }
  333. if (myFtp.CheckFtp() == true)
  334. {
  335. //删除远程文件
  336. myFtp.DeleteFile("/ParamsMode/" + comboBox_ModelFile.Text);
  337. comboBox_ModelFile.Items.Clear();
  338. richTextBox_AdvanceParams.Clear();
  339. MessageBox.Show("模板已删除,请刷新!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  340. }
  341. else
  342. {
  343. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  344. }
  345. }
  346. }
  347. /// <summary>
  348. /// 导入样机生产记录文件,可用于生成模板
  349. /// </summary>
  350. /// <param name="sender"></param>
  351. /// <param name="e"></param>
  352. private void button_LoadFile_Click(object sender, EventArgs e)
  353. {
  354. comboBox_ModelFile.SelectedIndex = -1;
  355. button_ExportParams.Enabled = true;
  356. //高级参数只读
  357. richTextBox_AdvanceParams.ReadOnly = true;
  358. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  359. WriteLockStatus = true;
  360. //打开对话框选择文件
  361. OpenFileDialog ofd = new OpenFileDialog();
  362. ofd.Title = "请选择样机测试记录文件";
  363. ofd.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  364. ofd.Filter = "文本文件(*.txt)|*.txt";
  365. ofd.Multiselect = false;
  366. if (ofd.ShowDialog() == DialogResult.OK)
  367. {
  368. //打开文件
  369. StreamReader objReader = new StreamReader(ofd.FileName);
  370. string sLine = "";
  371. ArrayList array_CfgInfo = new ArrayList();
  372. array_CfgInfo.Clear();
  373. while (sLine != null)
  374. {
  375. sLine = objReader.ReadLine();
  376. array_CfgInfo.Add(sLine);
  377. }
  378. objReader.Close();
  379. //转换为模板显示
  380. try
  381. {
  382. string fileInfo = "";
  383. fileInfo += "#说明\r\n";
  384. fileInfo += "#0表示命令无效,1开启该命令的参数写入\r\n";
  385. fileInfo += "\r\n";
  386. fileInfo += "[型号],1\r\n";
  387. fileInfo += "电机型号," + array_CfgInfo[5].ToString().Split(new string[] { ": " }, StringSplitOptions.None)[1] + "\r\n";
  388. fileInfo += "\r\n";
  389. fileInfo += "[SN号],0\r\n";
  390. fileInfo += "电机SN," + "\r\n";
  391. fileInfo += "\r\n";
  392. fileInfo += "[校验码],0\r\n";
  393. fileInfo += "校验码," + "\r\n";
  394. fileInfo += "\r\n";
  395. if (array_CfgInfo[71].ToString().Length <= 6)
  396. {
  397. fileInfo += "[自定义1],0\r\n";
  398. fileInfo += "自定义字符串1," + "\r\n";
  399. fileInfo += "\r\n";
  400. }
  401. else
  402. {
  403. fileInfo += "[自定义1],1\r\n";
  404. fileInfo += "自定义字符串1," + array_CfgInfo[71].ToString().Split(new string[] { ": " }, StringSplitOptions.None)[1] + "\r\n";
  405. fileInfo += "\r\n";
  406. }
  407. if (array_CfgInfo[72].ToString().Length <= 6)
  408. {
  409. fileInfo += "[自定义2],0\r\n";
  410. fileInfo += "自定义字符串2," + "\r\n";
  411. fileInfo += "\r\n";
  412. }
  413. else
  414. {
  415. fileInfo += "[自定义2],1\r\n";
  416. fileInfo += "自定义字符串2," + array_CfgInfo[72].ToString().Split(new string[] { ": " }, StringSplitOptions.None)[1] + "\r\n";
  417. fileInfo += "\r\n";
  418. }
  419. if (array_CfgInfo[73].ToString().Length <= 6)
  420. {
  421. fileInfo += "[自定义3],0\r\n";
  422. fileInfo += "自定义字符串3," + "\r\n";
  423. fileInfo += "\r\n";
  424. }
  425. else
  426. {
  427. fileInfo += "[自定义3],1\r\n";
  428. fileInfo += "自定义字符串3," + array_CfgInfo[73].ToString().Split(new string[] { ": " }, StringSplitOptions.None)[1] + "\r\n";
  429. fileInfo += "\r\n";
  430. }
  431. fileInfo += "[生产信息],1\r\n";
  432. fileInfo += "生产商," + "\r\n";
  433. fileInfo += "生产地," + "\r\n";
  434. fileInfo += "生产日期," + "\r\n";
  435. fileInfo += "产品标识," + "\r\n";
  436. fileInfo += "\r\n";
  437. fileInfo += "[马达信息],1\r\n";
  438. fileInfo += "存储标志,1\r\n";
  439. fileInfo += array_CfgInfo[13].ToString().Replace('=',',').Replace(", ", "\r\n") + "\r\n";
  440. fileInfo += "\r\n";
  441. fileInfo += "[整车参数],1\r\n";
  442. fileInfo += "存储标志,1\r\n";
  443. fileInfo += array_CfgInfo[16].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  444. fileInfo += "\r\n";
  445. fileInfo += "[控制参数],1\r\n";
  446. fileInfo += "存储标志,1\r\n";
  447. fileInfo += array_CfgInfo[19].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  448. fileInfo += "\r\n";
  449. fileInfo += "[力矩传感器参数],1\r\n";
  450. fileInfo += "存储标志,1\r\n";
  451. fileInfo += array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  452. fileInfo += "\r\n";
  453. fileInfo += "[其它传感器参数],1\r\n";
  454. fileInfo += "存储标志,1\r\n";
  455. fileInfo += ("力矩传感器踏频脉冲数" + array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  456. fileInfo += "\r\n";
  457. fileInfo += "[助力参数],1\r\n";
  458. fileInfo += "存储标志,1\r\n";
  459. fileInfo += "空,0\r\n";
  460. fileInfo += array_CfgInfo[25].ToString().Split(new string[] { ", 助力转矩曲线编号" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(" ", "\r\n") + "\r\n";
  461. fileInfo += ("转矩曲线.a" + array_CfgInfo[25].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  462. fileInfo += ("转矩曲线.a" + array_CfgInfo[27].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  463. fileInfo += ("转矩曲线.a" + array_CfgInfo[29].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  464. fileInfo += ("转矩曲线.a" + array_CfgInfo[31].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  465. fileInfo += ("转矩曲线.a" + array_CfgInfo[33].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  466. fileInfo += ("转矩曲线.a" + array_CfgInfo[35].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  467. fileInfo += ("转矩曲线.a" + array_CfgInfo[37].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  468. fileInfo += ("转矩曲线.a" + array_CfgInfo[39].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  469. fileInfo += ("转矩曲线.a" + array_CfgInfo[41].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  470. fileInfo += ("转矩曲线.a" + array_CfgInfo[43].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  471. fileInfo += ("转矩曲线.a" + array_CfgInfo[45].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  472. fileInfo += ("转矩曲线.a" + array_CfgInfo[47].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  473. fileInfo += ("转矩曲线.a" + array_CfgInfo[49].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  474. fileInfo += ("转矩曲线.a" + array_CfgInfo[51].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  475. fileInfo += ("转矩曲线.a" + array_CfgInfo[53].ToString().Split(new string[] { "转矩曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 踏频曲线.a" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  476. fileInfo += ("踏频曲线.a" + array_CfgInfo[25].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  477. fileInfo += ("踏频曲线.a" + array_CfgInfo[27].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  478. fileInfo += ("踏频曲线.a" + array_CfgInfo[29].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  479. fileInfo += ("踏频曲线.a" + array_CfgInfo[31].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  480. fileInfo += ("踏频曲线.a" + array_CfgInfo[33].ToString().Split(new string[] { "踏频曲线.a" }, StringSplitOptions.None)[1].Split(new string[] { ", 助力启动阈值" }, StringSplitOptions.None)[0]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  481. fileInfo += ("助力启动阈值" + array_CfgInfo[25].ToString().Split(new string[] { "助力启动阈值" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  482. fileInfo += "\r\n";
  483. fileInfo += "[调试参数],1\r\n";
  484. fileInfo += "存储标志,1\r\n";
  485. fileInfo += array_CfgInfo[56].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  486. //加载高级界面
  487. richTextBox_AdvanceParams.Clear();
  488. richTextBox_AdvanceParams.AppendText(fileInfo);
  489. //加载简易界面
  490. do //基础参数界面
  491. {
  492. //内容转换行
  493. ArrayList arrText = new ArrayList(fileInfo.Split(new string[] { "\r\n" }, StringSplitOptions.None));//创建一个动态数组
  494. //建立字典,存放并获取每个命令的行号
  495. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  496. DicRowNum.Add("[整车参数]", 0);
  497. DicRowNum.Add("[控制参数]", 0);
  498. DicRowNum.Add("[助力参数]", 0);
  499. DicRowNum.Add("[调试参数]", 0);
  500. DicRowNum.Add("[生产信息]", 0);
  501. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  502. foreach (KeyValuePair<string, int> item in __dict)
  503. {
  504. foreach (string cmd in arrText)
  505. {
  506. if (cmd.Contains(item.Key))
  507. {
  508. DicRowNum[item.Key] = arrText.IndexOf(cmd);
  509. break;
  510. }
  511. }
  512. }
  513. //遍历加载
  514. foreach (string index in DicRowNum.Keys)
  515. {
  516. int rowNum = DicRowNum[index]; //行号
  517. switch (index)
  518. {
  519. case "[整车参数]":
  520. {
  521. //轮胎周长
  522. textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  523. //转把限速
  524. textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  525. //推行限速
  526. textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1];
  527. //前牙盘
  528. textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  529. //后牙盘
  530. textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  531. //前灯电压
  532. ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]);
  533. if ((LightParams & 0x00FF) == 6)
  534. comboBox_BikeVolF.SelectedIndex = 0;
  535. else if ((LightParams & 0x00FF) == 12)
  536. comboBox_BikeVolF.SelectedIndex = 1;
  537. else
  538. comboBox_BikeVolF.SelectedIndex = -1;
  539. //后灯电压
  540. if (((LightParams >> 8) & 0x0F) == 6)
  541. comboBox_BikeVolB.SelectedIndex = 0;
  542. else if (((LightParams >> 8) & 0x0F) == 12)
  543. comboBox_BikeVolB.SelectedIndex = 1;
  544. else
  545. comboBox_BikeVolB.SelectedIndex = -1;
  546. //后灯模式c
  547. comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1;
  548. //启动模式
  549. comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1;
  550. //开机延迟
  551. ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]);
  552. textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString();
  553. //关机延迟
  554. textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString();
  555. //自动关机
  556. textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString();
  557. break;
  558. }
  559. case "[控制参数]":
  560. {
  561. //峰值电流
  562. textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  563. //过压保护
  564. textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  565. //欠压保护
  566. textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  567. break;
  568. }
  569. case "[助力参数]":
  570. {
  571. //限速起始
  572. textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1];
  573. //限速结束
  574. textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1];
  575. break;
  576. }
  577. case "[调试参数]":
  578. {
  579. //运行模式
  580. if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6))
  581. {
  582. comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4;
  583. }
  584. else
  585. comboBox_SysRunMode.SelectedIndex = -1;
  586. //旋转方向
  587. comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]);
  588. //功率限幅
  589. textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1];
  590. break;
  591. }
  592. case "[生产信息]":
  593. {
  594. //生产商
  595. textBox_ProductMac.Text = arrText[rowNum + 1].ToString().Split(',')[1];
  596. //生产地
  597. textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  598. //生产日期
  599. textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
  600. //生产标识
  601. textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  602. break;
  603. }
  604. default: break;
  605. }
  606. }
  607. } while (false);
  608. MessageBox.Show("导入完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  609. }
  610. catch (Exception ex)
  611. {
  612. MessageBox.Show("导入错误,请检查导入文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  613. }
  614. }
  615. }
  616. private void pictureBox1_Click(object sender, EventArgs e)
  617. {
  618. if (WriteLockStatus == true)
  619. {
  620. richTextBox_AdvanceParams.ReadOnly = false;
  621. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  622. WriteLockStatus = !WriteLockStatus;
  623. }
  624. else
  625. {
  626. richTextBox_AdvanceParams.ReadOnly = true;
  627. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  628. WriteLockStatus = !WriteLockStatus;
  629. }
  630. }
  631. private void GenerateParams_Load(object sender, EventArgs e)
  632. {
  633. //更新版本信息
  634. label_Ver.Text = "版本: V" + mainForm.Version;
  635. label_BT.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  636. //导入网络配置
  637. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  638. {
  639. //打开文件
  640. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  641. string sLine = "";
  642. ArrayList array_CfgInfo = new ArrayList();
  643. array_CfgInfo.Clear();
  644. while (sLine != null)
  645. {
  646. sLine = objReader.ReadLine();
  647. array_CfgInfo.Add(sLine);
  648. }
  649. objReader.Close();
  650. //解析配置文件
  651. try
  652. {
  653. //Server Set IP, Port, User, PassWS, ModelPath;
  654. IP = array_CfgInfo[12].ToString().Split(':')[1];
  655. Port = array_CfgInfo[13].ToString().Split(':')[1];
  656. User = array_CfgInfo[14].ToString().Split(':')[1];
  657. PassWD = array_CfgInfo[15].ToString().Split(':')[1];
  658. ModelPath = "ParamsMode";
  659. myFtp.FtpOption(IP, Port, User, PassWD);
  660. }
  661. catch (System.Exception)
  662. {
  663. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  664. }
  665. }
  666. else
  667. {
  668. MessageBox.Show("参数文件丢失!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  669. this.Close();
  670. }
  671. //检查网络
  672. if (myFtp.CheckFtp() == false)
  673. {
  674. label_Server_ComStatus.Text = "网络已断开";
  675. label_ServerStatus.BackColor = Color.Red;
  676. MessageBox.Show("网络断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  677. this.Close();
  678. }
  679. else
  680. {
  681. label_Server_ComStatus.Text = "网络已连接:" + IP;
  682. label_ServerStatus.BackColor = Color.Green;
  683. }
  684. //加载模板文件
  685. comboBox_ModelFile.Items.Clear();
  686. string[] FileList = { "" };
  687. FileList = myFtp.GetFileNameList(ModelPath);
  688. comboBox_ModelFile.Items.Clear();
  689. foreach (var file in FileList)
  690. {
  691. if (file.Contains(".src"))
  692. {
  693. comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  694. }
  695. }
  696. }
  697. private void button_ModeRefresh_Click(object sender, EventArgs e)
  698. {
  699. //加载模板文件
  700. comboBox_ModelFile.Items.Clear();
  701. string[] FileList = { "" };
  702. FileList = myFtp.GetFileNameList(ModelPath);
  703. comboBox_ModelFile.Items.Clear();
  704. foreach (var file in FileList)
  705. {
  706. if (file.Contains(".src"))
  707. {
  708. comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  709. }
  710. }
  711. }
  712. private void comboBox_ModelFile_SelectedIndexChanged(object sender, EventArgs e)
  713. {
  714. button_ExportParams.Enabled = true;
  715. //高级参数只读
  716. richTextBox_AdvanceParams.ReadOnly = true;
  717. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  718. WriteLockStatus = true;
  719. //下载文件
  720. if (System.IO.File.Exists(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text))//本地存在选定文件,先删除本地
  721. {
  722. System.IO.File.Delete(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text);
  723. }
  724. myFtp.DownloadFile("ParamsMode/" + comboBox_ModelFile.Text, localInfo.LocalPath);
  725. //打开文件
  726. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text);
  727. string sLine = "";
  728. ArrayList arrText = new ArrayList();//创建一个动态数组
  729. while (sLine != null)
  730. {
  731. sLine = objReader.ReadLine();
  732. arrText.Add(sLine);
  733. }
  734. objReader.Close();
  735. //加载文件
  736. do //基础参数界面
  737. {
  738. //建立字典,存放并获取每个命令的行号
  739. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  740. DicRowNum.Add("[整车参数]", 0);
  741. DicRowNum.Add("[控制参数]", 0);
  742. DicRowNum.Add("[助力参数]", 0);
  743. DicRowNum.Add("[调试参数]", 0);
  744. DicRowNum.Add("[生产信息]", 0);
  745. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  746. foreach (KeyValuePair<string, int> item in __dict)
  747. {
  748. foreach (string cmd in arrText)
  749. {
  750. if (cmd.Contains(item.Key))
  751. {
  752. DicRowNum[item.Key] = arrText.IndexOf(cmd);
  753. break;
  754. }
  755. }
  756. }
  757. //遍历加载
  758. foreach (string index in DicRowNum.Keys)
  759. {
  760. int rowNum = DicRowNum[index]; //行号
  761. switch (index)
  762. {
  763. case "[整车参数]":
  764. {
  765. //轮胎周长
  766. textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  767. //转把限速
  768. textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  769. //推行限速
  770. textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1];
  771. //前牙盘
  772. textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  773. //后牙盘
  774. textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  775. //前灯电压
  776. ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]);
  777. if ((LightParams & 0x00FF) == 6)
  778. comboBox_BikeVolF.SelectedIndex = 0;
  779. else if ((LightParams & 0x00FF) == 12)
  780. comboBox_BikeVolF.SelectedIndex = 1;
  781. else
  782. comboBox_BikeVolF.SelectedIndex = -1;
  783. //后灯电压
  784. if (((LightParams >> 8) & 0x0F) == 6)
  785. comboBox_BikeVolB.SelectedIndex = 0;
  786. else if (((LightParams >> 8) & 0x0F) == 12)
  787. comboBox_BikeVolB.SelectedIndex = 1;
  788. else
  789. comboBox_BikeVolB.SelectedIndex = -1;
  790. //后灯模式c
  791. comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1;
  792. //启动模式
  793. comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1;
  794. //开机延迟
  795. ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]);
  796. textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString();
  797. //关机延迟
  798. textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString();
  799. //自动关机
  800. textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString();
  801. break;
  802. }
  803. case "[控制参数]":
  804. {
  805. //峰值电流
  806. textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  807. //过压保护
  808. textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  809. //欠压保护
  810. textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  811. break;
  812. }
  813. case "[助力参数]":
  814. {
  815. //限速起始
  816. textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1];
  817. //限速结束
  818. textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1];
  819. break;
  820. }
  821. case "[调试参数]":
  822. {
  823. //运行模式
  824. if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6))
  825. {
  826. comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4;
  827. }
  828. else
  829. comboBox_SysRunMode.SelectedIndex = -1;
  830. //旋转方向
  831. comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]);
  832. //功率限幅
  833. textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1];
  834. break;
  835. }
  836. case "[生产信息]":
  837. {
  838. //生产商
  839. textBox_ProductMac.Text= arrText[rowNum + 1].ToString().Split(',')[1];
  840. //生产地
  841. textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  842. //生产日期
  843. textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
  844. //生产标识
  845. textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  846. break;
  847. }
  848. default:break;
  849. }
  850. }
  851. } while (false);
  852. do //高级参数界面
  853. {
  854. richTextBox_AdvanceParams.Clear();
  855. foreach (string sOutput in arrText)
  856. {
  857. richTextBox_AdvanceParams.AppendText(sOutput + "\r\n");
  858. }
  859. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 2);
  860. } while (false);
  861. }
  862. private void button_GenerateModelFile_Click(object sender, EventArgs e)
  863. {
  864. string DataFileName = "";
  865. string FileInfo = "";
  866. //填写文件名
  867. Scan ModeFileName = new Scan();
  868. ModeFileName.ShowDialog();
  869. if (ModeFileName.textBox_Scan.Text == string.Empty)
  870. {
  871. MessageBox.Show("文件名为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  872. return;
  873. }
  874. DataFileName = ModeFileName.textBox_Scan.Text + ".src";
  875. //核对文件名格式
  876. //...
  877. //获取模板文本信息写入文件
  878. FileInfo = richTextBox_AdvanceParams.Text;
  879. if (FileInfo == string.Empty)
  880. {
  881. MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  882. return;
  883. }
  884. System.IO.File.WriteAllText(DataFileName, FileInfo);
  885. //模板文件上传服务器
  886. if (myFtp.CheckFtp() == true)
  887. {
  888. //上传文件
  889. bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode");
  890. if (result1 == true)
  891. {
  892. MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  893. }
  894. else
  895. {
  896. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  897. }
  898. }
  899. else
  900. {
  901. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  902. }
  903. System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName);
  904. }
  905. private void button_ExportParams_Click(object sender, EventArgs e)
  906. {
  907. //检查
  908. if ((radioButton_MIGIC.Checked | radioButton_HUB.Checked) == false)
  909. {
  910. MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  911. return;
  912. }
  913. foreach (Control c in groupBox1.Controls)
  914. {
  915. if (c is TextBox)
  916. {
  917. if (c.Text == "")
  918. {
  919. MessageBox.Show("信息填写不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  920. return;
  921. }
  922. if (c.Text.Contains('_'))
  923. {
  924. if ((c.Name != "textBox_ProductTag")&& (c.Name != "textBox_SoftwareVer"))
  925. {
  926. MessageBox.Show("\"" + c.Text + "\"" + "包含字符'_'", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  927. return;
  928. }
  929. }
  930. }
  931. }
  932. //分割参数
  933. string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
  934. try
  935. {
  936. //更新信息
  937. do
  938. {
  939. //建立字典,存放并获取每个命令的行号
  940. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  941. DicRowNum.Add("[整车参数]", 0);
  942. DicRowNum.Add("[控制参数]", 0);
  943. DicRowNum.Add("[助力参数]", 0);
  944. DicRowNum.Add("[调试参数]", 0);
  945. DicRowNum.Add("[生产信息]", 0);
  946. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  947. foreach (KeyValuePair<string, int> item in __dict)
  948. {
  949. for (int i = 0; i < lines.Length; i++)
  950. {
  951. if (lines[i].Contains(item.Key))
  952. {
  953. DicRowNum[item.Key] = i;
  954. break;
  955. }
  956. }
  957. }
  958. //遍历更新
  959. foreach (string index in DicRowNum.Keys)
  960. {
  961. int rowNum = DicRowNum[index]; //行号
  962. switch (index)
  963. {
  964. case "[整车参数]":
  965. {
  966. //轮胎周长
  967. lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text;
  968. //转把限速
  969. lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text;
  970. //推行限速
  971. lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text;
  972. //前牙盘
  973. lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text;
  974. //后牙盘
  975. lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text;
  976. //前后灯参数
  977. int LightParams = 0x0000;
  978. if (comboBox_BikeVolF.SelectedIndex == 0)
  979. LightParams |= 0x0006;
  980. else if (comboBox_BikeVolF.SelectedIndex == 1)
  981. LightParams |= 0x000C;
  982. else
  983. {
  984. MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  985. return;
  986. }
  987. if (comboBox_BikeVolB.SelectedIndex == 0)
  988. LightParams |= 0x0600;
  989. else if (comboBox_BikeVolB.SelectedIndex == 1)
  990. LightParams |= 0x0C00;
  991. else
  992. {
  993. MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  994. return;
  995. }
  996. if (comboBox_BikeModeB.SelectedIndex >= 0)
  997. LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12);
  998. else
  999. {
  1000. MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1001. return;
  1002. }
  1003. lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString();
  1004. //启动模式
  1005. lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString();
  1006. //开机延迟
  1007. int PowerTime = 0;
  1008. PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text);
  1009. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8);
  1010. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12);
  1011. lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString();
  1012. break;
  1013. }
  1014. case "[控制参数]":
  1015. {
  1016. //峰值电流
  1017. lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text;
  1018. //过压保护
  1019. lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text;
  1020. //欠压保护
  1021. lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text;
  1022. break;
  1023. }
  1024. case "[助力参数]":
  1025. {
  1026. //限速起始
  1027. lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text;
  1028. //限速结束
  1029. lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text;
  1030. break;
  1031. }
  1032. case "[调试参数]":
  1033. {
  1034. //运行模式
  1035. lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString();
  1036. //旋转方向
  1037. lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString();
  1038. //功率限幅
  1039. lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text;
  1040. break;
  1041. }
  1042. case "[生产信息]":
  1043. {
  1044. //生产商
  1045. lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text;
  1046. //生产地
  1047. lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text;
  1048. //生产日期
  1049. lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text;
  1050. //产品标识
  1051. lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text;
  1052. break;
  1053. }
  1054. default: break;
  1055. }
  1056. }
  1057. } while (false);
  1058. //参数更新
  1059. richTextBox_AdvanceParams.Clear();
  1060. for (int i = 0; i < lines.Length; i++)
  1061. {
  1062. richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n");
  1063. }
  1064. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1);
  1065. }
  1066. catch (System.Exception)
  1067. {
  1068. MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK);
  1069. return;
  1070. }
  1071. //确定本地保存路径
  1072. string Date = DateTime.Now.ToString("yyyy-MM-dd");
  1073. string LocalPath = localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + Date;
  1074. if (!Directory.Exists(LocalPath))
  1075. {
  1076. Directory.CreateDirectory(LocalPath);
  1077. }
  1078. //确定远程保存路径
  1079. string ServerPath = "";
  1080. if (radioButton_HUB.Checked)
  1081. {
  1082. if (!myFtp.DirectoryExist("HUB_Control_TEST/cfg", Date))
  1083. myFtp.MakeDir("HUB_Control_TEST/cfg" + "/" + Date);
  1084. ServerPath = "HUB_Control_TEST/cfg" + "/" + Date;
  1085. }
  1086. else if (radioButton_MIGIC.Checked)
  1087. {
  1088. if (!myFtp.DirectoryExist("MIGIC_TEST/cfg", Date))
  1089. myFtp.MakeDir("MIGIC_TEST/cfg" + "/" + Date);
  1090. ServerPath = "MIGIC_TEST/cfg" + "/" + Date;
  1091. }
  1092. //确定文件名
  1093. string fileName = "";
  1094. fileName = textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1095. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + textBox_SoftwareVer.Text + "_" +
  1096. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "-");
  1097. //保存.src文件
  1098. System.IO.File.WriteAllText(LocalPath + "\\" + fileName + ".src", richTextBox_AdvanceParams.Text);
  1099. //检查是否存在转换工具
  1100. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1101. {
  1102. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1103. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1104. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1105. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1106. }
  1107. else
  1108. {
  1109. //程序使用最新版本
  1110. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  1111. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe");
  1112. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1113. //库文件不更新
  1114. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  1115. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1116. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  1117. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1118. }
  1119. //转换.ttcfg文件
  1120. ProcessStartInfo startInfo = new ProcessStartInfo();
  1121. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  1122. startInfo.Arguments = "\"" + LocalPath + "\\" + fileName + ".src" + "\"";
  1123. System.Diagnostics.Process.Start(startInfo);
  1124. Thread.Sleep(1000);
  1125. //保存页面
  1126. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  1127. Graphics g = Graphics.FromImage(bit);
  1128. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  1129. bit.Save(LocalPath + "\\" + fileName + ".png");
  1130. //生成pdf文件,上传服务器
  1131. //上传
  1132. bool result1 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".src", ServerPath);
  1133. bool result2 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".ttcfg", ServerPath);
  1134. bool result3 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".png", ServerPath);
  1135. if (result1 & result2 & result3)
  1136. {
  1137. MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK);
  1138. }
  1139. else
  1140. {
  1141. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK);
  1142. }
  1143. }
  1144. }
  1145. }