GenerateParams.cs 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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 | radioButton_HUB_FCT.Checked) == false)
  910. {
  911. MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  912. return;
  913. }
  914. //不导出到本地时需填写完整订单信息
  915. if (!checkBox_SyncFac.Checked)
  916. {
  917. foreach (Control c in groupBox1.Controls)
  918. {
  919. if (c is TextBox)
  920. {
  921. if (c.Text == "")
  922. {
  923. MessageBox.Show("信息填写不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  924. return;
  925. }
  926. if (c.Text.Contains('_'))
  927. {
  928. if ((c.Name != "textBox_ProductTag") && (c.Name != "textBox_SoftwareVer"))
  929. {
  930. MessageBox.Show("\"" + c.Text + "\"" + "包含字符'_'", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  931. return;
  932. }
  933. }
  934. }
  935. }
  936. }
  937. //分割参数
  938. string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
  939. try
  940. {
  941. //更新信息
  942. do
  943. {
  944. //建立字典,存放并获取每个命令的行号
  945. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  946. DicRowNum.Add("[整车参数]", 0);
  947. DicRowNum.Add("[控制参数]", 0);
  948. DicRowNum.Add("[助力参数]", 0);
  949. DicRowNum.Add("[调试参数]", 0);
  950. DicRowNum.Add("[生产信息]", 0);
  951. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  952. foreach (KeyValuePair<string, int> item in __dict)
  953. {
  954. for (int i = 0; i < lines.Length; i++)
  955. {
  956. if (lines[i].Contains(item.Key))
  957. {
  958. DicRowNum[item.Key] = i;
  959. break;
  960. }
  961. }
  962. }
  963. //遍历更新
  964. foreach (string index in DicRowNum.Keys)
  965. {
  966. int rowNum = DicRowNum[index]; //行号
  967. switch (index)
  968. {
  969. case "[整车参数]":
  970. {
  971. //轮胎周长
  972. lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text;
  973. //转把限速
  974. lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text;
  975. //推行限速
  976. lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text;
  977. //前牙盘
  978. lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text;
  979. //后牙盘
  980. lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text;
  981. //前后灯参数
  982. int LightParams = 0x0000;
  983. if (comboBox_BikeVolF.SelectedIndex == 0)
  984. LightParams |= 0x0006;
  985. else if (comboBox_BikeVolF.SelectedIndex == 1)
  986. LightParams |= 0x000C;
  987. else
  988. {
  989. MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  990. return;
  991. }
  992. if (comboBox_BikeVolB.SelectedIndex == 0)
  993. LightParams |= 0x0600;
  994. else if (comboBox_BikeVolB.SelectedIndex == 1)
  995. LightParams |= 0x0C00;
  996. else
  997. {
  998. MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  999. return;
  1000. }
  1001. if (comboBox_BikeModeB.SelectedIndex >= 0)
  1002. LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12);
  1003. else
  1004. {
  1005. MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1006. return;
  1007. }
  1008. lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString();
  1009. //启动模式
  1010. lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString();
  1011. //开机延迟
  1012. int PowerTime = 0;
  1013. PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text);
  1014. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8);
  1015. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12);
  1016. lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString();
  1017. break;
  1018. }
  1019. case "[控制参数]":
  1020. {
  1021. //峰值电流
  1022. lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text;
  1023. //过压保护
  1024. lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text;
  1025. //欠压保护
  1026. lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text;
  1027. break;
  1028. }
  1029. case "[助力参数]":
  1030. {
  1031. //限速起始
  1032. lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text;
  1033. //限速结束
  1034. lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text;
  1035. break;
  1036. }
  1037. case "[调试参数]":
  1038. {
  1039. //运行模式
  1040. lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString();
  1041. //旋转方向
  1042. lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString();
  1043. //功率限幅
  1044. lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text;
  1045. break;
  1046. }
  1047. case "[生产信息]":
  1048. {
  1049. //生产商
  1050. lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text;
  1051. //生产地
  1052. lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text;
  1053. //生产日期
  1054. lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text;
  1055. //产品标识
  1056. lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text;
  1057. break;
  1058. }
  1059. default: break;
  1060. }
  1061. }
  1062. } while (false);
  1063. //参数更新
  1064. richTextBox_AdvanceParams.Clear();
  1065. for (int i = 0; i < lines.Length; i++)
  1066. {
  1067. richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n");
  1068. }
  1069. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1);
  1070. }
  1071. catch (System.Exception)
  1072. {
  1073. MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK);
  1074. return;
  1075. }
  1076. //不导出本地时,上传服务器
  1077. if (!checkBox_SyncFac.Checked)
  1078. {
  1079. //确定本地保存路径
  1080. string Date = DateTime.Now.ToString("yyyy-MM-dd");
  1081. string LocalPath = localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + Date;
  1082. if (!Directory.Exists(LocalPath))
  1083. {
  1084. Directory.CreateDirectory(LocalPath);
  1085. }
  1086. //确定远程保存路径
  1087. string ServerPath = "";
  1088. if (radioButton_HUB.Checked)
  1089. {
  1090. if (!myFtp.DirectoryExist("HUB_Control_TEST/cfg", Date))
  1091. myFtp.MakeDir("HUB_Control_TEST/cfg" + "/" + Date);
  1092. ServerPath = "HUB_Control_TEST/cfg" + "/" + Date;
  1093. }
  1094. else if (radioButton_MIGIC.Checked)
  1095. {
  1096. if (!myFtp.DirectoryExist("MIGIC_TEST/cfg", Date))
  1097. myFtp.MakeDir("MIGIC_TEST/cfg" + "/" + Date);
  1098. ServerPath = "MIGIC_TEST/cfg" + "/" + Date;
  1099. }
  1100. else if (radioButton_HUB_FCT.Checked)
  1101. {
  1102. if (!myFtp.DirectoryExist("HUB_Control_FCT/cfg", Date))
  1103. myFtp.MakeDir("HUB_Control_FCT/cfg" + "/" + Date);
  1104. ServerPath = "HUB_Control_FCT/cfg" + "/" + Date;
  1105. }
  1106. //确定文件名
  1107. string fileName = "";
  1108. fileName = textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1109. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + textBox_SoftwareVer.Text + "_" +
  1110. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "-");
  1111. //保存.src文件
  1112. System.IO.File.WriteAllText(LocalPath + "\\" + fileName + ".src", richTextBox_AdvanceParams.Text);
  1113. //检查是否存在转换工具
  1114. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1115. {
  1116. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1117. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1118. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1119. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1120. }
  1121. else
  1122. {
  1123. //程序使用最新版本
  1124. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  1125. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe");
  1126. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1127. //库文件不更新
  1128. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  1129. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1130. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  1131. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1132. }
  1133. //转换.ttcfg文件
  1134. ProcessStartInfo startInfo = new ProcessStartInfo();
  1135. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  1136. startInfo.Arguments = "\"" + LocalPath + "\\" + fileName + ".src" + "\"";
  1137. System.Diagnostics.Process.Start(startInfo);
  1138. Thread.Sleep(1000);
  1139. //保存页面
  1140. Double scaleX = PrimaryScreen.ScaleX;
  1141. Double scaleY = PrimaryScreen.ScaleY;
  1142. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  1143. Graphics g = Graphics.FromImage(bit);
  1144. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  1145. bit.Save(LocalPath + "\\" + fileName + ".png");
  1146. //生成pdf文件,上传服务器
  1147. //...
  1148. //上传
  1149. bool result1 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".src", ServerPath);
  1150. bool result2 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".ttcfg", ServerPath);
  1151. bool result3 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".png", ServerPath);
  1152. if (result1 & result2 & result3)
  1153. {
  1154. MessageBoxTimeOut.Show("上传成功", "提示", 1000, MessageBoxButtons.OK);
  1155. }
  1156. else
  1157. {
  1158. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK);
  1159. }
  1160. }
  1161. //导出本地指定路径
  1162. else
  1163. {
  1164. SaveFileDialog saveFileDialog = new SaveFileDialog();
  1165. saveFileDialog.Filter = "配置文件(*.ttcfg)|*.ttcfg";
  1166. DialogResult result = saveFileDialog.ShowDialog();
  1167. if (result == DialogResult.OK)
  1168. {
  1169. string filePath = saveFileDialog.FileName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
  1170. //保存src文件
  1171. System.IO.File.WriteAllText(filePath + ".src", richTextBox_AdvanceParams.Text);
  1172. //检查是否存在转换工具
  1173. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1174. {
  1175. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1176. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1177. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1178. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1179. }
  1180. else
  1181. {
  1182. //程序使用最新版本
  1183. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  1184. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe");
  1185. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1186. //库文件不更新
  1187. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  1188. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1189. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  1190. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1191. }
  1192. //转换.ttcfg文件
  1193. ProcessStartInfo startInfo = new ProcessStartInfo();
  1194. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  1195. startInfo.Arguments = filePath + ".src";
  1196. System.Diagnostics.Process.Start(startInfo);
  1197. Thread.Sleep(1000);
  1198. MessageBoxTimeOut.Show("导出本地完成", "提示", 1000, MessageBoxButtons.OK);
  1199. }
  1200. }
  1201. }
  1202. }
  1203. }