ExportForm.cs 29 KB

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