ExportForm.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Runtime.Serialization.Formatters.Binary;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using System.Xml.Serialization;
  11. using System.Text.RegularExpressions;
  12. using System.Net;
  13. using Microsoft.Office.Interop.Excel;
  14. using Microsoft.Office.Core;
  15. using Application = Microsoft.Office.Interop.Excel.Application;
  16. using System.Reflection;
  17. namespace MOTINOVA_Motor_Factory_Set
  18. {
  19. public partial class ExportForm : Form
  20. {
  21. //参数按照字典类型存储
  22. Dictionary<string, UInt16> Params1 = new Dictionary<string, UInt16>();
  23. Dictionary<string, UInt16> Params2 = new Dictionary<string, UInt16>();
  24. Dictionary<string, UInt16> MotorParam = new Dictionary<string, UInt16>();
  25. Dictionary<string, string> Otherinfo = new Dictionary<string, string>();
  26. Dictionary<string, UInt16> TestThData = new Dictionary<string, ushort>();
  27. //文件路径
  28. public string FilePath = "";
  29. public ExportForm()
  30. {
  31. InitializeComponent();
  32. }
  33. private void ExportForm_Load(object sender, EventArgs e)
  34. {
  35. }
  36. private void SetDefault()
  37. {
  38. //参数1
  39. Params1.Clear();
  40. Params1.Add("启动模式", 2);
  41. Params1.Add("停机时间", 100);
  42. Params1.Add("限速值", 25);
  43. Params1.Add("下降速度", 3);
  44. Params1.Add("前飞", 14);
  45. Params1.Add("后飞", 9);
  46. Params1.Add("限流", 15);
  47. Params1.Add("温度预警", 95);
  48. Params1.Add("温度保护", 125);
  49. Params1.Add("码表", 0x55);//有,不支持无码表
  50. Params1.Add("轮胎周长", 219);//cm
  51. Params1.Add("系列号", 0);
  52. Params1.Add("ECO增益", 100);//放大100倍
  53. Params1.Add("ECO加速", 100);
  54. Params1.Add("NORM增益", 100);
  55. Params1.Add("NORM加速", 100);
  56. Params1.Add("SPORT增益", 100);
  57. Params1.Add("SPORT加速", 100);
  58. Params1.Add("TURBO增益", 100);
  59. Params1.Add("TURBO加速", 100);
  60. Params1.Add("SMART增益", 100);
  61. Params1.Add("SMART加速", 100);
  62. Params1.Add("车速级数", 1);
  63. Params1.Add("踏频启动", 2);
  64. Params1.Add("指拨模式", 0x55);
  65. Params1.Add("速度信号来源", 0x55);//传感器
  66. Params1.Add("周长微调", 0);
  67. Params1.Add("低压保护", 3000);//mV
  68. Params1.Add("推行限速", 60);//放大10倍
  69. Params1.Add("推行转速", 135);
  70. //参数2
  71. Params2.Clear();
  72. Params2.Add("姿态传感器", 0x55);//不支持
  73. Params2.Add("俯仰角零偏", 0);
  74. Params2.Add("横滚角零偏", 0);
  75. Params2.Add("尾灯模式", 2);
  76. Params2.Add("前灯电压", 12);
  77. Params2.Add("尾灯电压", 12);
  78. //马达参数
  79. MotorParam.Clear();
  80. MotorParam.Add("额定功率", 250);
  81. MotorParam.Add("额定转速", 1200);
  82. MotorParam.Add("定子电阻", 10);
  83. MotorParam.Add("定子Lq", 10);
  84. MotorParam.Add("定子Ld", 10);
  85. MotorParam.Add("反电动势", 36000);
  86. MotorParam.Add("额定电压", 36);
  87. //其它信息
  88. Otherinfo.Clear();
  89. Otherinfo.Add("生产商", "TTIUM");
  90. Otherinfo.Add("生产地", "WUHAN");
  91. Otherinfo.Add("生产日期", DateTime.Now.ToString("yyyyMMdd"));
  92. Otherinfo.Add("校验密钥", "AVONITOM");
  93. Otherinfo.Add("信息1", "");
  94. Otherinfo.Add("信息2", "");
  95. Otherinfo.Add("信息3", "");
  96. //测试阈值
  97. TestThData.Clear();
  98. TestThData.Add("空载电流", 1000);
  99. TestThData.Add("车速", 150);
  100. TestThData.Add("指拨转速", 1200);
  101. TestThData.Add("零偏最小值", 100);
  102. TestThData.Add("零偏最大值", 1800);
  103. TestThData.Add("标定系数最小值", 25);
  104. TestThData.Add("标定系数最大值", 75);
  105. TestThData.Add("启动值最小值", 350);
  106. TestThData.Add("启动值最大值", 750);
  107. }
  108. private void ParamsDisplayUpdate()
  109. {
  110. //参数1
  111. comboBox_StartMode.SelectedIndex = Params1["启动模式"] - 1;
  112. textBox_StopTime.Text = Params1["停机时间"].ToString();
  113. textBox_SpeedLimit.Text = Params1["限速值"].ToString();
  114. textBox_Dec.Text = Params1["下降速度"].ToString();
  115. textBox_T_Front.Text = Params1["前飞"].ToString();
  116. textBox_T_Tail.Text = Params1["后飞"].ToString();
  117. textBox_MaxCurrent.Text = Params1["限流"].ToString();
  118. textBox_NTC_Alarm.Text = Params1["温度预警"].ToString();
  119. textBox_NTC_Ptotect.Text = Params1["温度保护"].ToString();
  120. if (Params1["码表"] == 0x55)
  121. {
  122. comboBox_NoPBU.SelectedIndex = 1;
  123. }
  124. else if (Params1["码表"] == 0xAA)
  125. {
  126. comboBox_NoPBU.SelectedIndex = 0;
  127. }
  128. textBox_WheelSize.Text = Params1["轮胎周长"].ToString();
  129. textBox_Serial.Text = Params1["系列号"].ToString();
  130. textBox_ECO_Gain.Text = ((float)(Params1["ECO增益"]) / 100.0f).ToString("#0.00");
  131. textBox_ECO_Acc.Text = ((float)(Params1["ECO加速"]) / 100.0f).ToString("#0.00");
  132. textBox_NORM_Gain.Text = ((float)(Params1["NORM增益"]) / 100.0f).ToString("#0.00");
  133. textBox_NORM_Acc.Text = ((float)(Params1["NORM加速"]) / 100.0f).ToString("#0.00");
  134. textBox_SPORT_Gain.Text = ((float)(Params1["SPORT增益"]) / 100.0f).ToString("#0.00");
  135. textBox_SPORT_Acc.Text = ((float)(Params1["SPORT加速"]) / 100.0f).ToString("#0.00");
  136. textBox_TURBO_Gain.Text = ((float)(Params1["TURBO增益"]) / 100.0f).ToString("#0.00");
  137. textBox_TURBO_Acc.Text = ((float)(Params1["TURBO加速"]) / 100.0f).ToString("#0.00");
  138. textBox_SMART_Gain.Text = ((float)(Params1["SMART增益"]) / 100.0f).ToString("#0.00");
  139. textBox_SMART_Acc.Text = ((float)(Params1["SMART加速"]) / 100.0f).ToString("#0.00");
  140. textBox_SpeedSensor.Text = Params1["车速级数"].ToString();
  141. textBox_CadenceStart.Text = Params1["踏频启动"].ToString();
  142. if (Params1["指拨模式"] == 0x55)
  143. {
  144. comboBox_GasMode.SelectedIndex = 0;
  145. }
  146. else if (Params1["指拨模式"] == 0xAA)
  147. {
  148. comboBox_GasMode.SelectedIndex = 1;
  149. }
  150. if (Params1["速度信号来源"] == 0x55)
  151. {
  152. comboBox_SpeedSensor.SelectedIndex = 0;
  153. }
  154. else if (Params1["速度信号来源"] == 0xAA)
  155. {
  156. comboBox_SpeedSensor.SelectedIndex = 1;
  157. }
  158. else if (Params1["速度信号来源"] == 0xEE)
  159. {
  160. comboBox_SpeedSensor.SelectedIndex = 2;
  161. }
  162. textBox_WheelSizeAdj.Text = Params1["周长微调"].ToString();
  163. textBox_UV_Protect.Text = Params1["低压保护"].ToString();
  164. textBox_Walk_SpeedLimit.Text = ((float)(Params1["推行限速"]) / 10.0f).ToString("#0.0");
  165. textBox_WalkSpeed.Text = Params1["推行转速"].ToString();
  166. //参数2
  167. if (Params2["姿态传感器"] == 0x55)
  168. {
  169. comboBox_AstSensor.SelectedIndex = 0;
  170. }
  171. else if (Params1["姿态传感器"] == 0xAA)
  172. {
  173. comboBox_AstSensor.SelectedIndex = 1;
  174. }
  175. textBox_Angle_P.Text = ((float)(Params2["俯仰角零偏"]) / 10.0f).ToString("#0.0");
  176. textBox_Angle_R.Text = ((float)(Params2["横滚角零偏"]) / 10.0f).ToString("#0.0");
  177. comboBox_LightMode.SelectedIndex = Params2["尾灯模式"] - 1;
  178. if (Params2["前灯电压"] == 6)
  179. {
  180. comboBox_HeadLightVol.SelectedIndex = 0;
  181. }
  182. else if (Params2["前灯电压"] == 12)
  183. {
  184. comboBox_HeadLightVol.SelectedIndex = 1;
  185. }
  186. else if (Params2["前灯电压"] == 0xFF)
  187. {
  188. comboBox_HeadLightVol.SelectedIndex = 2;
  189. }
  190. else if (Params2["前灯电压"] == 0)
  191. {
  192. comboBox_HeadLightVol.SelectedIndex = 3;
  193. }
  194. if (Params2["尾灯电压"] == 6)
  195. {
  196. comboBox_TailLightVol.SelectedIndex = 0;
  197. }
  198. else if (Params2["尾灯电压"] == 12)
  199. {
  200. comboBox_TailLightVol.SelectedIndex = 1;
  201. }
  202. else if (Params2["尾灯电压"] == 0xFF)
  203. {
  204. comboBox_TailLightVol.SelectedIndex = 2;
  205. }
  206. else if (Params2["尾灯电压"] == 0)
  207. {
  208. comboBox_TailLightVol.SelectedIndex = 3;
  209. }
  210. //马达参数
  211. textBox_RatePower.Text = MotorParam["额定功率"].ToString();
  212. textBox_RateSpeed.Text = MotorParam["额定转速"].ToString();
  213. textBox_RotorR.Text = MotorParam["定子电阻"].ToString();
  214. textBox_Rotor_Lq.Text = MotorParam["定子Lq"].ToString();
  215. textBox_Rotor_Ld.Text = MotorParam["定子Ld"].ToString();
  216. textBox_E.Text = MotorParam["反电动势"].ToString();
  217. textBox_Rate_Vol.Text = MotorParam["额定电压"].ToString();
  218. //其它信息
  219. textBox_Mac.Text = Otherinfo["生产商"].ToString();
  220. textBox_Mac_Addr.Text = Otherinfo["生产地"].ToString();
  221. textBox_Mac_Date.Text = Otherinfo["生产日期"].ToString();
  222. textBox_Secrect.Text = Otherinfo["校验密钥"].ToString();
  223. textBox_Info1.Text = Otherinfo["信息1"].ToString();
  224. textBox_Info2.Text = Otherinfo["信息2"].ToString();
  225. textBox_Info3.Text = Otherinfo["信息3"].ToString();
  226. //测试阈值
  227. textBox_NC_Current.Text = TestThData["空载电流"].ToString();
  228. textBox_SpeedTh.Text = TestThData["车速"].ToString();
  229. textBox_GasSpeedTh.Text = TestThData["指拨转速"].ToString();
  230. textBox_Zero_Min.Text = TestThData["零偏最小值"].ToString();
  231. textBox_Zero_Max.Text = TestThData["零偏最大值"].ToString();
  232. textBox_K_Min.Text = ((float)(TestThData["标定系数最小值"]) / 100.0f).ToString("#0.00");
  233. textBox_K_Max.Text = ((float)(TestThData["标定系数最大值"]) / 100.0f).ToString("#0.00");
  234. textBox_Start_Min.Text = TestThData["启动值最小值"].ToString();
  235. textBox_Start_Max.Text = TestThData["启动值最大值"].ToString();
  236. }
  237. private bool DisplaySetToParams()
  238. {
  239. try
  240. {
  241. //参数1
  242. Params1.Clear();
  243. if (comboBox_StartMode.Text == "柔和")
  244. {
  245. Params1.Add("启动模式", 1);
  246. }
  247. else if (comboBox_StartMode.Text == "正常")
  248. {
  249. Params1.Add("启动模式", 2);
  250. }
  251. else if (comboBox_StartMode.Text == "强劲")
  252. {
  253. Params1.Add("启动模式", 3);
  254. }
  255. else
  256. {
  257. MessageBox.Show("请检查启动模式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  258. return false;
  259. }
  260. Params1.Add("停机时间", Convert.ToUInt16(textBox_StopTime.Text));
  261. if (Params1["停机时间"] < 50 || Params1["停机时间"] > 500)
  262. {
  263. MessageBox.Show("停机时间有效值:50~500 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  264. return false;
  265. }
  266. Params1.Add("限速值", Convert.ToUInt16(textBox_SpeedLimit.Text));
  267. if (Params1["限速值"] < 5 || Params1["限速值"] > 80)
  268. {
  269. MessageBox.Show("限速值有效值:5~80 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  270. return false;
  271. }
  272. Params1.Add("下降速度", Convert.ToUInt16(textBox_Dec.Text));
  273. if (Params1["下降速度"] < 1 || Params1["下降速度"] > 5)
  274. {
  275. MessageBox.Show("下降速度有效值:1~5 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  276. return false;
  277. }
  278. Params1.Add("前飞", Convert.ToUInt16(textBox_T_Front.Text));
  279. if (Params1["前飞"] < 5 || Params1["前飞"] > 100)
  280. {
  281. MessageBox.Show("前飞有效值:5~100 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  282. return false;
  283. }
  284. Params1.Add("后飞", Convert.ToUInt16(textBox_T_Tail.Text));
  285. if (Params1["后飞"] < 5 || Params1["后飞"] > 100)
  286. {
  287. MessageBox.Show("后飞有效值:5~100 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  288. return false;
  289. }
  290. Params1.Add("限流", Convert.ToUInt16(textBox_MaxCurrent.Text));
  291. if (Params1["限流"] < 5 || Params1["限流"] > 25)
  292. {
  293. MessageBox.Show("限流有效值:5~25 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  294. return false;
  295. }
  296. Params1.Add("温度预警", Convert.ToUInt16(textBox_NTC_Alarm.Text));
  297. Params1.Add("温度保护", Convert.ToUInt16(textBox_NTC_Ptotect.Text));
  298. if (comboBox_NoPBU.Text == "有")
  299. {
  300. Params1.Add("码表", 0x55);
  301. }
  302. else if (comboBox_NoPBU.Text == "无")
  303. {
  304. Params1.Add("码表", 0xAA);
  305. }
  306. else
  307. {
  308. MessageBox.Show("请检查无码表设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  309. }
  310. Params1.Add("轮胎周长", Convert.ToUInt16(textBox_WheelSize.Text));
  311. if (Params1["轮胎周长"] < 100 || Params1["轮胎周长"] > 250)
  312. {
  313. MessageBox.Show("轮胎周长有效值:100~250 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  314. return false;
  315. }
  316. Params1.Add("系列号", Convert.ToUInt16(textBox_Serial.Text));
  317. if (Params1["系列号"] < 1 || Params1["系列号"] > 16)
  318. {
  319. MessageBox.Show("系列号有效值:1~16 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  320. return false;
  321. }
  322. Params1.Add("ECO增益", Convert.ToUInt16(float.Parse(textBox_ECO_Gain.Text) * 100));//放大100倍
  323. Params1.Add("ECO加速", Convert.ToUInt16(float.Parse(textBox_ECO_Acc.Text) * 100));
  324. Params1.Add("NORM增益", Convert.ToUInt16(float.Parse(textBox_NORM_Gain.Text) * 100));
  325. Params1.Add("NORM加速", Convert.ToUInt16(float.Parse(textBox_NORM_Acc.Text) * 100));
  326. Params1.Add("SPORT增益", Convert.ToUInt16(float.Parse(textBox_SPORT_Gain.Text) * 100));
  327. Params1.Add("SPORT加速", Convert.ToUInt16(float.Parse(textBox_SPORT_Acc.Text) * 100));
  328. Params1.Add("TURBO增益", Convert.ToUInt16(float.Parse(textBox_TURBO_Gain.Text) * 100));
  329. Params1.Add("TURBO加速", Convert.ToUInt16(float.Parse(textBox_TURBO_Acc.Text) * 100));
  330. Params1.Add("SMART增益", Convert.ToUInt16(float.Parse(textBox_SMART_Gain.Text) * 100));
  331. Params1.Add("SMART加速", Convert.ToUInt16(float.Parse(textBox_SMART_Acc.Text) * 100));
  332. Params1.Add("车速级数", Convert.ToUInt16(textBox_SpeedSensor.Text));
  333. Params1.Add("踏频启动", Convert.ToUInt16(textBox_CadenceStart.Text));
  334. if (comboBox_GasMode.Text == "不支持")
  335. {
  336. Params1.Add("指拨模式", 0x55);
  337. }
  338. else if (comboBox_GasMode.Text == "支持")
  339. {
  340. Params1.Add("指拨模式", 0xAA);
  341. }
  342. else
  343. {
  344. MessageBox.Show("请检查指拨模式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  345. }
  346. if (comboBox_SpeedSensor.Text == "传感器")
  347. {
  348. Params1.Add("速度信号来源", 0x55);
  349. }
  350. else if (comboBox_SpeedSensor.Text == "踏频")
  351. {
  352. Params1.Add("速度信号来源", 0xAA);
  353. }
  354. else if (comboBox_SpeedSensor.Text == "通信")
  355. {
  356. Params1.Add("速度信号来源", 0xEE);
  357. }
  358. else
  359. {
  360. MessageBox.Show("请检查速度信号来源设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  361. }
  362. Params1.Add("周长微调", Convert.ToUInt16(textBox_WheelSizeAdj.Text));
  363. Params1.Add("低压保护", Convert.ToUInt16(textBox_UV_Protect.Text));//mV
  364. Params1.Add("推行限速", Convert.ToUInt16(float.Parse(textBox_Walk_SpeedLimit.Text) * 10));//放大10倍
  365. Params1.Add("推行转速", Convert.ToUInt16(textBox_WalkSpeed.Text));
  366. //参数2
  367. Params2.Clear();
  368. if (comboBox_AstSensor.Text == "不支持")
  369. {
  370. Params2.Add("姿态传感器", 0x55);
  371. }
  372. else if (comboBox_AstSensor.Text == "支持")
  373. {
  374. Params2.Add("姿态传感器", 0xAA);
  375. }
  376. else
  377. {
  378. MessageBox.Show("请检查姿态传感器设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  379. }
  380. Params2.Add("俯仰角零偏", Convert.ToUInt16(float.Parse(textBox_Angle_P.Text) * 10));
  381. Params2.Add("横滚角零偏", Convert.ToUInt16(float.Parse(textBox_Angle_R.Text) * 10));
  382. if (comboBox_LightMode.Text == "模式 1")
  383. {
  384. Params2.Add("尾灯模式", 1);
  385. }
  386. else if(comboBox_LightMode.Text == "模式 2")
  387. {
  388. Params2.Add("尾灯模式", 2);
  389. }
  390. else if (comboBox_LightMode.Text == "模式 3")
  391. {
  392. Params2.Add("尾灯模式", 3);
  393. }
  394. else if (comboBox_LightMode.Text == "模式 4")
  395. {
  396. Params2.Add("尾灯模式", 4);
  397. }
  398. if (comboBox_HeadLightVol.Text == "6V")
  399. {
  400. Params2.Add("前灯电压", 6);
  401. }
  402. else if (comboBox_HeadLightVol.Text == "12V")
  403. {
  404. Params2.Add("前灯电压", 12);
  405. }
  406. else if (comboBox_HeadLightVol.Text == "随电池")
  407. {
  408. Params2.Add("前灯电压", 0xFF);
  409. }
  410. else if (comboBox_HeadLightVol.Text == "硬件配置")
  411. {
  412. Params2.Add("前灯电压", 0);
  413. }
  414. if (comboBox_TailLightVol.Text == "6V")
  415. {
  416. Params2.Add("尾灯电压", 6);
  417. }
  418. else if (comboBox_TailLightVol.Text == "12V")
  419. {
  420. Params2.Add("尾灯电压", 12);
  421. }
  422. else if (comboBox_TailLightVol.Text == "随电池")
  423. {
  424. Params2.Add("尾灯电压", 0xFF);
  425. }
  426. else if (comboBox_TailLightVol.Text == "硬件配置")
  427. {
  428. Params2.Add("尾灯电压", 0);
  429. }
  430. //马达参数
  431. MotorParam.Clear();
  432. MotorParam.Add("额定功率", Convert.ToUInt16(textBox_RatePower.Text));
  433. MotorParam.Add("额定转速", Convert.ToUInt16(textBox_RateSpeed.Text));
  434. MotorParam.Add("定子电阻", Convert.ToUInt16(textBox_RotorR.Text));
  435. MotorParam.Add("定子Lq", Convert.ToUInt16(textBox_Rotor_Lq.Text));
  436. MotorParam.Add("定子Ld", Convert.ToUInt16(textBox_Rotor_Ld.Text));
  437. MotorParam.Add("反电动势", Convert.ToUInt16(textBox_E.Text));
  438. MotorParam.Add("额定电压", Convert.ToUInt16(textBox_Rate_Vol.Text));
  439. //其它信息
  440. Otherinfo.Clear();
  441. Otherinfo.Add("生产商", textBox_Mac.Text);
  442. Otherinfo.Add("生产地", textBox_Mac_Addr.Text);
  443. Otherinfo.Add("生产日期", textBox_Mac_Date.Text);
  444. Otherinfo.Add("校验密钥", textBox_Secrect.Text);
  445. Otherinfo.Add("信息1", textBox_Info1.Text);
  446. Otherinfo.Add("信息2", textBox_Info2.Text);
  447. Otherinfo.Add("信息3", textBox_Info3.Text);
  448. //测试阈值
  449. TestThData.Clear();
  450. TestThData.Add("空载电流", Convert.ToUInt16(textBox_NC_Current.Text));
  451. TestThData.Add("车速", Convert.ToUInt16(textBox_SpeedTh.Text));
  452. TestThData.Add("指拨转速", Convert.ToUInt16(textBox_GasSpeedTh.Text));
  453. TestThData.Add("零偏最小值", Convert.ToUInt16(textBox_Zero_Min.Text));
  454. TestThData.Add("零偏最大值", Convert.ToUInt16(textBox_Zero_Max.Text));
  455. TestThData.Add("标定系数最小值", Convert.ToUInt16(float.Parse(textBox_K_Min.Text) * 100));
  456. TestThData.Add("标定系数最大值", Convert.ToUInt16(float.Parse(textBox_K_Max.Text) * 100));
  457. TestThData.Add("启动值最小值", Convert.ToUInt16(textBox_Start_Min.Text));
  458. TestThData.Add("启动值最大值", Convert.ToUInt16(textBox_Start_Max.Text));
  459. return true;
  460. }
  461. catch(Exception ex)
  462. {
  463. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  464. return false;
  465. }
  466. }
  467. private void button_Default_Click(object sender, EventArgs e)
  468. {
  469. if (MessageBox.Show("确认恢复默认值?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  470. {
  471. return;
  472. }
  473. SetDefault();
  474. ParamsDisplayUpdate();
  475. }
  476. private void button_Generate_Click(object sender, EventArgs e)
  477. {
  478. if (MessageBox.Show("确认提交?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  479. {
  480. return;
  481. }
  482. //空间内容更新到字典
  483. if (DisplaySetToParams() == false)
  484. {
  485. MessageBox.Show("参数生成失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  486. return;
  487. }
  488. //保存为配置文件
  489. if (textBox_Model.Text == string.Empty) //判断型号是否填写
  490. {
  491. MessageBox.Show("请输入电机型号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  492. return;
  493. }
  494. if (textBox_Client.Text == string.Empty) //判断客户号是否填写
  495. {
  496. textBox_Client.Text = "STD";
  497. }
  498. Regex Reg = new Regex(@"[V][0-9].[0-9]|[0-9][0-9].[0-9]|[0-9][0-9].[0-9]|[0-9][0-9].[0-9]|[0-9][0-9]_20\d{6}");
  499. if (Reg.IsMatch(textBox_FW_Version.Text) == false) //判断主控软件版本是否填写
  500. {
  501. MessageBox.Show("主控软件版本格式不正确,例如V1.0.0.0.0_20210101 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  502. return;
  503. }
  504. if (textBox_TE_FW_Version.Text != "N_A")//兼容单MCU主控板,无TE时填写N_A
  505. {
  506. Reg = new Regex(@"[V][0-9].[0-9].[0-9]_20\d{6}"); //判断TE软件版本是否填写
  507. if (Reg.IsMatch(textBox_TE_FW_Version.Text) == false) //判断TE软件版本是否填写
  508. {
  509. MessageBox.Show("TE软件版本格式不正确,例如N_A或V1.0.0_20210101 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  510. return;
  511. }
  512. }
  513. if (System.IO.Directory.Exists(FilePath) == false)
  514. System.IO.Directory.CreateDirectory(FilePath);
  515. string Datenow = DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  516. if (System.IO.Directory.Exists(FilePath + Datenow) == false)
  517. System.IO.Directory.CreateDirectory(FilePath + Datenow);
  518. string fileName = FilePath + Datenow + textBox_Model.Text + "_" + textBox_Client.Text + "_" + textBox_FW_Version.Text + "_" + textBox_TE_FW_Version.Text + "_" + ((textBox_Remark.Text == string.Empty) ? "" : textBox_Remark.Text + "_") + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".ttcfg";
  519. using (StreamWriter file = new StreamWriter(fileName))
  520. {
  521. //用户参数1
  522. file.WriteLine("[{0}]", "用户参数1");
  523. foreach (var entry in Params1)
  524. if (entry.Key == "码表")
  525. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "有" : entry.Value == 0xAA ? "无" : "无效");
  526. else if (entry.Key == "指拨模式")
  527. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "不支持" : entry.Value == 0xAA ? "支持" : "无效");
  528. else if (entry.Key == "速度信号来源")
  529. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "传感器" : entry.Value == 0xAA ? "踏频" : entry.Value == 0xEE ? "通信" : "无效");
  530. else
  531. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  532. //用户参数2
  533. file.WriteLine("");
  534. file.WriteLine("[{0}]", "用户参数2");
  535. foreach (var entry in Params2)
  536. if (entry.Key == "姿态传感器")
  537. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "不支持" : entry.Value == 0xAA ? "支持" : "无效");
  538. else if (entry.Key == "前灯电压")
  539. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0xFF ? "随电池" : entry.Value == 0 ? "硬件配置" : entry.Value + "V");
  540. else if (entry.Key == "尾灯电压")
  541. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0xFF ? "随电池" : entry.Value == 0 ? "硬件配置" : entry.Value + "V");
  542. else
  543. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  544. //马达参数
  545. file.WriteLine("");
  546. file.WriteLine("[{0}]", "马达参数");
  547. foreach (var entry in MotorParam)
  548. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  549. //其它信息
  550. file.WriteLine("");
  551. file.WriteLine("[{0}]", "其它信息");
  552. foreach (var entry in Otherinfo)
  553. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  554. //测试阈值
  555. file.WriteLine("");
  556. file.WriteLine("[{0}]", "测试阈值");
  557. foreach (var entry in TestThData)
  558. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  559. }
  560. //保存为Excel文件
  561. try
  562. {
  563. string excelFileName = FilePath + Datenow + textBox_Model.Text + "_" + textBox_Client.Text + "_" + textBox_FW_Version.Text + "_" + textBox_TE_FW_Version.Text + "_" + ((textBox_Remark.Text == string.Empty) ? "" : textBox_Remark.Text + "_") + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".xls";
  564. System.IO.File.Copy("FOQC成机参数检验标准_Temple.xls", excelFileName, true);//复制模板文件
  565. Application myExcel = new Application();
  566. Workbooks wbs = myExcel.Workbooks;
  567. _Workbook wb = wbs.Add(excelFileName);//打开并显示文件
  568. object Nothing = System.Reflection.Missing.Value;
  569. _Worksheet mySheet1 = wb.Sheets[1];
  570. string sheetName = mySheet1.Name;
  571. mySheet1.Activate();
  572. mySheet1.Cells[1, 5] = "VS 7500";
  573. wb.Save();
  574. wb.Close();
  575. wbs.Close();
  576. myExcel.Quit();
  577. System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
  578. }
  579. catch (Exception ex)
  580. {
  581. throw (ex);
  582. }
  583. MessageBox.Show("参数已生成,进入文件管理页面查看!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  584. //发送文件到服务器
  585. if (StartForm.myFtp.IsNetConnected == true)
  586. {
  587. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  588. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/cfg/", DateNow) == false)
  589. {
  590. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
  591. }
  592. bool result = StartForm.myFtp.UploadFile(fileName, StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
  593. if (result == true)
  594. {
  595. MessageBox.Show("文件上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  596. }
  597. else
  598. {
  599. MessageBox.Show("文件上传服务器失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  600. }
  601. }
  602. }
  603. private void button_keyboard_Click(object sender, EventArgs e)
  604. {
  605. System.Diagnostics.Process.Start("osk.exe");
  606. }
  607. //输入型号时自动更新关键参数
  608. private void textBox_Model_TextChanged(object sender, EventArgs e)
  609. {
  610. if (textBox_Model.Text.Contains("J01"))
  611. {
  612. textBox_Serial.Text = "1";//系列号
  613. textBox_MaxCurrent.Text = "13";//限流
  614. textBox_RatePower.Text = "250";//额定功率
  615. textBox_RateSpeed.Text = "1200";//额定转速
  616. textBox_Rate_Vol.Text = "36";//额定电压
  617. textBox_NC_Current.Text = "1000";//空载电流
  618. textBox_GasSpeedTh.Text = "1000";//指拨转速
  619. textBox_Zero_Min.Text = "100";//零偏下限
  620. textBox_Zero_Max.Text = "2000";//零偏上限
  621. textBox_K_Min.Text = "0.40";//传感器标定值下限
  622. textBox_K_Max.Text = "1.20";//传感器标定值下限
  623. textBox_Start_Min.Text = "350";//启动值下限
  624. textBox_Start_Max.Text = "750";//启动值上限
  625. }
  626. else if (textBox_Model.Text.Contains("VL"))
  627. {
  628. textBox_Serial.Text = "1";//系列号
  629. textBox_MaxCurrent.Text = "13";//限流
  630. textBox_RatePower.Text = "250";//额定功率
  631. textBox_RateSpeed.Text = "1200";//额定转速
  632. textBox_Rate_Vol.Text = "36";//额定电压
  633. textBox_NC_Current.Text = "1000";//空载电流
  634. textBox_GasSpeedTh.Text = "1000";//指拨转速
  635. textBox_Zero_Min.Text = "200";//零偏下限
  636. textBox_Zero_Max.Text = "1800";//零偏上限
  637. textBox_K_Min.Text = "0.25";//传感器标定值下限
  638. textBox_K_Max.Text = "0.75";//传感器标定值下限
  639. textBox_Start_Min.Text = "350";//启动值下限
  640. textBox_Start_Max.Text = "750";//启动值上限
  641. }
  642. else if (textBox_Model.Text.Contains("VS"))
  643. {
  644. textBox_Serial.Text = "2";//系列号
  645. textBox_MaxCurrent.Text = "15";//限流
  646. textBox_RatePower.Text = "250";//额定功率
  647. textBox_RateSpeed.Text = "1200";//额定转速
  648. textBox_Rate_Vol.Text = "36";//额定电压
  649. textBox_NC_Current.Text = "1000";//空载电流
  650. textBox_GasSpeedTh.Text = "1000";//指拨转速
  651. textBox_Zero_Min.Text = "200";//零偏下限
  652. textBox_Zero_Max.Text = "1800";//零偏上限
  653. textBox_K_Min.Text = "0.25";//传感器标定值下限
  654. textBox_K_Max.Text = "0.75";//传感器标定值下限
  655. textBox_Start_Min.Text = "350";//启动值下限
  656. textBox_Start_Max.Text = "750";//启动值上限
  657. }
  658. else if (textBox_Model.Text.Contains("PG"))
  659. {
  660. textBox_Serial.Text = "3";//系列号
  661. textBox_MaxCurrent.Text = "17";//限流
  662. textBox_RatePower.Text = "250";//额定功率
  663. textBox_RateSpeed.Text = "1600";//额定转速
  664. textBox_Rate_Vol.Text = "36";//额定电压
  665. textBox_NC_Current.Text = "1000";//空载电流
  666. textBox_GasSpeedTh.Text = "1000";//指拨转速
  667. textBox_Zero_Min.Text = "100";//零偏下限
  668. textBox_Zero_Max.Text = "2000";//零偏上限
  669. textBox_K_Min.Text = "0.25";//传感器标定值下限
  670. textBox_K_Max.Text = "1.20";//传感器标定值下限
  671. textBox_Start_Min.Text = "350";//启动值下限
  672. textBox_Start_Max.Text = "750";//启动值上限
  673. }
  674. else if (textBox_Model.Text.Contains("PS"))
  675. {
  676. textBox_Serial.Text = "4";//系列号
  677. textBox_MaxCurrent.Text = "17";//限流
  678. textBox_RatePower.Text = "500";//额定功率
  679. textBox_RateSpeed.Text = "1800";//额定转速
  680. textBox_Rate_Vol.Text = "48";//额定电压
  681. textBox_NC_Current.Text = "1000";//空载电流
  682. textBox_GasSpeedTh.Text = "1000";//指拨转速
  683. textBox_Zero_Min.Text = "100";//零偏下限
  684. textBox_Zero_Max.Text = "2000";//零偏上限
  685. textBox_K_Min.Text = "0.25";//传感器标定值下限
  686. textBox_K_Max.Text = "1.20";//传感器标定值下限
  687. textBox_Start_Min.Text = "350";//启动值下限
  688. textBox_Start_Max.Text = "750";//启动值上限
  689. }
  690. else
  691. {
  692. textBox_Serial.Text = "";//系列号
  693. textBox_MaxCurrent.Text = "";//限流
  694. textBox_RatePower.Text = "";//额定功率
  695. textBox_RateSpeed.Text = "";//额定转速
  696. textBox_Rate_Vol.Text = "";//额定电压
  697. textBox_NC_Current.Text = "";//空载电流
  698. textBox_GasSpeedTh.Text = "";//指拨转速
  699. textBox_Zero_Min.Text = "";//零偏下限
  700. textBox_Zero_Max.Text = "";//零偏上限
  701. textBox_K_Min.Text = "";//传感器标定值下限
  702. textBox_K_Max.Text = "";//传感器标定值下限
  703. textBox_Start_Min.Text = "";//启动值下限
  704. textBox_Start_Max.Text = "";//启动值上限
  705. }
  706. }
  707. }
  708. }