GenerateParams.cs 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  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. using NPOI;
  19. using NPOI.SS.UserModel;
  20. using NPOI.HSSF.UserModel;
  21. using NPOI.POIFS.FileSystem;
  22. using Spire.Xls;
  23. using Workbook = Spire.Xls.Workbook;
  24. using Spire.Xls.Core;
  25. namespace Welling_Motor_Debug_Tool
  26. {
  27. public partial class GenerateParams : Form
  28. {
  29. //存储路径文件
  30. LocalInfo localInfo = new LocalInfo();
  31. //服务器配置
  32. string IP, Port, User, PassWD, ModelPath, CfgPath;
  33. //离线标志
  34. bool Offline_Flag = false;
  35. //FTP
  36. ftp myFtp = new ftp();
  37. //高级参数修改标志
  38. bool WriteLockStatus = true;
  39. public GenerateParams()
  40. {
  41. InitializeComponent();
  42. }
  43. private void button_NoteRead_Click(object sender, EventArgs e)
  44. {
  45. //检查本地文件删除
  46. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  47. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  48. //下载远程文件
  49. myFtp.DownloadFile("/Note/Note.txt", localInfo.LocalPath);
  50. //显示文件
  51. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.NoteFileName);
  52. string sLine = "";
  53. ArrayList arrText = new ArrayList();//创建一个动态数组
  54. while (sLine != null)
  55. {
  56. sLine = objReader.ReadLine();
  57. arrText.Add(sLine);
  58. }
  59. objReader.Close();
  60. richTextBox_Note.Clear();
  61. foreach (string sOutput in arrText)
  62. {
  63. richTextBox_Note.AppendText(sOutput + "\r\n");
  64. }
  65. richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1);
  66. }
  67. private void button_NoteWrite_Click(object sender, EventArgs e)
  68. {
  69. //检查本地并删除
  70. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  71. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  72. //保存
  73. System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, richTextBox_Note.Text);
  74. //上传服务器
  75. if (!myFtp.DirectoryExist("/", "Note"))
  76. myFtp.MakeDir("/Note");
  77. bool result = myFtp.UploadFile(localInfo.LocalPath + localInfo.NoteFileName, "/Note");
  78. if (result)
  79. MessageBoxTimeOut.Show("上传完成", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  80. else
  81. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  82. }
  83. private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  84. {
  85. //选中备忘录时自动读取更新
  86. if (tabControl1.SelectedIndex == 2)
  87. {
  88. //检查本地文件删除
  89. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
  90. System.IO.File.Delete(localInfo.LocalPath + localInfo.NoteFileName);
  91. //下载远程文件
  92. myFtp.DownloadFile("/Note/Note.txt", localInfo.LocalPath);
  93. //显示文件
  94. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.NoteFileName);
  95. string sLine = "";
  96. ArrayList arrText = new ArrayList();//创建一个动态数组
  97. while (sLine != null)
  98. {
  99. sLine = objReader.ReadLine();
  100. arrText.Add(sLine);
  101. }
  102. objReader.Close();
  103. richTextBox_Note.Clear();
  104. foreach (string sOutput in arrText)
  105. {
  106. richTextBox_Note.AppendText(sOutput + "\r\n");
  107. }
  108. richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1);
  109. }
  110. //高级参数只读
  111. richTextBox_AdvanceParams.ReadOnly = true;
  112. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  113. WriteLockStatus = true;
  114. }
  115. private void radioButton_MIGIC_Click(object sender, EventArgs e)
  116. {
  117. textBox_ProductTag.Text = "MM_MC1";
  118. comboBox_SysRunMode.Items.Clear();
  119. comboBox_SysRunMode.Items.Add("CITY");
  120. comboBox_SysRunMode.Items.Add("MTB");
  121. }
  122. private void radioButton_HUB_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 radioButton_HUB_FCT_Click(object sender, EventArgs e)
  130. {
  131. textBox_ProductTag.Text = "GF_250_1";
  132. comboBox_SysRunMode.Items.Clear();
  133. comboBox_SysRunMode.Items.Add("踏频");
  134. comboBox_SysRunMode.Items.Add("力矩");
  135. }
  136. private void comboBox_SysRunMode_Click(object sender, EventArgs e)
  137. {
  138. if ((radioButton_MIGIC.Checked | radioButton_HUB.Checked | radioButton_HUB_FCT.Checked) == false)
  139. {
  140. MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  141. }
  142. }
  143. private void button_ChangeModelFile_Click(object sender, EventArgs e)
  144. {
  145. string DataFileName = "";
  146. string FileInfo = "";
  147. if (comboBox_ModelFile.SelectedIndex == -1)
  148. {
  149. MessageBox.Show("未选择模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  150. return;
  151. }
  152. if (MessageBox.Show("确认修改模板?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  153. {
  154. return;
  155. }
  156. //填写文件名
  157. DataFileName = comboBox_ModelFile.Text;
  158. //分割参数更新参数内容
  159. string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
  160. try
  161. {
  162. //更新信息
  163. do
  164. {
  165. //建立字典,存放并获取每个命令的行号
  166. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  167. DicRowNum.Add("[整车参数]", 0);
  168. DicRowNum.Add("[控制参数]", 0);
  169. DicRowNum.Add("[助力参数]", 0);
  170. DicRowNum.Add("[调试参数]", 0);
  171. DicRowNum.Add("[生产信息]", 0);
  172. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  173. foreach (KeyValuePair<string, int> item in __dict)
  174. {
  175. for (int i = 0; i < lines.Length; i++)
  176. {
  177. if (lines[i].Contains(item.Key))
  178. {
  179. DicRowNum[item.Key] = i;
  180. break;
  181. }
  182. }
  183. }
  184. //遍历更新
  185. foreach (string index in DicRowNum.Keys)
  186. {
  187. int rowNum = DicRowNum[index]; //行号
  188. switch (index)
  189. {
  190. case "[整车参数]":
  191. {
  192. //轮胎周长
  193. lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text;
  194. //转把限速
  195. lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text;
  196. //推行限速
  197. lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text;
  198. //前牙盘
  199. lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text;
  200. //后牙盘
  201. lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text;
  202. //前后灯参数
  203. int LightParams = 0x0000;
  204. if (comboBox_BikeVolF.SelectedIndex == 0)
  205. LightParams |= 0x0006;
  206. else if (comboBox_BikeVolF.SelectedIndex == 1)
  207. LightParams |= 0x000C;
  208. else
  209. {
  210. MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  211. return;
  212. }
  213. if (comboBox_BikeVolB.SelectedIndex == 0)
  214. LightParams |= 0x0600;
  215. else if (comboBox_BikeVolB.SelectedIndex == 1)
  216. LightParams |= 0x0C00;
  217. else
  218. {
  219. MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  220. return;
  221. }
  222. if (comboBox_BikeModeB.SelectedIndex >= 0)
  223. LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12);
  224. else
  225. {
  226. MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  227. return;
  228. }
  229. lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString();
  230. //启动模式
  231. lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString();
  232. //开机延迟
  233. int PowerTime = 0;
  234. PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text);
  235. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8);
  236. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12);
  237. lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString();
  238. break;
  239. }
  240. case "[控制参数]":
  241. {
  242. //峰值电流
  243. lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text;
  244. //过压保护
  245. lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text;
  246. //欠压保护
  247. lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text;
  248. break;
  249. }
  250. case "[助力参数]":
  251. {
  252. //限速起始
  253. lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text;
  254. //限速结束
  255. lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text;
  256. break;
  257. }
  258. case "[调试参数]":
  259. {
  260. //运行模式
  261. lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString();
  262. //旋转方向
  263. lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString();
  264. //功率限幅
  265. lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text;
  266. break;
  267. }
  268. case "[生产信息]":
  269. {
  270. //生产商
  271. lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text;
  272. //生产地
  273. lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text;
  274. //生产日期
  275. lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text;
  276. //产品标识
  277. lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text;
  278. break;
  279. }
  280. default: break;
  281. }
  282. }
  283. } while (false);
  284. //参数更新
  285. richTextBox_AdvanceParams.Clear();
  286. for (int i = 0; i < lines.Length; i++)
  287. {
  288. richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n");
  289. }
  290. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1);
  291. }
  292. catch (System.Exception)
  293. {
  294. MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK);
  295. return;
  296. }
  297. //获取模板文本信息写入文件
  298. FileInfo = richTextBox_AdvanceParams.Text;
  299. if (FileInfo == string.Empty)
  300. {
  301. MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  302. return;
  303. }
  304. System.IO.File.WriteAllText(DataFileName, FileInfo);
  305. //模板文件上传服务器
  306. if (myFtp.CheckFtp() == true)
  307. {
  308. //删除远程文件
  309. myFtp.DeleteFile("/ParamsMode/" + DataFileName);
  310. //上传文件
  311. bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode");
  312. if (result1 == true)
  313. {
  314. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  315. }
  316. else
  317. {
  318. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  319. }
  320. }
  321. else
  322. {
  323. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  324. }
  325. System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName);
  326. }
  327. private void button_DeletModelFile_Click(object sender, EventArgs e)
  328. {
  329. if (comboBox_ModelFile.SelectedIndex == -1)
  330. {
  331. MessageBox.Show("未选择模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  332. }
  333. else
  334. {
  335. Login loginForm = new Login();
  336. loginForm.ShowDialog();
  337. if (loginForm.textBox_Passwd.Text == loginForm.UserAccount[loginForm.comboBox_User.Text])//检验模式所有用户支持
  338. {
  339. if (!loginForm.comboBox_User.Text.Contains("工程参数配置"))
  340. {
  341. MessageBox.Show("权限不支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  342. return;
  343. }
  344. }
  345. else
  346. {
  347. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  348. return;
  349. }
  350. if (myFtp.CheckFtp() == true)
  351. {
  352. //删除远程文件
  353. myFtp.DeleteFile("/ParamsMode/" + comboBox_ModelFile.Text);
  354. comboBox_ModelFile.Items.Clear();
  355. richTextBox_AdvanceParams.Clear();
  356. MessageBox.Show("模板已删除,请刷新!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  357. }
  358. else
  359. {
  360. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  361. }
  362. }
  363. }
  364. /// <summary>
  365. /// 导入样机生产记录文件,可用于生成模板
  366. /// </summary>
  367. /// <param name="sender"></param>
  368. /// <param name="e"></param>
  369. private void button_LoadFile_Click(object sender, EventArgs e)
  370. {
  371. comboBox_ModelFile.SelectedIndex = -1;
  372. button_ExportParams.Enabled = true;
  373. //高级参数只读
  374. richTextBox_AdvanceParams.ReadOnly = true;
  375. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  376. WriteLockStatus = true;
  377. //打开对话框选择文件
  378. OpenFileDialog ofd = new OpenFileDialog();
  379. ofd.Title = "请选择样机测试记录文件";
  380. ofd.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  381. ofd.Filter = "文本文件(*.txt)|*.txt";
  382. ofd.Multiselect = false;
  383. if (ofd.ShowDialog() == DialogResult.OK)
  384. {
  385. //打开文件
  386. StreamReader objReader = new StreamReader(ofd.FileName);
  387. string sLine = "";
  388. ArrayList array_CfgInfo = new ArrayList();
  389. array_CfgInfo.Clear();
  390. while (sLine != null)
  391. {
  392. sLine = objReader.ReadLine();
  393. array_CfgInfo.Add(sLine);
  394. }
  395. objReader.Close();
  396. //转换为模板显示
  397. try
  398. {
  399. string fileInfo = "";
  400. fileInfo += "#说明\r\n";
  401. fileInfo += "#0表示命令无效,1开启该命令的参数写入\r\n";
  402. fileInfo += "\r\n";
  403. fileInfo += "[型号],1\r\n";
  404. fileInfo += "电机型号," + array_CfgInfo[5].ToString().Split(new string[] { ": " }, StringSplitOptions.None)[1] + "\r\n";
  405. fileInfo += "\r\n";
  406. fileInfo += "[SN号],0\r\n";
  407. fileInfo += "电机SN," + "\r\n";
  408. fileInfo += "\r\n";
  409. fileInfo += "[校验码],0\r\n";
  410. fileInfo += "校验码," + "\r\n";
  411. fileInfo += "\r\n";
  412. fileInfo += "[自定义1],0\r\n";
  413. fileInfo += "自定义字符串1," + "\r\n";
  414. fileInfo += "\r\n";
  415. fileInfo += "[自定义2],0\r\n";
  416. fileInfo += "自定义字符串1," + "\r\n";
  417. fileInfo += "\r\n";
  418. fileInfo += "[自定义3],0\r\n";
  419. fileInfo += "自定义字符串1," + "\r\n";
  420. fileInfo += "\r\n";
  421. fileInfo += "[生产信息],1\r\n";
  422. fileInfo += "生产商," + "\r\n";
  423. fileInfo += "生产地," + "\r\n";
  424. fileInfo += "生产日期," + "\r\n";
  425. fileInfo += "产品标识," + "\r\n";
  426. fileInfo += "\r\n";
  427. fileInfo += "[马达信息],1\r\n";
  428. fileInfo += "存储标志,1\r\n";
  429. fileInfo += array_CfgInfo[13].ToString().Replace('=',',').Replace(", ", "\r\n") + "\r\n";
  430. fileInfo += "\r\n";
  431. fileInfo += "[整车参数],1\r\n";
  432. fileInfo += "存储标志,1\r\n";
  433. fileInfo += array_CfgInfo[16].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  434. fileInfo += "\r\n";
  435. fileInfo += "[控制参数],1\r\n";
  436. fileInfo += "存储标志,1\r\n";
  437. fileInfo += array_CfgInfo[19].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  438. fileInfo += "\r\n";
  439. fileInfo += "[力矩传感器参数],1\r\n";
  440. fileInfo += "存储标志,1\r\n";
  441. fileInfo += array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  442. fileInfo += "\r\n";
  443. fileInfo += "[其它传感器参数],1\r\n";
  444. fileInfo += "存储标志,1\r\n";
  445. fileInfo += ("力矩传感器踏频脉冲数" + array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  446. fileInfo += "\r\n";
  447. fileInfo += "[助力参数],1\r\n";
  448. fileInfo += "存储标志,1\r\n";
  449. fileInfo += "空,0\r\n";
  450. fileInfo += array_CfgInfo[25].ToString().Split(new string[] { ", 助力转矩曲线编号" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(" ", "\r\n") + "\r\n";
  451. 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";
  452. 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";
  453. 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";
  454. 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";
  455. 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";
  456. 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";
  457. 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";
  458. 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";
  459. 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";
  460. 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";
  461. 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";
  462. 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";
  463. 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";
  464. 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";
  465. 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";
  466. 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";
  467. 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";
  468. 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";
  469. 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";
  470. 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";
  471. fileInfo += ("助力启动阈值" + array_CfgInfo[25].ToString().Split(new string[] { "助力启动阈值" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  472. fileInfo += "\r\n";
  473. fileInfo += "[调试参数],1\r\n";
  474. fileInfo += "存储标志,1\r\n";
  475. fileInfo += array_CfgInfo[56].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  476. fileInfo += "\r\n";
  477. string FileVer = "";
  478. FileVer = array_CfgInfo[array_CfgInfo.Count - 2].ToString();
  479. if (FileVer.Contains("V2.0")) //2.0版本包含整车参数和用户骑行参数
  480. {
  481. fileInfo += "[整车参数2],1\r\n";
  482. fileInfo += "存储标志,1\r\n";
  483. fileInfo += array_CfgInfo[65].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  484. fileInfo += "\r\n";
  485. fileInfo += "[用户骑行参数],1\r\n";
  486. fileInfo += "存储标志,1\r\n";
  487. fileInfo += array_CfgInfo[68].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  488. }
  489. else //2.0版本前不包含整车参数和用户骑行参数,写0,不转换
  490. {
  491. fileInfo += "[整车参数2],0\r\n\r\n";
  492. fileInfo += "\r\n";
  493. fileInfo += "[用户骑行参数],0\r\n\r\n";
  494. fileInfo += "\r\n";
  495. }
  496. //加载高级界面
  497. richTextBox_AdvanceParams.Clear();
  498. richTextBox_AdvanceParams.AppendText(fileInfo);
  499. //加载简易界面
  500. do //基础参数界面
  501. {
  502. //内容转换行
  503. ArrayList arrText = new ArrayList(fileInfo.Split(new string[] { "\r\n" }, StringSplitOptions.None));//创建一个动态数组
  504. //建立字典,存放并获取每个命令的行号
  505. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  506. DicRowNum.Add("[整车参数]", 0);
  507. DicRowNum.Add("[控制参数]", 0);
  508. DicRowNum.Add("[助力参数]", 0);
  509. DicRowNum.Add("[调试参数]", 0);
  510. DicRowNum.Add("[生产信息]", 0);
  511. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  512. foreach (KeyValuePair<string, int> item in __dict)
  513. {
  514. foreach (string cmd in arrText)
  515. {
  516. if (cmd.Contains(item.Key))
  517. {
  518. DicRowNum[item.Key] = arrText.IndexOf(cmd);
  519. break;
  520. }
  521. }
  522. }
  523. //遍历加载
  524. foreach (string index in DicRowNum.Keys)
  525. {
  526. int rowNum = DicRowNum[index]; //行号
  527. switch (index)
  528. {
  529. case "[整车参数]":
  530. {
  531. //轮胎周长
  532. textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  533. //转把限速
  534. textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  535. //推行限速
  536. textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1];
  537. //前牙盘
  538. textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  539. //后牙盘
  540. textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  541. //前灯电压
  542. ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]);
  543. if ((LightParams & 0x00FF) == 6)
  544. comboBox_BikeVolF.SelectedIndex = 0;
  545. else if ((LightParams & 0x00FF) == 12)
  546. comboBox_BikeVolF.SelectedIndex = 1;
  547. else
  548. comboBox_BikeVolF.SelectedIndex = -1;
  549. //后灯电压
  550. if (((LightParams >> 8) & 0x0F) == 6)
  551. comboBox_BikeVolB.SelectedIndex = 0;
  552. else if (((LightParams >> 8) & 0x0F) == 12)
  553. comboBox_BikeVolB.SelectedIndex = 1;
  554. else
  555. comboBox_BikeVolB.SelectedIndex = -1;
  556. //后灯模式c
  557. comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1;
  558. //启动模式
  559. comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1;
  560. //开机延迟
  561. ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]);
  562. textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString();
  563. //关机延迟
  564. textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString();
  565. //自动关机
  566. textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString();
  567. break;
  568. }
  569. case "[控制参数]":
  570. {
  571. //峰值电流
  572. textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  573. //过压保护
  574. textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  575. //欠压保护
  576. textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  577. break;
  578. }
  579. case "[助力参数]":
  580. {
  581. //限速起始
  582. textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1];
  583. //限速结束
  584. textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1];
  585. break;
  586. }
  587. case "[调试参数]":
  588. {
  589. //运行模式
  590. if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6))
  591. {
  592. comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4;
  593. }
  594. else
  595. comboBox_SysRunMode.SelectedIndex = -1;
  596. //旋转方向
  597. comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]);
  598. //功率限幅
  599. textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1];
  600. break;
  601. }
  602. case "[生产信息]":
  603. {
  604. //生产商
  605. textBox_ProductMac.Text = arrText[rowNum + 1].ToString().Split(',')[1];
  606. //生产地
  607. textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  608. //生产日期
  609. textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
  610. //生产标识
  611. textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  612. break;
  613. }
  614. default: break;
  615. }
  616. }
  617. } while (false);
  618. MessageBoxTimeOut.Show("导入完成!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  619. }
  620. catch (Exception ex)
  621. {
  622. MessageBox.Show("导入错误,请检查导入文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  623. }
  624. }
  625. }
  626. private void pictureBox1_Click(object sender, EventArgs e)
  627. {
  628. if (WriteLockStatus == true)
  629. {
  630. richTextBox_AdvanceParams.ReadOnly = false;
  631. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  632. WriteLockStatus = !WriteLockStatus;
  633. }
  634. else
  635. {
  636. richTextBox_AdvanceParams.ReadOnly = true;
  637. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  638. WriteLockStatus = !WriteLockStatus;
  639. }
  640. }
  641. private void GenerateParams_Load(object sender, EventArgs e)
  642. {
  643. //更新版本信息
  644. label_Ver.Text = "版本: V" + mainForm.Version;
  645. label_BT.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  646. //离线使用标志
  647. Offline_Flag = (mainform1.OfflineFlag == true);
  648. //模板文件服务器路径
  649. ModelPath = "ParamsMode";
  650. //FTP配置
  651. IP = mainform1.ServerIP;
  652. Port = mainform1.ServerPort;
  653. User = mainform1.ServerUser;
  654. PassWD = mainform1.ServerPassWd;
  655. myFtp.FtpOption(IP, Port, User, PassWD, "admin", "ttium_admin");
  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. //写入excel表格
  1146. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName)) //删除本地模板,从服务器下载最新模板
  1147. {
  1148. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName);
  1149. }
  1150. myFtp.DownloadFile("Tools/GenerateParamsFile/" + localInfo.ExcelTempleFileName, localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1151. string importExcelName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName;
  1152. string exportExcelName = LocalPath + "\\" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1153. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".xls";
  1154. try
  1155. {
  1156. string sLine = "";
  1157. //读取力矩传感器范围
  1158. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.TorqueSensorFileName);
  1159. List<string> TorqueInfo = new List<string>();
  1160. while (sLine != null)
  1161. {
  1162. sLine = objReader.ReadLine();
  1163. TorqueInfo.Add(sLine);
  1164. }
  1165. objReader.Close();
  1166. //读取MOS校准参数
  1167. objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  1168. sLine = "";
  1169. List<string> MosCalInfo = new List<string>();
  1170. while (sLine != null)
  1171. {
  1172. sLine = objReader.ReadLine();
  1173. MosCalInfo.Add(sLine);
  1174. }
  1175. objReader.Close();
  1176. //导入模板文件
  1177. NPOI.SS.UserModel.IWorkbook workbook = WorkbookFactory.Create(importExcelName);
  1178. //获取第一个工作薄
  1179. ISheet sheet = workbook.GetSheetAt(0);
  1180. //建立字典,获取并存放并获取每个命令的起始行号
  1181. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  1182. DicRowNum.Add("[马达信息]", 0);
  1183. DicRowNum.Add("[整车参数]", 0);
  1184. DicRowNum.Add("[控制参数]", 0);
  1185. DicRowNum.Add("[其它传感器参数]", 0);
  1186. DicRowNum.Add("[助力参数]", 0);
  1187. DicRowNum.Add("[调试参数]", 0);
  1188. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  1189. foreach (KeyValuePair<string, int> item in __dict)
  1190. {
  1191. for (int i = 0; i < lines.Length; i++)
  1192. {
  1193. if (lines[i].Contains(item.Key))
  1194. {
  1195. DicRowNum[item.Key] = i;
  1196. break;
  1197. }
  1198. }
  1199. }
  1200. #region 开始按行写入数据
  1201. //第3行,文件信息
  1202. IRow row = sheet.GetRow(2);
  1203. row.GetCell(0).SetCellValue("文件信息 File Info:" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1204. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss"));
  1205. //第5行,第2列型号,定制功能使能标志
  1206. row = sheet.GetRow(4);
  1207. row.GetCell(1).SetCellValue(textBox_ProductName.Text);
  1208. row.GetCell(9).SetCellValue(lines[DicRowNum["[控制参数]"] + 15].Split(',')[1]);
  1209. //第6行,第2列序列号,第10列力矩传感器零点范围
  1210. row = sheet.GetRow(5);
  1211. row.GetCell(1).SetCellValue("Same as marking label");
  1212. row.GetCell(9).SetCellValue(TorqueInfo[0].Split(',')[1] + "-" + TorqueInfo[0].Split(',')[2]);
  1213. //第7行,第2列PCBA板号,第10列力矩传感器标定1范围
  1214. row = sheet.GetRow(6);
  1215. row.GetCell(1).SetCellValue(textBox_PCBA.Text);
  1216. row.GetCell(9).SetCellValue(TorqueInfo[1].Split(',')[0] + ": " + TorqueInfo[1].Split(',')[1] + "-" + TorqueInfo[1].Split(',')[2]);
  1217. //第8行,第2列软件版本,第10列力矩传感器标定2范围
  1218. row = sheet.GetRow(7);
  1219. row.GetCell(1).SetCellValue(textBox_SoftwareVer.Text);
  1220. row.GetCell(9).SetCellValue(TorqueInfo[2].Split(',')[0] + ": " + TorqueInfo[2].Split(',')[1] + "-" + TorqueInfo[2].Split(',')[2]);
  1221. //第9行,第2列Bootloader版本,第10列力矩传感器标定3范围
  1222. row = sheet.GetRow(8);
  1223. row.GetCell(1).SetCellValue("250K");
  1224. row.GetCell(9).SetCellValue(TorqueInfo[3].Split(',')[0] + ": " + TorqueInfo[3].Split(',')[1] + "-" + TorqueInfo[3].Split(',')[2]);
  1225. //第10行,第2列静态母线电压范围,第10列力矩传感器标定4范围
  1226. row = sheet.GetRow(9);
  1227. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 12].Split(',')[1].Substring(0, 2) + " ± 1V");
  1228. row.GetCell(9).SetCellValue(TorqueInfo[4].Split(',')[0] + ": " + TorqueInfo[4].Split(',')[1] + "-" + TorqueInfo[4].Split(',')[2]);
  1229. //第11行,第2列静态母线电流范围,第10列力矩传感器踏频脉冲数
  1230. row = sheet.GetRow(10);
  1231. row.GetCell(1).SetCellValue("≤ 0.050 A");
  1232. row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 2].Split(',')[1]);
  1233. //第12行,第2列极对数,第10列车速传感器脉冲数
  1234. row = sheet.GetRow(11);
  1235. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 2].Split(',')[1]);
  1236. row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 3].Split(',')[1]);
  1237. //第13行,第2列相电阻,第10列踏频传感器脉冲数
  1238. row = sheet.GetRow(12);
  1239. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 3].Split(',')[1]);
  1240. row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 4].Split(',')[1]);
  1241. //第14行,第2列d轴电感,第10列助力启动阈值
  1242. row = sheet.GetRow(13);
  1243. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 4].Split(',')[1]);
  1244. row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 85].Split(',')[1]);
  1245. //第15行,第2列q轴电感,第10列助力停机阈值
  1246. row = sheet.GetRow(14);
  1247. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 5].Split(',')[1]);
  1248. row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 86].Split(',')[1]);
  1249. //第16行,第2列永磁体磁链,第10列限速起始值
  1250. row = sheet.GetRow(15);
  1251. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 6].Split(',')[1]);
  1252. row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 92].Split(',')[1] + " km/h");
  1253. //第17行,第2列Id最小值,第10列限速停机值
  1254. row = sheet.GetRow(16);
  1255. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 8].Split(',')[1]);
  1256. row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 93].Split(',')[1] + " km/h");
  1257. //第18行,第2列额定转速,第10列运行模式
  1258. row = sheet.GetRow(17);
  1259. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 9].Split(',')[1] + " rpm");
  1260. row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 2].Split(',')[1]);
  1261. //第19行,第2列额定功率,第10列采样方式
  1262. row = sheet.GetRow(18);
  1263. UInt16 x = Convert.ToUInt16(lines[DicRowNum["[马达信息]"] + 10].Split(',')[1]);
  1264. row.GetCell(1).SetCellValue((x >> 11).ToString() + ", " + (x & 0x07FF).ToString() + " W");
  1265. row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 4].Split(',')[1]);
  1266. //第20行,第2列额定电流,第10列旋转方向
  1267. row = sheet.GetRow(19);
  1268. x = Convert.ToUInt16(lines[DicRowNum["[马达信息]"] + 11].Split(',')[1]);
  1269. row.GetCell(1).SetCellValue(((float)x / 100f).ToString("0.00") + " A");
  1270. row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 5].Split(',')[1]);
  1271. //第21行,第2列额定电压,第10列功率限幅
  1272. row = sheet.GetRow(20);
  1273. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 12].Split(',')[1].Substring(0, 2) + " V");
  1274. row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 23].Split(',')[1]);
  1275. //第22行,第2列轮胎周长,第10列MOS内阻校准1
  1276. row = sheet.GetRow(21);
  1277. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 2].Split(',')[1] + " cm");
  1278. row.GetCell(9).SetCellValue(MosCalInfo[40].Split(':')[1].ToString().Replace(',', '-'));
  1279. //第23行,第2列传动比,第10列MOS内阻校准2
  1280. row = sheet.GetRow(22);
  1281. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 3].Split(',')[1]);
  1282. row.GetCell(9).SetCellValue(MosCalInfo[41].Split(':')[1].ToString().Replace(',', '-'));
  1283. //第24行,第2列转把限速,第10列MOS内阻校准3
  1284. row = sheet.GetRow(23);
  1285. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 4].Split(',')[1] + " km/h");
  1286. row.GetCell(9).SetCellValue(MosCalInfo[42].Split(':')[1].ToString().Replace(',', '-'));
  1287. //第25行,第2列推行限速,第10列位置校准零点偏差
  1288. row = sheet.GetRow(24);
  1289. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 5].Split(',')[1] + " km/h");
  1290. row.GetCell(9).SetCellValue("± " + MosCalInfo[53].Split(':')[1].ToString());
  1291. //第26行,第2列前牙盘
  1292. row = sheet.GetRow(25);
  1293. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 6].Split(',')[1]);
  1294. //第27行,第2列后牙盘
  1295. row = sheet.GetRow(26);
  1296. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 7].Split(',')[1]);
  1297. //第28行,第2列前灯电压
  1298. row = sheet.GetRow(27);
  1299. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) % 256).ToString() + " V");
  1300. //第29行,第2列尾灯电压
  1301. row = sheet.GetRow(28);
  1302. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) / 256 % 16).ToString() + " V");
  1303. //第30行,第2列尾灯模式
  1304. row = sheet.GetRow(29);
  1305. row.GetCell(1).SetCellValue("Mode " + (Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) / 256 / 16).ToString());
  1306. //第31行,第2列启动模式
  1307. row = sheet.GetRow(30);
  1308. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 12].Split(',')[1]);
  1309. //第32行,第2列开机延迟
  1310. row = sheet.GetRow(31);
  1311. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) / 256 / 16).ToString());
  1312. //第33行,第2列关机延迟
  1313. row = sheet.GetRow(32);
  1314. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) / 256 % 16).ToString());
  1315. //第34行,第2列自动关机时间
  1316. row = sheet.GetRow(33);
  1317. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) % 256).ToString() + " min");
  1318. //第35行,第2列峰值电流
  1319. row = sheet.GetRow(34);
  1320. row.GetCell(1).SetCellValue(lines[DicRowNum["[控制参数]"] + 4].Split(',')[1]);
  1321. #endregion
  1322. using (FileStream file = System.IO.File.OpenWrite(exportExcelName))
  1323. {
  1324. workbook.Write(file);
  1325. workbook.Close();
  1326. }
  1327. }
  1328. catch (Exception ex)
  1329. {
  1330. throw (ex);
  1331. }
  1332. //生成pdf文件
  1333. string exportPdfName = LocalPath + "\\" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1334. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".pdf";
  1335. Workbook workbook_1 = new Workbook();//创建Workbook类的实例
  1336. workbook_1.LoadFromFile(exportExcelName);//加载Excel工作簿
  1337. workbook_1.SaveToFile(exportPdfName, FileFormat.PDF);//将整个工作薄保存为PDF
  1338. //上传
  1339. bool result1 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".src", ServerPath);
  1340. bool result2 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".ttcfg", ServerPath);
  1341. bool result3 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".png", ServerPath);
  1342. bool result4 = myFtp.UploadFile(exportExcelName, ServerPath);
  1343. bool result5 = myFtp.UploadFile(exportPdfName, ServerPath);
  1344. if (result1 & result2 & result3 & result4 & result5)
  1345. {
  1346. MessageBoxTimeOut.Show("上传成功", "提示", 1000, MessageBoxButtons.OK);
  1347. }
  1348. else
  1349. {
  1350. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK);
  1351. }
  1352. }
  1353. //导出本地指定路径
  1354. else
  1355. {
  1356. SaveFileDialog saveFileDialog = new SaveFileDialog();
  1357. saveFileDialog.Filter = "配置文件(*.ttcfg)|*.ttcfg";
  1358. DialogResult result = saveFileDialog.ShowDialog();
  1359. if (result == DialogResult.OK)
  1360. {
  1361. string filePath = saveFileDialog.FileName.Split('.')[0] + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
  1362. //保存src文件
  1363. System.IO.File.WriteAllText(filePath + ".src", richTextBox_AdvanceParams.Text);
  1364. //转换工具检查
  1365. if (Offline_Flag != true) //在线时始终保持最新版本
  1366. {
  1367. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1368. {
  1369. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1370. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1371. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1372. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1373. }
  1374. else
  1375. {
  1376. //程序使用最新版本
  1377. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  1378. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe");
  1379. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1380. //库文件不更新
  1381. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  1382. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1383. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  1384. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1385. }
  1386. }
  1387. else //离线时使用本地
  1388. {
  1389. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1390. {
  1391. MessageBoxTimeOut.Show("转换工具缺失,请连接服务器自动下载", "提示", 1000, MessageBoxButtons.OK);
  1392. return;
  1393. }
  1394. }
  1395. //转换.ttcfg文件
  1396. ProcessStartInfo startInfo = new ProcessStartInfo();
  1397. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  1398. startInfo.Arguments = filePath + ".src";
  1399. System.Diagnostics.Process.Start(startInfo);
  1400. Thread.Sleep(1000);
  1401. MessageBoxTimeOut.Show("导出本地完成", "提示", 1000, MessageBoxButtons.OK);
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }