GenerateParams.cs 66 KB

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