GenerateParams.cs 70 KB

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