GenerateParams.cs 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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. fileInfo += "[自定义1],0\r\n";
  404. fileInfo += "自定义字符串1," + "\r\n";
  405. fileInfo += "\r\n";
  406. fileInfo += "[自定义2],0\r\n";
  407. fileInfo += "自定义字符串1," + "\r\n";
  408. fileInfo += "\r\n";
  409. fileInfo += "[自定义3],0\r\n";
  410. fileInfo += "自定义字符串1," + "\r\n";
  411. fileInfo += "\r\n";
  412. fileInfo += "[生产信息],1\r\n";
  413. fileInfo += "生产商," + "\r\n";
  414. fileInfo += "生产地," + "\r\n";
  415. fileInfo += "生产日期," + "\r\n";
  416. fileInfo += "产品标识," + "\r\n";
  417. fileInfo += "\r\n";
  418. fileInfo += "[马达信息],1\r\n";
  419. fileInfo += "存储标志,1\r\n";
  420. fileInfo += array_CfgInfo[13].ToString().Replace('=',',').Replace(", ", "\r\n") + "\r\n";
  421. fileInfo += "\r\n";
  422. fileInfo += "[整车参数],1\r\n";
  423. fileInfo += "存储标志,1\r\n";
  424. fileInfo += array_CfgInfo[16].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  425. fileInfo += "\r\n";
  426. fileInfo += "[控制参数],1\r\n";
  427. fileInfo += "存储标志,1\r\n";
  428. fileInfo += array_CfgInfo[19].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  429. fileInfo += "\r\n";
  430. fileInfo += "[力矩传感器参数],1\r\n";
  431. fileInfo += "存储标志,1\r\n";
  432. fileInfo += array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  433. fileInfo += "\r\n";
  434. fileInfo += "[其它传感器参数],1\r\n";
  435. fileInfo += "存储标志,1\r\n";
  436. fileInfo += ("力矩传感器踏频脉冲数" + array_CfgInfo[22].ToString().Split(new string[] { ", 力矩传感器踏频脉冲数" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  437. fileInfo += "\r\n";
  438. fileInfo += "[助力参数],1\r\n";
  439. fileInfo += "存储标志,1\r\n";
  440. fileInfo += "空,0\r\n";
  441. fileInfo += array_CfgInfo[25].ToString().Split(new string[] { ", 助力转矩曲线编号" }, StringSplitOptions.None)[0].Replace('=', ',').Replace(" ", "\r\n") + "\r\n";
  442. 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";
  443. 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";
  444. 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";
  445. 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";
  446. 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";
  447. 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";
  448. 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";
  449. 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";
  450. 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";
  451. 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";
  452. 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";
  453. 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";
  454. 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";
  455. 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";
  456. 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";
  457. 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";
  458. 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";
  459. 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";
  460. 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";
  461. 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";
  462. fileInfo += ("助力启动阈值" + array_CfgInfo[25].ToString().Split(new string[] { "助力启动阈值" }, StringSplitOptions.None)[1]).Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  463. fileInfo += "\r\n";
  464. fileInfo += "[调试参数],1\r\n";
  465. fileInfo += "存储标志,1\r\n";
  466. fileInfo += array_CfgInfo[56].ToString().Replace('=', ',').Replace(", ", "\r\n") + "\r\n";
  467. //加载高级界面
  468. richTextBox_AdvanceParams.Clear();
  469. richTextBox_AdvanceParams. AppendText(fileInfo);
  470. //加载简易界面
  471. do //基础参数界面
  472. {
  473. //内容转换行
  474. ArrayList arrText = new ArrayList(fileInfo.Split(new string[] { "\r\n" }, StringSplitOptions.None));//创建一个动态数组
  475. //建立字典,存放并获取每个命令的行号
  476. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  477. DicRowNum.Add("[整车参数]", 0);
  478. DicRowNum.Add("[控制参数]", 0);
  479. DicRowNum.Add("[助力参数]", 0);
  480. DicRowNum.Add("[调试参数]", 0);
  481. DicRowNum.Add("[生产信息]", 0);
  482. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  483. foreach (KeyValuePair<string, int> item in __dict)
  484. {
  485. foreach (string cmd in arrText)
  486. {
  487. if (cmd.Contains(item.Key))
  488. {
  489. DicRowNum[item.Key] = arrText.IndexOf(cmd);
  490. break;
  491. }
  492. }
  493. }
  494. //遍历加载
  495. foreach (string index in DicRowNum.Keys)
  496. {
  497. int rowNum = DicRowNum[index]; //行号
  498. switch (index)
  499. {
  500. case "[整车参数]":
  501. {
  502. //轮胎周长
  503. textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  504. //转把限速
  505. textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  506. //推行限速
  507. textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1];
  508. //前牙盘
  509. textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  510. //后牙盘
  511. textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  512. //前灯电压
  513. ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]);
  514. if ((LightParams & 0x00FF) == 6)
  515. comboBox_BikeVolF.SelectedIndex = 0;
  516. else if ((LightParams & 0x00FF) == 12)
  517. comboBox_BikeVolF.SelectedIndex = 1;
  518. else
  519. comboBox_BikeVolF.SelectedIndex = -1;
  520. //后灯电压
  521. if (((LightParams >> 8) & 0x0F) == 6)
  522. comboBox_BikeVolB.SelectedIndex = 0;
  523. else if (((LightParams >> 8) & 0x0F) == 12)
  524. comboBox_BikeVolB.SelectedIndex = 1;
  525. else
  526. comboBox_BikeVolB.SelectedIndex = -1;
  527. //后灯模式c
  528. comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1;
  529. //启动模式
  530. comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1;
  531. //开机延迟
  532. ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]);
  533. textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString();
  534. //关机延迟
  535. textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString();
  536. //自动关机
  537. textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString();
  538. break;
  539. }
  540. case "[控制参数]":
  541. {
  542. //峰值电流
  543. textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  544. //过压保护
  545. textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  546. //欠压保护
  547. textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  548. break;
  549. }
  550. case "[助力参数]":
  551. {
  552. //限速起始
  553. textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1];
  554. //限速结束
  555. textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1];
  556. break;
  557. }
  558. case "[调试参数]":
  559. {
  560. //运行模式
  561. if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6))
  562. {
  563. comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4;
  564. }
  565. else
  566. comboBox_SysRunMode.SelectedIndex = -1;
  567. //旋转方向
  568. comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]);
  569. //功率限幅
  570. textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1];
  571. break;
  572. }
  573. case "[生产信息]":
  574. {
  575. //生产商
  576. textBox_ProductMac.Text = arrText[rowNum + 1].ToString().Split(',')[1];
  577. //生产地
  578. textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  579. //生产日期
  580. textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
  581. //生产标识
  582. textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  583. break;
  584. }
  585. default: break;
  586. }
  587. }
  588. } while (false);
  589. MessageBoxTimeOut.Show("导入完成!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  590. }
  591. catch (Exception ex)
  592. {
  593. MessageBox.Show("导入错误,请检查导入文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  594. }
  595. }
  596. }
  597. private void pictureBox1_Click(object sender, EventArgs e)
  598. {
  599. if (WriteLockStatus == true)
  600. {
  601. richTextBox_AdvanceParams.ReadOnly = false;
  602. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Unlock;
  603. WriteLockStatus = !WriteLockStatus;
  604. }
  605. else
  606. {
  607. richTextBox_AdvanceParams.ReadOnly = true;
  608. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  609. WriteLockStatus = !WriteLockStatus;
  610. }
  611. }
  612. private void GenerateParams_Load(object sender, EventArgs e)
  613. {
  614. //更新版本信息
  615. label_Ver.Text = "版本: V" + mainForm.Version;
  616. label_BT.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  617. //导入网络配置
  618. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  619. {
  620. //打开文件
  621. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  622. string sLine = "";
  623. ArrayList array_CfgInfo = new ArrayList();
  624. array_CfgInfo.Clear();
  625. while (sLine != null)
  626. {
  627. sLine = objReader.ReadLine();
  628. array_CfgInfo.Add(sLine);
  629. }
  630. objReader.Close();
  631. //解析配置文件
  632. try
  633. {
  634. //Server Set IP, Port, User, PassWS, ModelPath;
  635. IP = array_CfgInfo[12].ToString().Split(':')[1];
  636. Port = array_CfgInfo[13].ToString().Split(':')[1];
  637. User = array_CfgInfo[14].ToString().Split(':')[1];
  638. PassWD = array_CfgInfo[15].ToString().Split(':')[1];
  639. ModelPath = "ParamsMode";
  640. myFtp.FtpOption(IP, Port, User, PassWD, "admin", "ttium_admin");
  641. }
  642. catch (System.Exception)
  643. {
  644. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  645. }
  646. }
  647. else
  648. {
  649. MessageBox.Show("参数文件丢失!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  650. this.Close();
  651. }
  652. //检查网络
  653. if (myFtp.CheckFtp() == false)
  654. {
  655. label_Server_ComStatus.Text = "网络已断开";
  656. label_ServerStatus.BackColor = Color.Red;
  657. MessageBox.Show("网络断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  658. this.Close();
  659. }
  660. else
  661. {
  662. label_Server_ComStatus.Text = "网络已连接: " + IP;
  663. label_ServerStatus.BackColor = Color.Green;
  664. }
  665. //加载模板文件
  666. comboBox_ModelFile.Items.Clear();
  667. string[] FileList = { "" };
  668. FileList = myFtp.GetFileNameList(ModelPath);
  669. comboBox_ModelFile.Items.Clear();
  670. foreach (var file in FileList)
  671. {
  672. if (file.Contains(".src"))
  673. {
  674. comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  675. }
  676. }
  677. }
  678. private void button_ModeRefresh_Click(object sender, EventArgs e)
  679. {
  680. //加载模板文件
  681. comboBox_ModelFile.Items.Clear();
  682. string[] FileList = { "" };
  683. FileList = myFtp.GetFileNameList(ModelPath);
  684. comboBox_ModelFile.Items.Clear();
  685. foreach (var file in FileList)
  686. {
  687. if (file.Contains(".src"))
  688. {
  689. comboBox_ModelFile.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  690. }
  691. }
  692. }
  693. private void comboBox_ModelFile_SelectedIndexChanged(object sender, EventArgs e)
  694. {
  695. button_ExportParams.Enabled = true;
  696. //高级参数只读
  697. richTextBox_AdvanceParams.ReadOnly = true;
  698. pictureBox1.Image = global::Welling_Motor_Debug_Tool.Properties.Resources.Lock;
  699. WriteLockStatus = true;
  700. //下载文件
  701. if (System.IO.File.Exists(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text))//本地存在选定文件,先删除本地
  702. {
  703. System.IO.File.Delete(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text);
  704. }
  705. myFtp.DownloadFile("ParamsMode/" + comboBox_ModelFile.Text, localInfo.LocalPath);
  706. //打开文件
  707. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\" + comboBox_ModelFile.Text);
  708. string sLine = "";
  709. ArrayList arrText = new ArrayList();//创建一个动态数组
  710. while (sLine != null)
  711. {
  712. sLine = objReader.ReadLine();
  713. arrText.Add(sLine);
  714. }
  715. objReader.Close();
  716. //加载文件
  717. do //基础参数界面
  718. {
  719. //建立字典,存放并获取每个命令的行号
  720. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  721. DicRowNum.Add("[整车参数]", 0);
  722. DicRowNum.Add("[控制参数]", 0);
  723. DicRowNum.Add("[助力参数]", 0);
  724. DicRowNum.Add("[调试参数]", 0);
  725. DicRowNum.Add("[生产信息]", 0);
  726. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  727. foreach (KeyValuePair<string, int> item in __dict)
  728. {
  729. foreach (string cmd in arrText)
  730. {
  731. if (cmd.Contains(item.Key))
  732. {
  733. DicRowNum[item.Key] = arrText.IndexOf(cmd);
  734. break;
  735. }
  736. }
  737. }
  738. //遍历加载
  739. foreach (string index in DicRowNum.Keys)
  740. {
  741. int rowNum = DicRowNum[index]; //行号
  742. switch (index)
  743. {
  744. case "[整车参数]":
  745. {
  746. //轮胎周长
  747. textBox_BikeWheel.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  748. //转把限速
  749. textBox_BikeThroSpeed.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  750. //推行限速
  751. textBox_BikeWalkSpeed.Text = arrText[rowNum + 5].ToString().Split(',')[1];
  752. //前牙盘
  753. textBox_BikeFrontT.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  754. //后牙盘
  755. textBox_BikeRealB.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  756. //前灯电压
  757. ushort LightParams = Convert.ToUInt16(arrText[rowNum + 10].ToString().Split(',')[1]);
  758. if ((LightParams & 0x00FF) == 6)
  759. comboBox_BikeVolF.SelectedIndex = 0;
  760. else if ((LightParams & 0x00FF) == 12)
  761. comboBox_BikeVolF.SelectedIndex = 1;
  762. else
  763. comboBox_BikeVolF.SelectedIndex = -1;
  764. //后灯电压
  765. if (((LightParams >> 8) & 0x0F) == 6)
  766. comboBox_BikeVolB.SelectedIndex = 0;
  767. else if (((LightParams >> 8) & 0x0F) == 12)
  768. comboBox_BikeVolB.SelectedIndex = 1;
  769. else
  770. comboBox_BikeVolB.SelectedIndex = -1;
  771. //后灯模式c
  772. comboBox_BikeModeB.SelectedIndex = (LightParams >> 12) - 1;
  773. //启动模式
  774. comboBox_BikeStartMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 12].ToString().Split(',')[1]) - 1;
  775. //开机延迟
  776. ushort PowerOnOffParams = Convert.ToUInt16(arrText[rowNum + 13].ToString().Split(',')[1]);
  777. textBox_BikePowerOnTime.Text = (PowerOnOffParams >> 12).ToString();
  778. //关机延迟
  779. textBox_BikePowerOffTime.Text = ((PowerOnOffParams >> 8) & 0x0F).ToString();
  780. //自动关机
  781. textBox_BikeAutoOffTime.Text = (PowerOnOffParams & 0x00FF).ToString();
  782. break;
  783. }
  784. case "[控制参数]":
  785. {
  786. //峰值电流
  787. textBox_MotorMaxCurr.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  788. //过压保护
  789. textBox_MotorOV.Text = arrText[rowNum + 6].ToString().Split(',')[1];
  790. //欠压保护
  791. textBox_MotorUV.Text = arrText[rowNum + 7].ToString().Split(',')[1];
  792. break;
  793. }
  794. case "[助力参数]":
  795. {
  796. //限速起始
  797. textBox_AssistSpeedBegin.Text = arrText[rowNum + 92].ToString().Split(',')[1];
  798. //限速结束
  799. textBox_AssistSpeedEnd.Text = arrText[rowNum + 93].ToString().Split(',')[1];
  800. break;
  801. }
  802. case "[调试参数]":
  803. {
  804. //运行模式
  805. if ((Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) >= 4) && (Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) <= 6))
  806. {
  807. comboBox_SysRunMode.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 2].ToString().Split(',')[1]) - 4;
  808. }
  809. else
  810. comboBox_SysRunMode.SelectedIndex = -1;
  811. //旋转方向
  812. comboBox_SysDir.SelectedIndex = Convert.ToUInt16(arrText[rowNum + 5].ToString().Split(',')[1]);
  813. //功率限幅
  814. textBox_SysPowerLimit.Text = arrText[rowNum + 23].ToString().Split(',')[1];
  815. break;
  816. }
  817. case "[生产信息]":
  818. {
  819. //生产商
  820. textBox_ProductMac.Text= arrText[rowNum + 1].ToString().Split(',')[1];
  821. //生产地
  822. textBox_ProductAddr.Text = arrText[rowNum + 2].ToString().Split(',')[1];
  823. //生产日期
  824. textBox_ProductDate.Text = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
  825. //生产标识
  826. textBox_ProductTag.Text = arrText[rowNum + 4].ToString().Split(',')[1];
  827. break;
  828. }
  829. default:break;
  830. }
  831. }
  832. } while (false);
  833. do //高级参数界面
  834. {
  835. richTextBox_AdvanceParams.Clear();
  836. foreach (string sOutput in arrText)
  837. {
  838. richTextBox_AdvanceParams.AppendText(sOutput + "\r\n");
  839. }
  840. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 2);
  841. } while (false);
  842. }
  843. private void button_GenerateModelFile_Click(object sender, EventArgs e)
  844. {
  845. string DataFileName = "";
  846. string FileInfo = "";
  847. //填写文件名
  848. Scan ModeFileName = new Scan();
  849. ModeFileName.ShowDialog();
  850. if (ModeFileName.textBox_Scan.Text == string.Empty)
  851. {
  852. MessageBox.Show("文件名为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  853. return;
  854. }
  855. DataFileName = ModeFileName.textBox_Scan.Text + ".src";
  856. //核对文件名格式
  857. //...
  858. //获取模板文本信息写入文件
  859. FileInfo = richTextBox_AdvanceParams.Text;
  860. if (FileInfo == string.Empty)
  861. {
  862. MessageBox.Show("无效参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  863. return;
  864. }
  865. System.IO.File.WriteAllText(DataFileName, FileInfo);
  866. //模板文件上传服务器
  867. if (myFtp.CheckFtp() == true)
  868. {
  869. //上传文件
  870. bool result1 = myFtp.UploadFile(Directory.GetCurrentDirectory() + "\\" + DataFileName, "ParamsMode");
  871. if (result1 == true)
  872. {
  873. MessageBoxTimeOut.Show("数据已上传!", "提示", 1000, MessageBoxButtons.OK, MessageBoxIcon.Information);
  874. }
  875. else
  876. {
  877. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  878. }
  879. }
  880. else
  881. {
  882. MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  883. }
  884. System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + DataFileName);
  885. }
  886. private void button_ExportParams_Click(object sender, EventArgs e)
  887. {
  888. //检查
  889. if ((radioButton_MIGIC.Checked | radioButton_HUB.Checked | radioButton_HUB_FCT.Checked) == false)
  890. {
  891. MessageBox.Show("请选择产品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  892. return;
  893. }
  894. //不导出到本地时需填写完整订单信息
  895. if (!checkBox_SyncFac.Checked)
  896. {
  897. foreach (Control c in groupBox1.Controls)
  898. {
  899. if (c is TextBox)
  900. {
  901. if (c.Text == "")
  902. {
  903. MessageBox.Show("信息填写不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  904. return;
  905. }
  906. if (c.Text.Contains('_'))
  907. {
  908. if ((c.Name != "textBox_ProductTag") && (c.Name != "textBox_SoftwareVer"))
  909. {
  910. MessageBox.Show("\"" + c.Text + "\"" + "包含字符'_'", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  911. return;
  912. }
  913. }
  914. }
  915. }
  916. }
  917. //分割参数
  918. string[] lines = richTextBox_AdvanceParams.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
  919. try
  920. {
  921. //更新信息
  922. do
  923. {
  924. //建立字典,存放并获取每个命令的行号
  925. Dictionary<string, int> DicRowNum = new Dictionary<string, int>();
  926. DicRowNum.Add("[整车参数]", 0);
  927. DicRowNum.Add("[控制参数]", 0);
  928. DicRowNum.Add("[助力参数]", 0);
  929. DicRowNum.Add("[调试参数]", 0);
  930. DicRowNum.Add("[生产信息]", 0);
  931. Dictionary<string, int> __dict = new Dictionary<string, int>(DicRowNum);
  932. foreach (KeyValuePair<string, int> item in __dict)
  933. {
  934. for (int i = 0; i < lines.Length; i++)
  935. {
  936. if (lines[i].Contains(item.Key))
  937. {
  938. DicRowNum[item.Key] = i;
  939. break;
  940. }
  941. }
  942. }
  943. //遍历更新
  944. foreach (string index in DicRowNum.Keys)
  945. {
  946. int rowNum = DicRowNum[index]; //行号
  947. switch (index)
  948. {
  949. case "[整车参数]":
  950. {
  951. //轮胎周长
  952. lines[rowNum + 2] = "轮胎周长," + textBox_BikeWheel.Text;
  953. //转把限速
  954. lines[rowNum + 4] = "转把限速," + textBox_BikeThroSpeed.Text;
  955. //推行限速
  956. lines[rowNum + 5] = "推行限速," + textBox_BikeWalkSpeed.Text;
  957. //前牙盘
  958. lines[rowNum + 6] = "前牙盘," + textBox_BikeFrontT.Text;
  959. //后牙盘
  960. lines[rowNum + 7] = "后牙盘," + textBox_BikeRealB.Text;
  961. //前后灯参数
  962. int LightParams = 0x0000;
  963. if (comboBox_BikeVolF.SelectedIndex == 0)
  964. LightParams |= 0x0006;
  965. else if (comboBox_BikeVolF.SelectedIndex == 1)
  966. LightParams |= 0x000C;
  967. else
  968. {
  969. MessageBox.Show("请选择前灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  970. return;
  971. }
  972. if (comboBox_BikeVolB.SelectedIndex == 0)
  973. LightParams |= 0x0600;
  974. else if (comboBox_BikeVolB.SelectedIndex == 1)
  975. LightParams |= 0x0C00;
  976. else
  977. {
  978. MessageBox.Show("请选择后灯电压!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  979. return;
  980. }
  981. if (comboBox_BikeModeB.SelectedIndex >= 0)
  982. LightParams |= ((comboBox_BikeModeB.SelectedIndex + 1) << 12);
  983. else
  984. {
  985. MessageBox.Show("请选择后灯模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  986. return;
  987. }
  988. lines[rowNum + 10] = "前后灯参数," + ((ushort)LightParams).ToString();
  989. //启动模式
  990. lines[rowNum + 12] = "启动模式," + (comboBox_BikeStartMode.SelectedIndex + 1).ToString();
  991. //开机延迟
  992. int PowerTime = 0;
  993. PowerTime |= Convert.ToUInt16(textBox_BikeAutoOffTime.Text);
  994. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOffTime.Text) << 8);
  995. PowerTime |= (Convert.ToUInt16(textBox_BikePowerOnTime.Text) << 12);
  996. lines[rowNum + 13] = "开关机参数," + ((ushort)PowerTime).ToString();
  997. break;
  998. }
  999. case "[控制参数]":
  1000. {
  1001. //峰值电流
  1002. lines[rowNum + 4] = "峰值电流," + textBox_MotorMaxCurr.Text;
  1003. //过压保护
  1004. lines[rowNum + 6] = "最高档位过压保护阈值," + textBox_MotorOV.Text;
  1005. //欠压保护
  1006. lines[rowNum + 7] = "最高档位欠压保护阈值," + textBox_MotorUV.Text;
  1007. break;
  1008. }
  1009. case "[助力参数]":
  1010. {
  1011. //限速起始
  1012. lines[rowNum + 92] = "车速限幅启动阈值," + textBox_AssistSpeedBegin.Text;
  1013. //限速结束
  1014. lines[rowNum + 93] = "车速限幅停止阈值," + textBox_AssistSpeedEnd.Text;
  1015. break;
  1016. }
  1017. case "[调试参数]":
  1018. {
  1019. //运行模式
  1020. lines[rowNum + 2] = "整体运行模式," + (comboBox_SysRunMode.SelectedIndex + 4).ToString();
  1021. //旋转方向
  1022. lines[rowNum + 5] = "旋转方向," + comboBox_SysDir.SelectedIndex.ToString();
  1023. //功率限幅
  1024. lines[rowNum + 23] = "功率限幅值," + textBox_SysPowerLimit.Text;
  1025. break;
  1026. }
  1027. case "[生产信息]":
  1028. {
  1029. //生产商
  1030. lines[rowNum + 1] = "生产商," + textBox_ProductMac.Text;
  1031. //生产地
  1032. lines[rowNum + 2] = "生产地," + textBox_ProductAddr.Text;
  1033. //生产日期
  1034. lines[rowNum + 3] = "生产日期," + textBox_ProductDate.Text;
  1035. //产品标识
  1036. lines[rowNum + 4] = "产品标识," + textBox_ProductTag.Text;
  1037. break;
  1038. }
  1039. default: break;
  1040. }
  1041. }
  1042. } while (false);
  1043. //参数更新
  1044. richTextBox_AdvanceParams.Clear();
  1045. for (int i = 0; i < lines.Length; i++)
  1046. {
  1047. richTextBox_AdvanceParams.AppendText(lines[i] + "\r\n");
  1048. }
  1049. richTextBox_AdvanceParams.Text = richTextBox_AdvanceParams.Text.Remove(richTextBox_AdvanceParams.Text.Length - 1);
  1050. }
  1051. catch (System.Exception)
  1052. {
  1053. MessageBox.Show("参数格式错误,更新失败", "提示", MessageBoxButtons.OK);
  1054. return;
  1055. }
  1056. //不导出本地时,上传服务器
  1057. if (!checkBox_SyncFac.Checked)
  1058. {
  1059. //确定本地保存路径
  1060. string Date = DateTime.Now.ToString("yyyy-MM-dd");
  1061. string LocalPath = localInfo.LocalPath + "\\" + localInfo.CfgPathName + "\\" + Date;
  1062. if (!Directory.Exists(LocalPath))
  1063. {
  1064. Directory.CreateDirectory(LocalPath);
  1065. }
  1066. //确定远程保存路径
  1067. string ServerPath = "";
  1068. if (radioButton_HUB.Checked)
  1069. {
  1070. if (!myFtp.DirectoryExist("HUB_Control_TEST/cfg", Date))
  1071. myFtp.MakeDir("HUB_Control_TEST/cfg" + "/" + Date);
  1072. ServerPath = "HUB_Control_TEST/cfg" + "/" + Date;
  1073. }
  1074. else if (radioButton_MIGIC.Checked)
  1075. {
  1076. if (!myFtp.DirectoryExist("MIGIC_TEST/cfg", Date))
  1077. myFtp.MakeDir("MIGIC_TEST/cfg" + "/" + Date);
  1078. ServerPath = "MIGIC_TEST/cfg" + "/" + Date;
  1079. }
  1080. else if (radioButton_HUB_FCT.Checked)
  1081. {
  1082. if (!myFtp.DirectoryExist("HUB_Control_FCT/cfg", Date))
  1083. myFtp.MakeDir("HUB_Control_FCT/cfg" + "/" + Date);
  1084. ServerPath = "HUB_Control_FCT/cfg" + "/" + Date;
  1085. }
  1086. //确定文件名
  1087. string fileName = "";
  1088. fileName = textBox_ProductName.Text + "_" + textBox_MarkCode.Text + "-" + textBox_CustomerName.Text + "-" +
  1089. textBox_MarkNum.Text + "_" + textBox_OtherInfo.Text + "_" + textBox_SoftwareVer.Text + "_" +
  1090. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "-");
  1091. //保存.src文件
  1092. System.IO.File.WriteAllText(LocalPath + "\\" + fileName + ".src", richTextBox_AdvanceParams.Text);
  1093. //检查是否存在转换工具
  1094. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1095. {
  1096. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1097. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1098. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1099. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1100. }
  1101. else
  1102. {
  1103. //程序使用最新版本
  1104. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  1105. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe");
  1106. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1107. //库文件不更新
  1108. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  1109. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1110. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  1111. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1112. }
  1113. //转换.ttcfg文件
  1114. ProcessStartInfo startInfo = new ProcessStartInfo();
  1115. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  1116. startInfo.Arguments = "\"" + LocalPath + "\\" + fileName + ".src" + "\"";
  1117. System.Diagnostics.Process.Start(startInfo);
  1118. Thread.Sleep(1000);
  1119. //保存页面
  1120. Double scaleX = PrimaryScreen.ScaleX;
  1121. Double scaleY = PrimaryScreen.ScaleY;
  1122. Bitmap bit = new Bitmap((int)(this.Width * scaleX), (int)(this.Height * scaleY));//实例化一个和窗体一样大的bitmap
  1123. Graphics g = Graphics.FromImage(bit);
  1124. g.CopyFromScreen((int)(this.Left * scaleX), (int)(this.Top * scaleY), 0, 0, new Size((int)(this.Width * scaleX), (int)(this.Height * scaleY)));//保存整个窗体为图片
  1125. bit.Save(LocalPath + "\\" + fileName + ".png");
  1126. //生成pdf文件,上传服务器
  1127. //...
  1128. //上传
  1129. bool result1 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".src", ServerPath);
  1130. bool result2 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".ttcfg", ServerPath);
  1131. bool result3 = myFtp.UploadFile(LocalPath + "\\" + fileName + ".png", ServerPath);
  1132. if (result1 & result2 & result3)
  1133. {
  1134. MessageBoxTimeOut.Show("上传成功", "提示", 1000, MessageBoxButtons.OK);
  1135. }
  1136. else
  1137. {
  1138. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK);
  1139. }
  1140. }
  1141. //导出本地指定路径
  1142. else
  1143. {
  1144. SaveFileDialog saveFileDialog = new SaveFileDialog();
  1145. saveFileDialog.Filter = "配置文件(*.ttcfg)|*.ttcfg";
  1146. DialogResult result = saveFileDialog.ShowDialog();
  1147. if (result == DialogResult.OK)
  1148. {
  1149. string filePath = saveFileDialog.FileName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
  1150. //保存src文件
  1151. System.IO.File.WriteAllText(filePath + ".src", richTextBox_AdvanceParams.Text);
  1152. //检查是否存在转换工具
  1153. if (!Directory.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile"))
  1154. {
  1155. Directory.CreateDirectory(localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1156. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1157. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1158. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1159. }
  1160. else
  1161. {
  1162. //程序使用最新版本
  1163. if (System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe"))
  1164. System.IO.File.Delete(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe");
  1165. myFtp.DownloadFile("Tools/GenerateParamsFile/ConsoleApp2.exe", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1166. //库文件不更新
  1167. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.xml"))
  1168. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.xml", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1169. if (!System.IO.File.Exists(localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "Newtonsoft.Json.dll"))
  1170. myFtp.DownloadFile("Tools/GenerateParamsFile/Newtonsoft.Json.dll", localInfo.ToolsPath + "\\" + "GenerateParamsFile");
  1171. }
  1172. //转换.ttcfg文件
  1173. ProcessStartInfo startInfo = new ProcessStartInfo();
  1174. startInfo.FileName = localInfo.ToolsPath + "\\" + "GenerateParamsFile" + "\\" + "ConsoleApp2.exe";
  1175. startInfo.Arguments = filePath + ".src";
  1176. System.Diagnostics.Process.Start(startInfo);
  1177. Thread.Sleep(1000);
  1178. MessageBoxTimeOut.Show("导出本地完成", "提示", 1000, MessageBoxButtons.OK);
  1179. }
  1180. }
  1181. }
  1182. }
  1183. }