GenerateParams.cs 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  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;
  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_VP_Click(object sender, EventArgs e)
  123. {
  124. textBox_ProductTag.Text = "MM_MV1";
  125. comboBox_SysRunMode.Items.Clear();
  126. comboBox_SysRunMode.Items.Add("NONE");
  127. comboBox_SysRunMode.Items.Add("力矩");
  128. }
  129. private void radioButton_HUB_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 radioButton_HUB_FCT_Click(object sender, EventArgs e)
  137. {
  138. textBox_ProductTag.Text = "GF_250_1";
  139. comboBox_SysRunMode.Items.Clear();
  140. comboBox_SysRunMode.Items.Add("踏频");
  141. comboBox_SysRunMode.Items.Add("力矩");
  142. }
  143. private void comboBox_SysRunMode_Click(object sender, EventArgs e)
  144. {
  145. if ((radioButton_MIGIC.Checked | radioButton_VP.Checked | radioButton_HUB.Checked | radioButton_HUB_FCT.Checked) == false)
  146. {
  147. MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  148. }
  149. }
  150. private void button_ChangeModelFile_Click(object sender, EventArgs e)
  151. {
  152. string DataFileName = "";
  153. string FileInfo = "";
  154. if (comboBox_ModelFile.SelectedIndex == -1)
  155. {
  156. MessageBox.Show("未选择模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  157. return;
  158. }
  159. if (MessageBox.Show("确认修改模板?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  160. {
  161. return;
  162. }
  163. //填写文件名
  164. DataFileName = comboBox_ModelFile.Text;
  165. //分割参数更新参数内容
  166. string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
  167. try
  168. {
  169. //更新信息
  170. do
  171. {
  172. //建立字典,存放并获取每个命令的行号
  173. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  174. DicRowNum.Add("[整车参数]", 0);
  175. DicRowNum.Add("[控制参数]", 0);
  176. DicRowNum.Add("[助力参数]", 0);
  177. DicRowNum.Add("[调试参数]", 0);
  178. DicRowNum.Add("[生产信息]", 0);
  179. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  180. foreach (KeyValuePair<string, int> item in __dict)
  181. {
  182. for (int i = 0; i < lines.Length; i++)
  183. {
  184. if (lines[i].Contains(item.Key))
  185. {
  186. DicRowNum[item.Key] = i;
  187. break;
  188. }
  189. }
  190. }
  191. //遍历更新
  192. foreach (string index in DicRowNum.Keys)
  193. {
  194. int rowNum = DicRowNum[index]; //行号
  195. switch (index)
  196. {
  197. case "[整车参数]":
  198. {
  199. //轮胎周长
  200. lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text;
  201. //转把限速
  202. lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text;
  203. //推行限速
  204. lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text;
  205. //前牙盘
  206. lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text;
  207. //后牙盘
  208. lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text;
  209. //前后灯参数
  210. int LightParams = 0x0000;
  211. if (comboBox_BikeVolF.SelectedIndex == 0)
  212. LightParams |= 0x0006;
  213. else if (comboBox_BikeVolF.SelectedIndex == 1)
  214. LightParams |= 0x000C;
  215. else
  216. {
  217. MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  218. return;
  219. }
  220. if (comboBox_BikeVolB.SelectedIndex == 0)
  221. LightParams |= 0x0600;
  222. else if (comboBox_BikeVolB.SelectedIndex == 1)
  223. LightParams |= 0x0C00;
  224. else
  225. {
  226. MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  227. return;
  228. }
  229. if (comboBox_BikeModeB.SelectedIndex >= 0)
  230. LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12);
  231. else
  232. {
  233. MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  234. return;
  235. }
  236. lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString();
  237. //启动模式
  238. lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString();
  239. //开机延迟
  240. int PowerTime = 0;
  241. PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text);
  242. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8);
  243. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12);
  244. lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString();
  245. break;
  246. }
  247. case "[控制参数]":
  248. {
  249. //峰值电流
  250. lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text;
  251. //过压保护
  252. lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text;
  253. //欠压保护
  254. lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text;
  255. break;
  256. }
  257. case "[助力参数]":
  258. {
  259. //限速起始
  260. lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text;
  261. //限速结束
  262. lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text;
  263. break;
  264. }
  265. case "[调试参数]":
  266. {
  267. //运行模式
  268. lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString();
  269. //旋转方向
  270. lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString();
  271. //功率限幅
  272. lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text;
  273. break;
  274. }
  275. case "[生产信息]":
  276. {
  277. //生产商
  278. lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text;
  279. //生产地
  280. lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text;
  281. //生产日期
  282. lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text;
  283. //产品标识
  284. lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text;
  285. break;
  286. }
  287. default: break;
  288. }
  289. }
  290. } while (false);
  291. //参数更新
  292. richTextBox_AdvanceParams.Clear();
  293. for (int i = 0; i < lines.Length; i++)
  294. {
  295. richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n");
  296. }
  297. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1);
  298. }
  299. catch (System.Exception)
  300. {
  301. MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK);
  302. return;
  303. }
  304. //获取模板文本信息写入文件
  305. FileInfo = richTextBox_AdvanceParams.Text;
  306. if (FileInfo == string.Empty)
  307. {
  308. MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  309. return;
  310. }
  311. System.IO.File.WriteAllText(DataFileName, FileInfo);
  312. //模板文件上传服务器
  313. if (myFtp.CheckFtp() == true)
  314. {
  315. //删除远程文件
  316. myFtp.DeleteFile("/ParamsMode/" + DataFileName);
  317. //上传文件
  318. bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode");
  319. if (result1 == true)
  320. {
  321. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  322. }
  323. else
  324. {
  325. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  326. }
  327. }
  328. else
  329. {
  330. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  331. }
  332. System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName);
  333. }
  334. private void button_DeletModelFile_Click(object sender, EventArgs e)
  335. {
  336. if (comboBox_ModelFile.SelectedIndex == -1)
  337. {
  338. MessageBox.Show("未选择模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  339. }
  340. else
  341. {
  342. Login loginForm = new Login();
  343. loginForm.ShowDialog();
  344. if (loginForm.textBox_Passwd.Text == loginForm.UserAccount[loginForm.comboBox_User.Text])//检验模式所有用户支持
  345. {
  346. if (!loginForm.comboBox_User.Text.Contains("工程参数配置"))
  347. {
  348. MessageBox.Show("权限不支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  349. return;
  350. }
  351. }
  352. else
  353. {
  354. MessageBox.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  355. return;
  356. }
  357. if (myFtp.CheckFtp() == true)
  358. {
  359. //删除远程文件
  360. myFtp.DeleteFile("/ParamsMode/" + comboBox_ModelFile.Text);
  361. comboBox_ModelFile.Items.Clear();
  362. richTextBox_AdvanceParams.Clear();
  363. MessageBox.Show("模板已删除,请刷新!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  364. }
  365. else
  366. {
  367. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  368. }
  369. }
  370. }
  371. /// <summary>
  372. /// 导入样机生产记录文件,可用于生成模板
  373. /// </summary>
  374. /// <param name="sender"></param>
  375. /// <param name="e"></param>
  376. private void button_LoadFile_Click(object sender, EventArgs e)
  377. {
  378. comboBox_ModelFile.SelectedIndex = -1;
  379. button_ExportParams.Enabled = true;
  380. //高级参数只读
  381. richTextBox_AdvanceParams.ReadOnly = true;
  382. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  383. WriteLockStatus = true;
  384. //打开对话框选择文件
  385. OpenFileDialog ofd = new OpenFileDialog();
  386. ofd.Title = "请选择样机测试记录文件";
  387. ofd.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  388. ofd.Filter = "文本文件(*.txt)|*.txt";
  389. ofd.Multiselect = false;
  390. if (ofd.ShowDialog() == DialogResult.OK)
  391. {
  392. //打开文件
  393. StreamReader objReader = new StreamReader(ofd.FileName);
  394. string sLine = "";
  395. ArrayList array_CfgInfo = new ArrayList();
  396. array_CfgInfo.Clear();
  397. while (sLine != null)
  398. {
  399. sLine = objReader.ReadLine();
  400. array_CfgInfo.Add(sLine);
  401. }
  402. objReader.Close();
  403. //转换为模板显示
  404. try
  405. {
  406. string fileInfo = "";
  407. fileInfo += "#说明\r\n";
  408. fileInfo += "#0表示命令无效,1开启该命令的参数写入\r\n";
  409. fileInfo += "\r\n";
  410. fileInfo += "[型号],1\r\n";
  411. fileInfo += "电机型号," + array_CfgInfo[5].ToString().Split(new string[] { ": " }, StringSplitOptions.None)[1] + "\r\n";
  412. fileInfo += "\r\n";
  413. fileInfo += "[SN号],0\r\n";
  414. fileInfo += "电机SN," + "\r\n";
  415. fileInfo += "\r\n";
  416. fileInfo += "[校验码],0\r\n";
  417. fileInfo += "校验码," + "\r\n";
  418. fileInfo += "\r\n";
  419. fileInfo += "[自定义1],0\r\n";
  420. fileInfo += "自定义字符串1," + "\r\n";
  421. fileInfo += "\r\n";
  422. fileInfo += "[自定义2],0\r\n";
  423. fileInfo += "自定义字符串1," + "\r\n";
  424. fileInfo += "\r\n";
  425. fileInfo += "[自定义3],0\r\n";
  426. fileInfo += "自定义字符串1," + "\r\n";
  427. fileInfo += "\r\n";
  428. fileInfo += "[生产信息],1\r\n";
  429. fileInfo += "生产商," + "\r\n";
  430. fileInfo += "生产地," + "\r\n";
  431. fileInfo += "生产日期," + "\r\n";
  432. fileInfo += "产品标识," + "\r\n";
  433. fileInfo += "\r\n";
  434. fileInfo += "[马达信息],1\r\n";
  435. fileInfo += "存储标志,1\r\n";
  436. fileInfo += array_CfgInfo[13].ToString().Replace('=',',').Replace(", ", "\r\n") + "\r\n";
  437. fileInfo += "\r\n";
  438. fileInfo += "[整车参数],1\r\n";
  439. fileInfo += "存储标志,1\r\n";
  440. fileInfo += array_CfgInfo[16].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  441. fileInfo += "\r\n";
  442. fileInfo += "[控制参数],1\r\n";
  443. fileInfo += "存储标志,1\r\n";
  444. fileInfo += array_CfgInfo[19].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  445. fileInfo += "\r\n";
  446. fileInfo += "[力矩传感器参数],1\r\n";
  447. fileInfo += "存储标志,1\r\n";
  448. fileInfo += array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  449. fileInfo += "\r\n";
  450. fileInfo += "[其它传感器参数],1\r\n";
  451. fileInfo += "存储标志,1\r\n";
  452. fileInfo += ("力矩传感器踏频脉冲数" + array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  453. fileInfo += "\r\n";
  454. fileInfo += "[助力参数],1\r\n";
  455. fileInfo += "存储标志,1\r\n";
  456. fileInfo += "空,0\r\n";
  457. fileInfo += array_CfgInfo[25].ToString().Split(new string[] { ", 助力转矩曲线编号" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(" ", "\r\n") + "\r\n";
  458. 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";
  459. 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";
  460. 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";
  461. 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";
  462. 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";
  463. 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";
  464. 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";
  465. 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";
  466. 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";
  467. 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";
  468. 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";
  469. 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";
  470. 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";
  471. 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";
  472. 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";
  473. 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";
  474. 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";
  475. 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";
  476. 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";
  477. 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";
  478. fileInfo += ("助力启动阈值" + array_CfgInfo[25].ToString().Split(new string[] { "助力启动阈值" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  479. fileInfo += "\r\n";
  480. fileInfo += "[调试参数],1\r\n";
  481. fileInfo += "存储标志,1\r\n";
  482. fileInfo += array_CfgInfo[56].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  483. fileInfo += "\r\n";
  484. string FileVer = "";
  485. FileVer = array_CfgInfo[array_CfgInfo.Count - 2].ToString();
  486. if (FileVer.Contains("V2.0")) //2.0版本包含整车参数和用户骑行参数
  487. {
  488. fileInfo += "[整车参数2],1\r\n";
  489. fileInfo += "存储标志,1\r\n";
  490. fileInfo += array_CfgInfo[65].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  491. fileInfo += "\r\n";
  492. fileInfo += "[用户骑行参数],1\r\n";
  493. fileInfo += "存储标志,1\r\n";
  494. fileInfo += array_CfgInfo[68].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  495. }
  496. else //2.0版本前不包含整车参数和用户骑行参数,写0,不转换
  497. {
  498. fileInfo += "[整车参数2],0\r\n\r\n";
  499. fileInfo += "\r\n";
  500. fileInfo += "[用户骑行参数],0\r\n\r\n";
  501. fileInfo += "\r\n";
  502. }
  503. //加载高级界面
  504. richTextBox_AdvanceParams.Clear();
  505. richTextBox_AdvanceParams.AppendText(fileInfo);
  506. //加载简易界面
  507. do //基础参数界面
  508. {
  509. //内容转换行
  510. ArrayList arrText = new ArrayList(fileInfo.Split(new string[] { "\r\n" }, StringSplitOptions.None));//创建一个动态数组
  511. //建立字典,存放并获取每个命令的行号
  512. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  513. DicRowNum.Add("[整车参数]", 0);
  514. DicRowNum.Add("[控制参数]", 0);
  515. DicRowNum.Add("[助力参数]", 0);
  516. DicRowNum.Add("[调试参数]", 0);
  517. DicRowNum.Add("[生产信息]", 0);
  518. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  519. foreach (KeyValuePair<string, int> item in __dict)
  520. {
  521. foreach (string cmd in arrText)
  522. {
  523. if (cmd.Contains(item.Key))
  524. {
  525. DicRowNum[item.Key] = arrText.IndexOf(cmd);
  526. break;
  527. }
  528. }
  529. }
  530. //遍历加载
  531. foreach (string index in DicRowNum.Keys)
  532. {
  533. int rowNum = DicRowNum[index]; //行号
  534. switch (index)
  535. {
  536. case "[整车参数]":
  537. {
  538. //轮胎周长
  539. textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  540. //转把限速
  541. textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  542. //推行限速
  543. textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1];
  544. //前牙盘
  545. textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  546. //后牙盘
  547. textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  548. //前灯电压
  549. ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]);
  550. if ((LightParams & 0x00FF) == 6)
  551. comboBox_BikeVolF.SelectedIndex = 0;
  552. else if ((LightParams & 0x00FF) == 12)
  553. comboBox_BikeVolF.SelectedIndex = 1;
  554. else
  555. comboBox_BikeVolF.SelectedIndex = -1;
  556. //后灯电压
  557. if (((LightParams >> 8) & 0x0F) == 6)
  558. comboBox_BikeVolB.SelectedIndex = 0;
  559. else if (((LightParams >> 8) & 0x0F) == 12)
  560. comboBox_BikeVolB.SelectedIndex = 1;
  561. else
  562. comboBox_BikeVolB.SelectedIndex = -1;
  563. //后灯模式c
  564. comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1;
  565. //启动模式
  566. comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1;
  567. //开机延迟
  568. ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]);
  569. textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString();
  570. //关机延迟
  571. textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString();
  572. //自动关机
  573. textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString();
  574. break;
  575. }
  576. case "[控制参数]":
  577. {
  578. //峰值电流
  579. textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  580. //过压保护
  581. textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  582. //欠压保护
  583. textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  584. break;
  585. }
  586. case "[助力参数]":
  587. {
  588. //限速起始
  589. textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1];
  590. //限速结束
  591. textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1];
  592. break;
  593. }
  594. case "[调试参数]":
  595. {
  596. //运行模式
  597. if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6))
  598. {
  599. comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4;
  600. }
  601. else
  602. comboBox_SysRunMode.SelectedIndex = -1;
  603. //旋转方向
  604. comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]);
  605. //功率限幅
  606. textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1];
  607. break;
  608. }
  609. case "[生产信息]":
  610. {
  611. //生产商
  612. textBox_ProductMac.Text = arrText[rowNum + 1].ToString().Split(',')[1];
  613. //生产地
  614. textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  615. //生产日期
  616. textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
  617. //生产标识
  618. textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  619. break;
  620. }
  621. default: break;
  622. }
  623. }
  624. } while (false);
  625. MessageBoxTimeOut.Show("导入完成!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  626. }
  627. catch (Exception ex)
  628. {
  629. MessageBox.Show("导入错误,请检查导入文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  630. }
  631. }
  632. }
  633. private void pictureBox1_Click(object sender, EventArgs e)
  634. {
  635. if (WriteLockStatus == true)
  636. {
  637. richTextBox_AdvanceParams.ReadOnly = false;
  638. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  639. WriteLockStatus = !WriteLockStatus;
  640. }
  641. else
  642. {
  643. richTextBox_AdvanceParams.ReadOnly = true;
  644. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  645. WriteLockStatus = !WriteLockStatus;
  646. }
  647. }
  648. private void GenerateParams_Load(object sender, EventArgs e)
  649. {
  650. //更新版本信息
  651. label_Ver.Text = "版本: V" + mainForm.Version;
  652. label_BT.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  653. //离线使用标志
  654. Offline_Flag = (mainform1.OfflineFlag == true);
  655. //模板文件服务器路径
  656. ModelPath = "ParamsMode";
  657. //FTP配置
  658. IP = mainform1.ServerIP;
  659. Port = mainform1.ServerPort;
  660. User = mainform1.ServerUser;
  661. PassWD = mainform1.ServerPassWd;
  662. myFtp.FtpOption(IP, Port, User, PassWD, "admin", "ttium_admin");
  663. //检查网络
  664. if (Offline_Flag != true)
  665. {
  666. if (myFtp.CheckFtp() == false)
  667. {
  668. label_Server_ComStatus.Text = "网络已断开";
  669. label_ServerStatus.BackColor = Color.Red;
  670. MessageBox.Show("网络断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  671. this.Close();
  672. }
  673. else
  674. {
  675. label_Server_ComStatus.Text = "网络已连接: " + IP;
  676. label_ServerStatus.BackColor = Color.Green;
  677. }
  678. //加载模板文件
  679. comboBox_ModelFile.Items.Clear();
  680. string[] FileList = { "" };
  681. FileList = myFtp.GetFileNameList(ModelPath);
  682. comboBox_ModelFile.Items.Clear();
  683. foreach (var file in FileList)
  684. {
  685. if (file.Contains(".src"))
  686. {
  687. comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  688. }
  689. }
  690. }
  691. else //离线状态仅支持本地
  692. {
  693. comboBox_ModelFile.Enabled = false;
  694. button_ModeRefresh.Enabled = false;
  695. button_GenerateModelFile.Enabled = false;
  696. button_DeletModelFile.Enabled = false;
  697. button_ChangeModelFile.Enabled = false;
  698. checkBox_SyncFac.Checked = true;
  699. tabPage_Note.Parent = null;
  700. }
  701. }
  702. private void button_ModeRefresh_Click(object sender, EventArgs e)
  703. {
  704. //加载模板文件
  705. comboBox_ModelFile.Items.Clear();
  706. string[] FileList = { "" };
  707. FileList = myFtp.GetFileNameList(ModelPath);
  708. comboBox_ModelFile.Items.Clear();
  709. foreach (var file in FileList)
  710. {
  711. if (file.Contains(".src"))
  712. {
  713. comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  714. }
  715. }
  716. }
  717. private void comboBox_ModelFile_SelectedIndexChanged(object sender, EventArgs e)
  718. {
  719. button_ExportParams.Enabled = true;
  720. //高级参数只读
  721. richTextBox_AdvanceParams.ReadOnly = true;
  722. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  723. WriteLockStatus = true;
  724. if (comboBox_ModelFile.SelectedIndex < 0)
  725. return;
  726. //下载文件
  727. if (System.IO.File.Exists(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text))//本地存在选定文件,先删除本地
  728. {
  729. System.IO.File.Delete(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text);
  730. }
  731. myFtp.DownloadFile("ParamsMode/" + comboBox_ModelFile.Text, localInfo.LocalPath);
  732. //打开文件
  733. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text);
  734. string sLine = "";
  735. ArrayList arrText = new ArrayList();//创建一个动态数组
  736. while (sLine != null)
  737. {
  738. sLine = objReader.ReadLine();
  739. arrText.Add(sLine);
  740. }
  741. objReader.Close();
  742. //加载文件
  743. do //基础参数界面
  744. {
  745. //建立字典,存放并获取每个命令的行号
  746. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  747. DicRowNum.Add("[整车参数]", 0);
  748. DicRowNum.Add("[控制参数]", 0);
  749. DicRowNum.Add("[助力参数]", 0);
  750. DicRowNum.Add("[调试参数]", 0);
  751. DicRowNum.Add("[生产信息]", 0);
  752. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  753. foreach (KeyValuePair<string, int> item in __dict)
  754. {
  755. foreach (string cmd in arrText)
  756. {
  757. if (cmd.Contains(item.Key))
  758. {
  759. DicRowNum[item.Key] = arrText.IndexOf(cmd);
  760. break;
  761. }
  762. }
  763. }
  764. //遍历加载
  765. foreach (string index in DicRowNum.Keys)
  766. {
  767. int rowNum = DicRowNum[index]; //行号
  768. switch (index)
  769. {
  770. case "[整车参数]":
  771. {
  772. //轮胎周长
  773. textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  774. //转把限速
  775. textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  776. //推行限速
  777. textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1];
  778. //前牙盘
  779. textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  780. //后牙盘
  781. textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  782. //前灯电压
  783. ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]);
  784. if ((LightParams & 0x00FF) == 6)
  785. comboBox_BikeVolF.SelectedIndex = 0;
  786. else if ((LightParams & 0x00FF) == 12)
  787. comboBox_BikeVolF.SelectedIndex = 1;
  788. else
  789. comboBox_BikeVolF.SelectedIndex = -1;
  790. //后灯电压
  791. if (((LightParams >> 8) & 0x0F) == 6)
  792. comboBox_BikeVolB.SelectedIndex = 0;
  793. else if (((LightParams >> 8) & 0x0F) == 12)
  794. comboBox_BikeVolB.SelectedIndex = 1;
  795. else
  796. comboBox_BikeVolB.SelectedIndex = -1;
  797. //后灯模式c
  798. comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1;
  799. //启动模式
  800. comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1;
  801. //开机延迟
  802. ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]);
  803. textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString();
  804. //关机延迟
  805. textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString();
  806. //自动关机
  807. textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString();
  808. break;
  809. }
  810. case "[控制参数]":
  811. {
  812. //峰值电流
  813. textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  814. //过压保护
  815. textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  816. //欠压保护
  817. textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  818. break;
  819. }
  820. case "[助力参数]":
  821. {
  822. //限速起始
  823. textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1];
  824. //限速结束
  825. textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1];
  826. break;
  827. }
  828. case "[调试参数]":
  829. {
  830. //运行模式
  831. if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6))
  832. {
  833. comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4;
  834. }
  835. else
  836. comboBox_SysRunMode.SelectedIndex = -1;
  837. //旋转方向
  838. comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]);
  839. //功率限幅
  840. textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1];
  841. break;
  842. }
  843. case "[生产信息]":
  844. {
  845. //生产商
  846. textBox_ProductMac.Text= arrText[rowNum + 1].ToString().Split(',')[1];
  847. //生产地
  848. textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  849. //生产日期
  850. textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
  851. //生产标识
  852. textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  853. break;
  854. }
  855. default:break;
  856. }
  857. }
  858. } while (false);
  859. do //高级参数界面
  860. {
  861. richTextBox_AdvanceParams.Clear();
  862. foreach (string sOutput in arrText)
  863. {
  864. richTextBox_AdvanceParams.AppendText(sOutput + "\r\n");
  865. }
  866. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 2);
  867. } while (false);
  868. }
  869. private void button_GenerateModelFile_Click(object sender, EventArgs e)
  870. {
  871. string DataFileName = "";
  872. string FileInfo = "";
  873. //填写文件名
  874. Scan ModeFileName = new Scan();
  875. ModeFileName.ShowDialog();
  876. if (ModeFileName.textBox_Scan.Text == string.Empty)
  877. {
  878. MessageBox.Show("文件名为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  879. return;
  880. }
  881. DataFileName = ModeFileName.textBox_Scan.Text + ".src";
  882. //核对文件名格式
  883. //...
  884. //获取模板文本信息写入文件
  885. FileInfo = richTextBox_AdvanceParams.Text;
  886. if (FileInfo == string.Empty)
  887. {
  888. MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  889. return;
  890. }
  891. System.IO.File.WriteAllText(DataFileName, FileInfo);
  892. //模板文件上传服务器
  893. if (myFtp.CheckFtp() == true)
  894. {
  895. //上传文件
  896. bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode");
  897. if (result1 == true)
  898. {
  899. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  900. }
  901. else
  902. {
  903. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  904. }
  905. }
  906. else
  907. {
  908. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  909. }
  910. System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName);
  911. }
  912. private void button_ExportParams_Click(object sender, EventArgs e)
  913. {
  914. //检查
  915. if ((radioButton_MIGIC.Checked | radioButton_VP.Checked | radioButton_HUB.Checked | radioButton_HUB_FCT.Checked) == false)
  916. {
  917. MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  918. return;
  919. }
  920. //不导出到本地时需填写完整订单信息
  921. if (!checkBox_SyncFac.Checked)
  922. {
  923. foreach (Control c in groupBox1.Controls)
  924. {
  925. if (c is TextBox)
  926. {
  927. if (c.Text == "")
  928. {
  929. MessageBox.Show("信息填写不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  930. return;
  931. }
  932. if (c.Text.Contains('_'))
  933. {
  934. if ((c.Name != "textBox_ProductTag") && (c.Name != "textBox_SoftwareVer"))
  935. {
  936. MessageBox.Show("\"" + c.Text + "\"" + "包含字符'_'", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  937. return;
  938. }
  939. }
  940. }
  941. }
  942. }
  943. //分割参数
  944. string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
  945. try
  946. {
  947. //更新信息
  948. do
  949. {
  950. //建立字典,存放并获取每个命令的行号
  951. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  952. DicRowNum.Add("[整车参数]", 0);
  953. DicRowNum.Add("[控制参数]", 0);
  954. DicRowNum.Add("[助力参数]", 0);
  955. DicRowNum.Add("[调试参数]", 0);
  956. DicRowNum.Add("[生产信息]", 0);
  957. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  958. foreach (KeyValuePair<string, int> item in __dict)
  959. {
  960. for (int i = 0; i < lines.Length; i++)
  961. {
  962. if (lines[i].Contains(item.Key))
  963. {
  964. DicRowNum[item.Key] = i;
  965. break;
  966. }
  967. }
  968. }
  969. //遍历更新
  970. foreach (string index in DicRowNum.Keys)
  971. {
  972. int rowNum = DicRowNum[index]; //行号
  973. switch (index)
  974. {
  975. case "[整车参数]":
  976. {
  977. //轮胎周长
  978. lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text;
  979. //转把限速
  980. lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text;
  981. //推行限速
  982. lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text;
  983. //前牙盘
  984. lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text;
  985. //后牙盘
  986. lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text;
  987. //前后灯参数
  988. int LightParams = 0x0000;
  989. if (comboBox_BikeVolF.SelectedIndex == 0)
  990. LightParams |= 0x0006;
  991. else if (comboBox_BikeVolF.SelectedIndex == 1)
  992. LightParams |= 0x000C;
  993. else
  994. {
  995. MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  996. return;
  997. }
  998. if (comboBox_BikeVolB.SelectedIndex == 0)
  999. LightParams |= 0x0600;
  1000. else if (comboBox_BikeVolB.SelectedIndex == 1)
  1001. LightParams |= 0x0C00;
  1002. else
  1003. {
  1004. MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1005. return;
  1006. }
  1007. if (comboBox_BikeModeB.SelectedIndex >= 0)
  1008. LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12);
  1009. else
  1010. {
  1011. MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1012. return;
  1013. }
  1014. lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString();
  1015. //启动模式
  1016. lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString();
  1017. //开机延迟
  1018. int PowerTime = 0;
  1019. PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text);
  1020. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8);
  1021. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12);
  1022. lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString();
  1023. break;
  1024. }
  1025. case "[控制参数]":
  1026. {
  1027. //峰值电流
  1028. lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text;
  1029. //过压保护
  1030. lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text;
  1031. //欠压保护
  1032. lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text;
  1033. break;
  1034. }
  1035. case "[助力参数]":
  1036. {
  1037. //限速起始
  1038. lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text;
  1039. //限速结束
  1040. lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text;
  1041. break;
  1042. }
  1043. case "[调试参数]":
  1044. {
  1045. //运行模式
  1046. lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString();
  1047. //旋转方向
  1048. lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString();
  1049. //功率限幅
  1050. lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text;
  1051. break;
  1052. }
  1053. case "[生产信息]":
  1054. {
  1055. //生产商
  1056. lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text;
  1057. //生产地
  1058. lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text;
  1059. //生产日期
  1060. lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text;
  1061. //产品标识
  1062. lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text;
  1063. break;
  1064. }
  1065. default: break;
  1066. }
  1067. }
  1068. } while (false);
  1069. //参数更新
  1070. richTextBox_AdvanceParams.Clear();
  1071. for (int i = 0; i < lines.Length; i++)
  1072. {
  1073. richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n");
  1074. }
  1075. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1);
  1076. }
  1077. catch (System.Exception)
  1078. {
  1079. MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK);
  1080. return;
  1081. }
  1082. //不导出本地时,上传服务器
  1083. if (!checkBox_SyncFac.Checked)
  1084. {
  1085. //确定本地保存路径
  1086. string Date = DateTime.Now.ToString("yyyy-MM-dd");
  1087. string LocalPath = localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + Date;
  1088. if (!Directory.Exists(LocalPath))
  1089. {
  1090. Directory.CreateDirectory(LocalPath);
  1091. }
  1092. //确定远程保存路径
  1093. string ServerPath = "";
  1094. if (radioButton_HUB.Checked)
  1095. {
  1096. if (!myFtp.DirectoryExist("HUB_Control_TEST/cfg", Date))
  1097. myFtp.MakeDir("HUB_Control_TEST/cfg" + "/" + Date);
  1098. ServerPath = "HUB_Control_TEST/cfg" + "/" + Date;
  1099. }
  1100. else if (radioButton_MIGIC.Checked)
  1101. {
  1102. if (!myFtp.DirectoryExist("MIGIC_TEST/cfg", Date))
  1103. myFtp.MakeDir("MIGIC_TEST/cfg" + "/" + Date);
  1104. ServerPath = "MIGIC_TEST/cfg" + "/" + Date;
  1105. }
  1106. else if (radioButton_VP.Checked)
  1107. {
  1108. if (!myFtp.DirectoryExist("MC_VP_TEST/cfg", Date))
  1109. myFtp.MakeDir("MC_VP_TEST/cfg" + "/" + Date);
  1110. ServerPath = "MC_VP_TEST/cfg" + "/" + Date;
  1111. }
  1112. else if (radioButton_HUB_FCT.Checked)
  1113. {
  1114. if (!myFtp.DirectoryExist("HUB_Control_FCT/cfg", Date))
  1115. myFtp.MakeDir("HUB_Control_FCT/cfg" + "/" + Date);
  1116. ServerPath = "HUB_Control_FCT/cfg" + "/" + Date;
  1117. }
  1118. //确定文件名
  1119. string fileName = "";
  1120. fileName = textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1121. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + textBox_SoftwareVer.Text + "_" +
  1122. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "-");
  1123. //保存.src文件
  1124. System.IO.File.WriteAllText(LocalPath + "\\" + fileName + ".src", richTextBox_AdvanceParams.Text);
  1125. //检查是否存在转换工具
  1126. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1127. {
  1128. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1129. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1130. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1131. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1132. }
  1133. else
  1134. {
  1135. //程序使用最新版本
  1136. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  1137. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe");
  1138. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1139. //库文件不更新
  1140. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  1141. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1142. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  1143. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1144. }
  1145. //转换.ttcfg文件
  1146. ProcessStartInfo startInfo = new ProcessStartInfo();
  1147. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  1148. startInfo.Arguments = "\"" + LocalPath + "\\" + fileName + ".src" + "\"";
  1149. System.Diagnostics.Process.Start(startInfo);
  1150. Thread.Sleep(1000);
  1151. //保存页面
  1152. Double scaleX = PrimaryScreen.ScaleX;
  1153. Double scaleY = PrimaryScreen.ScaleY;
  1154. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  1155. Graphics g = Graphics.FromImage(bit);
  1156. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  1157. bit.Save(LocalPath + "\\" + fileName + ".png");
  1158. //写入excel表格
  1159. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName)) //删除本地模板,从服务器下载最新模板
  1160. {
  1161. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName);
  1162. }
  1163. myFtp.DownloadFile("Tools/GenerateParamsFile/" + localInfo.ExcelTempleFileName, localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1164. string importExcelName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + localInfo.ExcelTempleFileName;
  1165. string exportExcelName = LocalPath + "\\" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1166. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".xls";
  1167. try
  1168. {
  1169. string sLine = "";
  1170. //读取力矩传感器范围
  1171. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.TorqueSensorFileName);
  1172. List<string> TorqueInfo = new List<string>();
  1173. while (sLine != null)
  1174. {
  1175. sLine = objReader.ReadLine();
  1176. TorqueInfo.Add(sLine);
  1177. }
  1178. objReader.Close();
  1179. //读取MOS校准参数
  1180. objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  1181. sLine = "";
  1182. List<string> MosCalInfo = new List<string>();
  1183. while (sLine != null)
  1184. {
  1185. sLine = objReader.ReadLine();
  1186. MosCalInfo.Add(sLine);
  1187. }
  1188. objReader.Close();
  1189. int index_MosCal = Array.IndexOf(MosCalInfo.ToArray(), "[MosCalK]");
  1190. int index_AngleCal = Array.IndexOf(MosCalInfo.ToArray(), "[AngleCal]");
  1191. //导入模板文件
  1192. NPOI.SS.UserModel.IWorkbook workbook = WorkbookFactory.Create(importExcelName);
  1193. //获取第一个工作薄
  1194. ISheet sheet = workbook.GetSheetAt(0);
  1195. //建立字典,获取并存放并获取每个命令的起始行号
  1196. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  1197. DicRowNum.Add("[马达信息]", 0);
  1198. DicRowNum.Add("[整车参数]", 0);
  1199. DicRowNum.Add("[控制参数]", 0);
  1200. DicRowNum.Add("[其它传感器参数]", 0);
  1201. DicRowNum.Add("[助力参数]", 0);
  1202. DicRowNum.Add("[调试参数]", 0);
  1203. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  1204. foreach (KeyValuePair<string, int> item in __dict)
  1205. {
  1206. for (int i = 0; i < lines.Length; i++)
  1207. {
  1208. if (lines[i].Contains(item.Key))
  1209. {
  1210. DicRowNum[item.Key] = i;
  1211. break;
  1212. }
  1213. }
  1214. }
  1215. #region 开始按行写入数据
  1216. //第3行,文件信息
  1217. IRow row = sheet.GetRow(2);
  1218. row.GetCell(0).SetCellValue("文件信息 File Info:" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1219. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss"));
  1220. //第5行,第2列型号,定制功能使能标志
  1221. row = sheet.GetRow(4);
  1222. row.GetCell(1).SetCellValue(textBox_ProductName.Text);
  1223. row.GetCell(9).SetCellValue(lines[DicRowNum["[控制参数]"] + 15].Split(',')[1]);
  1224. //第6行,第2列序列号,第10列力矩传感器零点范围
  1225. row = sheet.GetRow(5);
  1226. row.GetCell(1).SetCellValue("Same as marking label");
  1227. row.GetCell(9).SetCellValue(TorqueInfo[0].Split(',')[1] + "-" + TorqueInfo[0].Split(',')[2]);
  1228. //第7行,第2列PCBA板号,第10列力矩传感器标定1范围
  1229. row = sheet.GetRow(6);
  1230. row.GetCell(1).SetCellValue(textBox_PCBA.Text);
  1231. row.GetCell(9).SetCellValue(TorqueInfo[1].Split(',')[0] + ": " + TorqueInfo[1].Split(',')[1] + "-" + TorqueInfo[1].Split(',')[2]);
  1232. //第8行,第2列软件版本,第10列力矩传感器标定2范围
  1233. row = sheet.GetRow(7);
  1234. row.GetCell(1).SetCellValue(textBox_SoftwareVer.Text);
  1235. row.GetCell(9).SetCellValue(TorqueInfo[2].Split(',')[0] + ": " + TorqueInfo[2].Split(',')[1] + "-" + TorqueInfo[2].Split(',')[2]);
  1236. //第9行,第2列Bootloader版本,第10列力矩传感器标定3范围
  1237. row = sheet.GetRow(8);
  1238. row.GetCell(1).SetCellValue("250K");
  1239. row.GetCell(9).SetCellValue(TorqueInfo[3].Split(',')[0] + ": " + TorqueInfo[3].Split(',')[1] + "-" + TorqueInfo[3].Split(',')[2]);
  1240. //第10行,第2列静态母线电压范围,第10列力矩传感器标定4范围
  1241. row = sheet.GetRow(9);
  1242. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 12].Split(',')[1].Substring(0, 2) + " ± 1V");
  1243. row.GetCell(9).SetCellValue(TorqueInfo[4].Split(',')[0] + ": " + TorqueInfo[4].Split(',')[1] + "-" + TorqueInfo[4].Split(',')[2]);
  1244. //第11行,第2列静态母线电流范围,第10列力矩传感器踏频脉冲数
  1245. row = sheet.GetRow(10);
  1246. row.GetCell(1).SetCellValue("≤ 0.050 A");
  1247. row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 2].Split(',')[1]);
  1248. //第12行,第2列极对数,第10列车速传感器脉冲数
  1249. row = sheet.GetRow(11);
  1250. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 2].Split(',')[1]);
  1251. row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 3].Split(',')[1]);
  1252. //第13行,第2列相电阻,第10列踏频传感器脉冲数
  1253. row = sheet.GetRow(12);
  1254. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 3].Split(',')[1]);
  1255. row.GetCell(9).SetCellValue(lines[DicRowNum["[其它传感器参数]"] + 4].Split(',')[1]);
  1256. //第14行,第2列d轴电感,第10列助力启动阈值
  1257. row = sheet.GetRow(13);
  1258. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 4].Split(',')[1]);
  1259. row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 85].Split(',')[1]);
  1260. //第15行,第2列q轴电感,第10列助力停机阈值
  1261. row = sheet.GetRow(14);
  1262. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 5].Split(',')[1]);
  1263. row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 86].Split(',')[1]);
  1264. //第16行,第2列永磁体磁链,第10列限速起始值
  1265. row = sheet.GetRow(15);
  1266. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 6].Split(',')[1]);
  1267. row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 92].Split(',')[1] + " km/h");
  1268. //第17行,第2列Id最小值,第10列限速停机值
  1269. row = sheet.GetRow(16);
  1270. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 8].Split(',')[1]);
  1271. row.GetCell(9).SetCellValue(lines[DicRowNum["[助力参数]"] + 93].Split(',')[1] + " km/h");
  1272. //第18行,第2列额定转速,第10列运行模式
  1273. row = sheet.GetRow(17);
  1274. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 9].Split(',')[1] + " rpm");
  1275. row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 2].Split(',')[1]);
  1276. //第19行,第2列额定功率,第10列采样方式
  1277. row = sheet.GetRow(18);
  1278. UInt16 x = Convert.ToUInt16(lines[DicRowNum["[马达信息]"] + 10].Split(',')[1]);
  1279. row.GetCell(1).SetCellValue((x >> 11).ToString() + ", " + (x & 0x07FF).ToString() + " W");
  1280. row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 4].Split(',')[1]);
  1281. //第20行,第2列额定电流,第10列旋转方向
  1282. row = sheet.GetRow(19);
  1283. x = Convert.ToUInt16(lines[DicRowNum["[马达信息]"] + 11].Split(',')[1]);
  1284. row.GetCell(1).SetCellValue(((float)x / 100f).ToString("0.00") + " A");
  1285. row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 5].Split(',')[1]);
  1286. //第21行,第2列额定电压,第10列功率限幅
  1287. row = sheet.GetRow(20);
  1288. row.GetCell(1).SetCellValue(lines[DicRowNum["[马达信息]"] + 12].Split(',')[1].Substring(0, 2) + " V");
  1289. row.GetCell(9).SetCellValue(lines[DicRowNum["[调试参数]"] + 23].Split(',')[1]);
  1290. //第22行,第2列轮胎周长,第10列MOS内阻校准1
  1291. row = sheet.GetRow(21);
  1292. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 2].Split(',')[1] + " cm");
  1293. row.GetCell(9).SetCellValue(MosCalInfo[index_MosCal + 2].Split(':')[1].ToString().Replace(',', '-'));
  1294. //第23行,第2列传动比,第10列MOS内阻校准2
  1295. row = sheet.GetRow(22);
  1296. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 3].Split(',')[1]);
  1297. row.GetCell(9).SetCellValue(MosCalInfo[index_MosCal + 3].Split(':')[1].ToString().Replace(',', '-'));
  1298. //第24行,第2列转把限速,第10列MOS内阻校准3
  1299. row = sheet.GetRow(23);
  1300. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 4].Split(',')[1] + " km/h");
  1301. row.GetCell(9).SetCellValue(MosCalInfo[index_MosCal + 4].Split(':')[1].ToString().Replace(',', '-'));
  1302. //第25行,第2列推行限速,第10列位置校准零点偏差
  1303. row = sheet.GetRow(24);
  1304. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 5].Split(',')[1] + " km/h");
  1305. row.GetCell(9).SetCellValue("± " + MosCalInfo[index_AngleCal + 2].Split(':')[1].ToString());
  1306. //第26行,第2列前牙盘
  1307. row = sheet.GetRow(25);
  1308. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 6].Split(',')[1]);
  1309. //第27行,第2列后牙盘
  1310. row = sheet.GetRow(26);
  1311. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 7].Split(',')[1]);
  1312. //第28行,第2列前灯电压
  1313. row = sheet.GetRow(27);
  1314. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) % 256).ToString() + " V");
  1315. //第29行,第2列尾灯电压
  1316. row = sheet.GetRow(28);
  1317. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) / 256 % 16).ToString() + " V");
  1318. //第30行,第2列尾灯模式
  1319. row = sheet.GetRow(29);
  1320. row.GetCell(1).SetCellValue("Mode " + (Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 10].Split(',')[1]) / 256 / 16).ToString());
  1321. //第31行,第2列启动模式
  1322. row = sheet.GetRow(30);
  1323. row.GetCell(1).SetCellValue(lines[DicRowNum["[整车参数]"] + 12].Split(',')[1]);
  1324. //第32行,第2列开机延迟
  1325. row = sheet.GetRow(31);
  1326. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) / 256 / 16).ToString());
  1327. //第33行,第2列关机延迟
  1328. row = sheet.GetRow(32);
  1329. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) / 256 % 16).ToString());
  1330. //第34行,第2列自动关机时间
  1331. row = sheet.GetRow(33);
  1332. row.GetCell(1).SetCellValue((Convert.ToUInt16(lines[DicRowNum["[整车参数]"] + 13].Split(',')[1]) % 256).ToString() + " min");
  1333. //第35行,第2列峰值电流
  1334. row = sheet.GetRow(34);
  1335. row.GetCell(1).SetCellValue(lines[DicRowNum["[控制参数]"] + 4].Split(',')[1]);
  1336. #endregion
  1337. using (FileStream file = System.IO.File.OpenWrite(exportExcelName))
  1338. {
  1339. workbook.Write(file);
  1340. workbook.Close();
  1341. }
  1342. }
  1343. catch (Exception ex)
  1344. {
  1345. throw (ex);
  1346. }
  1347. //生成pdf文件
  1348. string exportPdfName = LocalPath + "\\" + textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1349. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".pdf";
  1350. Workbook workbook_1 = new Workbook();//创建Workbook类的实例
  1351. workbook_1.LoadFromFile(exportExcelName);//加载Excel工作簿
  1352. workbook_1.SaveToFile(exportPdfName, FileFormat.PDF);//将整个工作薄保存为PDF
  1353. //上传
  1354. bool result1 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".src", ServerPath);
  1355. bool result2 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".ttcfg", ServerPath);
  1356. bool result3 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".png", ServerPath);
  1357. bool result4 = myFtp.UploadFile(exportExcelName, ServerPath);
  1358. bool result5 = myFtp.UploadFile(exportPdfName, ServerPath);
  1359. if (result1 & result2 & result3 & result4 & result5)
  1360. {
  1361. MessageBoxTimeOut.Show("上传成功", "提示", 1000, MessageBoxButtons.OK);
  1362. }
  1363. else
  1364. {
  1365. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK);
  1366. }
  1367. }
  1368. //导出本地指定路径
  1369. else
  1370. {
  1371. SaveFileDialog saveFileDialog = new SaveFileDialog();
  1372. saveFileDialog.Filter = "配置文件(*.ttcfg)|*.ttcfg";
  1373. DialogResult result = saveFileDialog.ShowDialog();
  1374. if (result == DialogResult.OK)
  1375. {
  1376. string filePath = saveFileDialog.FileName.Split('.')[0] + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
  1377. //保存src文件
  1378. System.IO.File.WriteAllText(filePath + ".src", richTextBox_AdvanceParams.Text);
  1379. //转换工具检查
  1380. if (Offline_Flag != true) //在线时始终保持最新版本
  1381. {
  1382. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1383. {
  1384. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1385. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1386. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1387. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1388. }
  1389. else
  1390. {
  1391. //程序使用最新版本
  1392. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  1393. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe");
  1394. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1395. //库文件不更新
  1396. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  1397. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1398. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  1399. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1400. }
  1401. }
  1402. else //离线时使用本地
  1403. {
  1404. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1405. {
  1406. MessageBoxTimeOut.Show("转换工具缺失,请连接服务器自动下载", "提示", 1000, MessageBoxButtons.OK);
  1407. return;
  1408. }
  1409. }
  1410. //转换.ttcfg文件
  1411. ProcessStartInfo startInfo = new ProcessStartInfo();
  1412. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  1413. startInfo.Arguments = filePath + ".src";
  1414. System.Diagnostics.Process.Start(startInfo);
  1415. Thread.Sleep(1000);
  1416. MessageBoxTimeOut.Show("导出本地完成", "提示", 1000, MessageBoxButtons.OK);
  1417. }
  1418. }
  1419. }
  1420. }
  1421. }