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