ExportForm.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. namespace MOTINOVA_Motor_Factory_Set
  12. {
  13. public partial class ExportForm : Form
  14. {
  15. //参数按照字典类型存储
  16. Dictionary<string, UInt16> Params1 = new Dictionary<string, UInt16>();
  17. Dictionary<string, UInt16> Params2 = new Dictionary<string, UInt16>();
  18. Dictionary<string, UInt16> MotorParam = new Dictionary<string, UInt16>();
  19. Dictionary<string, string> Otherinfo = new Dictionary<string, string>();
  20. public ExportForm()
  21. {
  22. InitializeComponent();
  23. }
  24. private void ExportForm_Load(object sender, EventArgs e)
  25. {
  26. }
  27. private void SetDefault()
  28. {
  29. //参数1
  30. Params1.Clear();
  31. Params1.Add("启动模式", 2);
  32. Params1.Add("停机时间", 100);
  33. Params1.Add("限速值", 25);
  34. Params1.Add("下降速度", 3);
  35. Params1.Add("前飞", 14);
  36. Params1.Add("后飞", 9);
  37. Params1.Add("限流", 15);
  38. Params1.Add("温度预警", 95);
  39. Params1.Add("温度保护", 125);
  40. Params1.Add("无码表支持", 0x55);
  41. Params1.Add("轮胎周长", 219);
  42. Params1.Add("系列号", 0);
  43. Params1.Add("ECO增益", 100);//放大100倍
  44. Params1.Add("ECO加速", 100);
  45. Params1.Add("NORM增益", 100);
  46. Params1.Add("NORM加速", 100);
  47. Params1.Add("SPORT增益", 100);
  48. Params1.Add("SPORT加速", 100);
  49. Params1.Add("TURBO增益", 100);
  50. Params1.Add("TURBO加速", 100);
  51. Params1.Add("SMART增益", 100);
  52. Params1.Add("SMART加速", 100);
  53. Params1.Add("车速级数", 1);
  54. Params1.Add("踏频启动", 2);
  55. Params1.Add("指拨模式", 0x55);
  56. Params1.Add("速度信号来源", 0x55);
  57. Params1.Add("周长微调", 0);
  58. Params1.Add("低压保护", 3100);//mV
  59. Params1.Add("推行限速", 60);//放大10倍
  60. Params1.Add("推行转速", 135);
  61. //参数2
  62. Params2.Clear();
  63. Params2.Add("姿态传感器", 0x55);
  64. Params2.Add("俯仰角零偏", 0);
  65. Params2.Add("横滚角零偏", 0);
  66. Params2.Add("尾灯模式", 2);
  67. //马达参数
  68. MotorParam.Clear();
  69. MotorParam.Add("额定功率", 250);
  70. MotorParam.Add("额定转速", 1500);
  71. MotorParam.Add("定子电阻", 10);
  72. MotorParam.Add("定子Lq", 10);
  73. MotorParam.Add("定子Ld", 10);
  74. MotorParam.Add("反电动势", 36000);
  75. MotorParam.Add("额定电压", 36);
  76. //其它信息
  77. Otherinfo.Clear();
  78. Otherinfo.Add("生产商", "TTIUM");
  79. Otherinfo.Add("生产地", "WUHAN");
  80. Otherinfo.Add("生产日期", "20200901");
  81. Otherinfo.Add("校验密钥", "AVONITOM");
  82. Otherinfo.Add("信息1", "");
  83. Otherinfo.Add("信息2", "");
  84. Otherinfo.Add("信息3", "");
  85. }
  86. private void ParamsDisplayUpdate()
  87. {
  88. //参数1
  89. if (Params1["启动模式"] == 1)
  90. {
  91. comboBox_StartMode.Text = "柔和";
  92. }
  93. else if (Params1["启动模式"] == 2)
  94. {
  95. comboBox_StartMode.Text = "正常";
  96. }
  97. else if (Params1["启动模式"] == 3)
  98. {
  99. comboBox_StartMode.Text = "强劲";
  100. }
  101. textBox_StopTime.Text = Params1["停机时间"].ToString();
  102. textBox_SpeedLimit.Text = Params1["限速值"].ToString();
  103. textBox_Dec.Text = Params1["下降速度"].ToString();
  104. textBox_T_Front.Text = Params1["前飞"].ToString();
  105. textBox_T_Tail.Text = Params1["后飞"].ToString();
  106. textBox_MaxCurrent.Text = Params1["限流"].ToString();
  107. textBox_NTC_Alarm.Text = Params1["温度预警"].ToString();
  108. textBox_NTC_Ptotect.Text = Params1["温度保护"].ToString();
  109. if (Params1["无码表支持"] == 0x55)
  110. {
  111. comboBox_NoPBU.Text = "不支持";
  112. }
  113. else if (Params1["无码表支持"] == 0xAA)
  114. {
  115. comboBox_NoPBU.Text = "支持";
  116. }
  117. textBox_WheelSize.Text = Params1["轮胎周长"].ToString();
  118. textBox_Serial.Text = Params1["系列号"].ToString();
  119. textBox_ECO_Gain.Text = ((float)(Params1["ECO增益"]) / 100.0f).ToString("#0.00");
  120. textBox_ECO_Acc.Text = ((float)(Params1["ECO加速"]) / 100.0f).ToString("#0.00");
  121. textBox_NORM_Gain.Text = ((float)(Params1["NORM增益"]) / 100.0f).ToString("#0.00");
  122. textBox_NORM_Acc.Text = ((float)(Params1["NORM加速"]) / 100.0f).ToString("#0.00");
  123. textBox_SPORT_Gain.Text = ((float)(Params1["SPORT增益"]) / 100.0f).ToString("#0.00");
  124. textBox_SPORT_Acc.Text = ((float)(Params1["SPORT加速"]) / 100.0f).ToString("#0.00");
  125. textBox_TURBO_Gain.Text = ((float)(Params1["TURBO增益"]) / 100.0f).ToString("#0.00");
  126. textBox_TURBO_Acc.Text = ((float)(Params1["TURBO加速"]) / 100.0f).ToString("#0.00");
  127. textBox_SMART_Gain.Text = ((float)(Params1["SMART增益"]) / 100.0f).ToString("#0.00");
  128. textBox_SMART_Acc.Text = ((float)(Params1["SMART加速"]) / 100.0f).ToString("#0.00");
  129. textBox_SpeedSensor.Text = Params1["车速级数"].ToString();
  130. textBox_CadenceStart.Text = Params1["踏频启动"].ToString();
  131. if (Params1["指拨模式"] == 0x55)
  132. {
  133. comboBox_GasMode.Text = "不支持";
  134. }
  135. else if (Params1["指拨模式"] == 0xAA)
  136. {
  137. comboBox_GasMode.Text = "支持";
  138. }
  139. if (Params1["速度信号来源"] == 0x55)
  140. {
  141. comboBox_SpeedSensor.Text = "传感器";
  142. }
  143. else if (Params1["速度信号来源"] == 0xAA)
  144. {
  145. comboBox_SpeedSensor.Text = "踏频";
  146. }
  147. else if (Params1["速度信号来源"] == 0xEE)
  148. {
  149. comboBox_SpeedSensor.Text = "通信";
  150. }
  151. textBox_WheelSizeAdj.Text = Params1["周长微调"].ToString();
  152. textBox_UV_Protect.Text = Params1["低压保护"].ToString();
  153. textBox_Walk_SpeedLimit.Text = ((float)(Params1["推行限速"]) / 10.0f).ToString("#0.0");
  154. textBox_WalkSpeed.Text = Params1["推行转速"].ToString();
  155. //参数2
  156. if (Params2["姿态传感器"] == 0x55)
  157. {
  158. comboBox_AstSensor.Text = "不支持";
  159. }
  160. else if (Params1["姿态传感器"] == 0xAA)
  161. {
  162. comboBox_AstSensor.Text = "支持";
  163. }
  164. textBox_Angle_P.Text = ((float)(Params2["俯仰角零偏"]) / 10.0f).ToString("#0.0");
  165. textBox_Angle_R.Text = ((float)(Params2["横滚角零偏"]) / 10.0f).ToString("#0.0");
  166. if (Params2["尾灯模式"] == 1)
  167. {
  168. comboBox_LightMode.Text = "模式 1";
  169. }
  170. else if (Params2["尾灯模式"] == 2)
  171. {
  172. comboBox_LightMode.Text = "模式 2";
  173. }
  174. else if (Params2["尾灯模式"] == 3)
  175. {
  176. comboBox_LightMode.Text = "模式 3";
  177. }
  178. else if (Params2["尾灯模式"] == 4)
  179. {
  180. comboBox_LightMode.Text = "模式 4";
  181. }
  182. //马达参数
  183. textBox_RatePower.Text = MotorParam["额定功率"].ToString();
  184. textBox_RateSpeed.Text = MotorParam["额定转速"].ToString();
  185. textBox_RotorR.Text = MotorParam["定子电阻"].ToString();
  186. textBox_Rotor_Lq.Text = MotorParam["定子Lq"].ToString();
  187. textBox_Rotor_Ld.Text = MotorParam["定子Ld"].ToString();
  188. textBox_E.Text = MotorParam["反电动势"].ToString();
  189. textBox_Rate_Vol.Text = MotorParam["额定电压"].ToString();
  190. //其它信息
  191. textBox_Mac.Text = Otherinfo["生产商"].ToString();
  192. textBox_Mac_Addr.Text = Otherinfo["生产地"].ToString();
  193. textBox_Mac_Date.Text = Otherinfo["生产日期"].ToString();
  194. textBox_Secrect.Text = Otherinfo["校验密钥"].ToString();
  195. textBox_Info1.Text = Otherinfo["信息1"].ToString();
  196. textBox_Info2.Text = Otherinfo["信息2"].ToString();
  197. textBox_Info3.Text = Otherinfo["信息3"].ToString();
  198. }
  199. private bool DisplaySetToParams()
  200. {
  201. try
  202. {
  203. //参数1
  204. Params1.Clear();
  205. if (comboBox_StartMode.Text == "柔和")
  206. {
  207. Params1.Add("启动模式", 1);
  208. }
  209. else if (comboBox_StartMode.Text == "正常")
  210. {
  211. Params1.Add("启动模式", 2);
  212. }
  213. else if (comboBox_StartMode.Text == "强劲")
  214. {
  215. Params1.Add("启动模式", 3);
  216. }
  217. else
  218. {
  219. MessageBox.Show("请检查启动模式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  220. }
  221. Params1.Add("停机时间", Convert.ToUInt16(textBox_StopTime.Text));
  222. Params1.Add("限速值", Convert.ToUInt16(textBox_SpeedLimit.Text));
  223. Params1.Add("下降速度", Convert.ToUInt16(textBox_Dec.Text));
  224. Params1.Add("前飞", Convert.ToUInt16(textBox_T_Front.Text));
  225. Params1.Add("后飞", Convert.ToUInt16(textBox_T_Tail.Text));
  226. Params1.Add("限流", Convert.ToUInt16(textBox_MaxCurrent.Text));
  227. Params1.Add("温度预警", Convert.ToUInt16(textBox_NTC_Alarm.Text));
  228. Params1.Add("温度保护", Convert.ToUInt16(textBox_NTC_Ptotect.Text));
  229. if (comboBox_NoPBU.Text == "不支持")
  230. {
  231. Params1.Add("无码表支持", 0x55);
  232. }
  233. else if (comboBox_NoPBU.Text == "支持")
  234. {
  235. Params1.Add("无码表支持", 0xAA);
  236. }
  237. else
  238. {
  239. MessageBox.Show("请检查无码表设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  240. }
  241. Params1.Add("轮胎周长", Convert.ToUInt16(textBox_WheelSize.Text));
  242. Params1.Add("系列号", Convert.ToUInt16(textBox_Serial.Text));
  243. Params1.Add("ECO增益", Convert.ToUInt16(float.Parse(textBox_ECO_Gain.Text) * 100));//放大100倍
  244. Params1.Add("ECO加速", Convert.ToUInt16(float.Parse(textBox_ECO_Acc.Text) * 100));
  245. Params1.Add("NORM增益", Convert.ToUInt16(float.Parse(textBox_NORM_Gain.Text) * 100));
  246. Params1.Add("NORM加速", Convert.ToUInt16(float.Parse(textBox_NORM_Acc.Text) * 100));
  247. Params1.Add("SPORT增益", Convert.ToUInt16(float.Parse(textBox_SPORT_Gain.Text) * 100));
  248. Params1.Add("SPORT加速", Convert.ToUInt16(float.Parse(textBox_SPORT_Acc.Text) * 100));
  249. Params1.Add("TURBO增益", Convert.ToUInt16(float.Parse(textBox_TURBO_Gain.Text) * 100));
  250. Params1.Add("TURBO加速", Convert.ToUInt16(float.Parse(textBox_TURBO_Acc.Text) * 100));
  251. Params1.Add("SMART增益", Convert.ToUInt16(float.Parse(textBox_SMART_Gain.Text) * 100));
  252. Params1.Add("SMART加速", Convert.ToUInt16(float.Parse(textBox_SMART_Acc.Text) * 100));
  253. Params1.Add("车速级数", Convert.ToUInt16(textBox_SpeedSensor.Text));
  254. Params1.Add("踏频启动", Convert.ToUInt16(textBox_CadenceStart.Text));
  255. if (comboBox_GasMode.Text == "不支持")
  256. {
  257. Params1.Add("指拨模式", 0x55);
  258. }
  259. else if (comboBox_GasMode.Text == "支持")
  260. {
  261. Params1.Add("指拨模式", 0xAA);
  262. }
  263. else
  264. {
  265. MessageBox.Show("请检查指拨模式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  266. }
  267. if (comboBox_SpeedSensor.Text == "传感器")
  268. {
  269. Params1.Add("速度信号来源", 0x55);
  270. }
  271. else if (comboBox_GasMode.Text == "踏频")
  272. {
  273. Params1.Add("速度信号来源", 0xAA);
  274. }
  275. else if (comboBox_GasMode.Text == "通信")
  276. {
  277. Params1.Add("速度信号来源", 0xEE);
  278. }
  279. else
  280. {
  281. MessageBox.Show("请检查速度信号来源设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  282. }
  283. Params1.Add("周长微调", Convert.ToUInt16(textBox_WheelSizeAdj.Text));
  284. Params1.Add("低压保护", Convert.ToUInt16(textBox_UV_Protect.Text));//mV
  285. Params1.Add("推行限速", Convert.ToUInt16(float.Parse(textBox_Walk_SpeedLimit.Text) * 10));//放大10倍
  286. Params1.Add("推行转速", Convert.ToUInt16(textBox_WalkSpeed.Text));
  287. //参数2
  288. Params2.Clear();
  289. if (comboBox_AstSensor.Text == "不支持")
  290. {
  291. Params2.Add("姿态传感器", 0x55);
  292. }
  293. else if (comboBox_AstSensor.Text == "支持")
  294. {
  295. Params2.Add("姿态传感器", 0xAA);
  296. }
  297. else
  298. {
  299. MessageBox.Show("请检查姿态传感器设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  300. }
  301. Params2.Add("俯仰角零偏", Convert.ToUInt16(float.Parse(textBox_Angle_P.Text) * 10));
  302. Params2.Add("横滚角零偏", Convert.ToUInt16(float.Parse(textBox_Angle_R.Text) * 10));
  303. if (comboBox_LightMode.Text == "模式 1")
  304. {
  305. Params2.Add("尾灯模式", 1);
  306. }
  307. else if(comboBox_LightMode.Text == "模式 2")
  308. {
  309. Params2.Add("尾灯模式", 2);
  310. }
  311. else if (comboBox_LightMode.Text == "模式 3")
  312. {
  313. Params2.Add("尾灯模式", 3);
  314. }
  315. else if (comboBox_LightMode.Text == "模式 4")
  316. {
  317. Params2.Add("尾灯模式", 4);
  318. }
  319. //马达参数
  320. MotorParam.Clear();
  321. MotorParam.Add("额定功率", Convert.ToUInt16(textBox_RatePower.Text));
  322. MotorParam.Add("额定转速", Convert.ToUInt16(textBox_RateSpeed.Text));
  323. MotorParam.Add("定子电阻", Convert.ToUInt16(textBox_RotorR.Text));
  324. MotorParam.Add("定子Lq", Convert.ToUInt16(textBox_Rotor_Lq.Text));
  325. MotorParam.Add("定子Ld", Convert.ToUInt16(textBox_Rotor_Ld.Text));
  326. MotorParam.Add("反电动势", Convert.ToUInt16(textBox_E.Text));
  327. MotorParam.Add("额定电压", Convert.ToUInt16(textBox_Rate_Vol.Text));
  328. //其它信息
  329. Otherinfo.Clear();
  330. Otherinfo.Add("生产商", textBox_Mac.Text);
  331. Otherinfo.Add("生产地", textBox_Mac_Addr.Text);
  332. Otherinfo.Add("生产日期", textBox_Mac_Date.Text);
  333. Otherinfo.Add("校验密钥", textBox_Secrect.Text);
  334. Otherinfo.Add("信息1", textBox_Info1.Text);
  335. Otherinfo.Add("信息2", textBox_Info2.Text);
  336. Otherinfo.Add("信息3", textBox_Info3.Text);
  337. return true;
  338. }
  339. catch(Exception ex)
  340. {
  341. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  342. return false;
  343. }
  344. }
  345. private void button_Default_Click(object sender, EventArgs e)
  346. {
  347. SetDefault();
  348. ParamsDisplayUpdate();
  349. }
  350. private void button_Generate_Click(object sender, EventArgs e)
  351. {
  352. //空间内容更新到字典
  353. if (DisplaySetToParams() == false)
  354. {
  355. MessageBox.Show("参数生成失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  356. return;
  357. }
  358. //保存为文件
  359. if (textBox_Model.Text == string.Empty)
  360. {
  361. MessageBox.Show("请输入电机型号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  362. return;
  363. }
  364. if (textBox_Client.Text == string.Empty)
  365. {
  366. textBox_Client.Text = "STD";
  367. }
  368. using (StreamWriter file = new StreamWriter("cfg\\" + textBox_Model.Text + "_" + textBox_Client.Text + "_" + textBox_Remark.Text + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".ttcfg"))
  369. {
  370. //用户参数1
  371. file.WriteLine("[{0}]", "用户参数1");
  372. foreach (var entry in Params1)
  373. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  374. //用户参数2
  375. file.WriteLine("");
  376. file.WriteLine("[{0}]", "用户参数2");
  377. foreach (var entry in Params2)
  378. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  379. //马达参数
  380. file.WriteLine("");
  381. file.WriteLine("[{0}]", "马达参数");
  382. foreach (var entry in MotorParam)
  383. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  384. //其它信息
  385. file.WriteLine("");
  386. file.WriteLine("[{0}]", "其它信息");
  387. foreach (var entry in Otherinfo)
  388. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  389. }
  390. MessageBox.Show("参数已生成,进入文件管理页面查看!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  391. }
  392. }
  393. }