ExportForm.cs 35 KB

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