ExportForm.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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 System.Reflection;
  14. using NPOI;
  15. using NPOI.SS.UserModel;
  16. using NPOI.HSSF.UserModel;
  17. using Spire.Xls;
  18. using Workbook = Spire.Xls.Workbook;
  19. using NPOI.POIFS.FileSystem;
  20. namespace MOTINOVA_Motor_Factory_Set
  21. {
  22. public partial class ExportForm : Form
  23. {
  24. //参数按照字典类型存储
  25. Dictionary<string, UInt16> Params1 = new Dictionary<string, UInt16>();
  26. Dictionary<string, UInt16> Params2 = new Dictionary<string, UInt16>();
  27. Dictionary<string, UInt16> MotorParam = new Dictionary<string, UInt16>();
  28. Dictionary<string, string> Otherinfo = new Dictionary<string, string>();
  29. Dictionary<string, UInt16> TestThData = new Dictionary<string, ushort>();
  30. Dictionary<string, string> MarkInfo = new Dictionary<string, string>();
  31. //文件路径
  32. public string FilePath = "";
  33. public ExportForm()
  34. {
  35. InitializeComponent();
  36. }
  37. private void ExportForm_Load(object sender, EventArgs e)
  38. {
  39. }
  40. private void SetDefault()
  41. {
  42. //参数1
  43. Params1.Clear();
  44. Params1.Add("启动模式", 2);
  45. Params1.Add("停机时间", 100);
  46. Params1.Add("限速值", 25);
  47. Params1.Add("下降速度", 3);
  48. Params1.Add("前飞", 14);
  49. Params1.Add("后飞", 9);
  50. Params1.Add("限流", 15);
  51. Params1.Add("温度预警", 95);
  52. Params1.Add("温度保护", 125);
  53. Params1.Add("码表", 0x55);//有,不支持无码表
  54. Params1.Add("轮胎周长", 219);//cm
  55. Params1.Add("系列号", 0);
  56. Params1.Add("ECO增益", 100);//放大100倍
  57. Params1.Add("ECO加速", 100);
  58. Params1.Add("NORM增益", 100);
  59. Params1.Add("NORM加速", 100);
  60. Params1.Add("SPORT增益", 100);
  61. Params1.Add("SPORT加速", 100);
  62. Params1.Add("TURBO增益", 100);
  63. Params1.Add("TURBO加速", 100);
  64. Params1.Add("SMART增益", 100);
  65. Params1.Add("SMART加速", 100);
  66. Params1.Add("车速级数", 1);
  67. Params1.Add("踏频启动", 2);
  68. Params1.Add("指拨模式", 0x55);//不支持
  69. Params1.Add("速度信号来源", 0x55);//传感器
  70. Params1.Add("周长微调", 0);
  71. Params1.Add("低压保护", 3000);//mV
  72. Params1.Add("推行限速", 60);//放大10倍
  73. Params1.Add("推行转速", 135);
  74. //参数2
  75. Params2.Clear();
  76. Params2.Add("姿态传感器", 0x55);//不支持
  77. Params2.Add("俯仰角零偏", 0);
  78. Params2.Add("横滚角零偏", 0);
  79. Params2.Add("尾灯模式", 2);
  80. Params2.Add("前灯电压", 12);
  81. Params2.Add("尾灯电压", 12);
  82. Params2.Add("报警阈值", 150);//放大10倍
  83. Params2.Add("尾灯脉宽", 70);
  84. Params2.Add("尾灯周期", 150);
  85. Params2.Add("起始限速", 0);
  86. Params2.Add("结束限速", 0);
  87. Params2.Add("限速微调", 0);
  88. Params2.Add("ECO最大电流增益", 100);
  89. Params2.Add("ECO最大力矩增益", 100);
  90. Params2.Add("NORM最大电流增益", 100);
  91. Params2.Add("NORM最大力矩增益", 100);
  92. Params2.Add("SPORT最大电流增益", 100);
  93. Params2.Add("SPORT最大力矩增益", 100);
  94. Params2.Add("TURBO最大电流增益", 100);
  95. Params2.Add("TURBO最大力矩增益", 100);
  96. Params2.Add("SMART最大电流增益", 100);
  97. Params2.Add("SMART最大力矩增益", 100);
  98. //马达参数
  99. MotorParam.Clear();
  100. MotorParam.Add("额定功率", 250);
  101. MotorParam.Add("空载转速", 1200);
  102. MotorParam.Add("定子电阻", 10);
  103. MotorParam.Add("定子Lq", 10);
  104. MotorParam.Add("定子Ld", 10);
  105. MotorParam.Add("反电动势", 36000);
  106. MotorParam.Add("额定电压", 36);
  107. //其它信息
  108. Otherinfo.Clear();
  109. Otherinfo.Add("生产商", "TTIUM");
  110. Otherinfo.Add("生产地", "Wuhan");
  111. Otherinfo.Add("生产日期", DateTime.Now.ToString("yyyyMMdd"));
  112. Otherinfo.Add("校验密钥", "AVONITOM");
  113. Otherinfo.Add("信息1", "");
  114. Otherinfo.Add("信息2", "");
  115. Otherinfo.Add("信息3", "");
  116. //测试阈值
  117. TestThData.Clear();
  118. TestThData.Add("空载电流", 1000);
  119. TestThData.Add("踏频", 120);
  120. TestThData.Add("车速", 150);
  121. TestThData.Add("指拨转速", 1225);
  122. TestThData.Add("零偏最小值", 100);
  123. TestThData.Add("零偏最大值", 1800);
  124. TestThData.Add("标定系数最小值", 25);
  125. TestThData.Add("标定系数最大值", 75);
  126. TestThData.Add("启动值最小值", 350);
  127. TestThData.Add("启动值最大值", 750);
  128. TestThData.Add("标定系数标准差", 250);
  129. //其它测试备注信息
  130. MarkInfo.Clear();
  131. MarkInfo.Add("PCBA版号", "");
  132. }
  133. private void ParamsDisplayUpdate()
  134. {
  135. //参数1
  136. comboBox_StartMode.SelectedIndex = Params1["启动模式"] - 1;
  137. textBox_StopTime.Text = Params1["停机时间"].ToString();
  138. textBox_SpeedLimit.Text = Params1["限速值"].ToString();
  139. textBox_Dec.Text = Params1["下降速度"].ToString();
  140. textBox_T_Front.Text = Params1["前飞"].ToString();
  141. textBox_T_Tail.Text = Params1["后飞"].ToString();
  142. textBox_MaxCurrent.Text = Params1["限流"].ToString();
  143. textBox_NTC_Alarm.Text = Params1["温度预警"].ToString();
  144. textBox_NTC_Ptotect.Text = Params1["温度保护"].ToString();
  145. if (Params1["码表"] == 0x55)
  146. {
  147. comboBox_NoPBU.SelectedIndex = 1;
  148. }
  149. else if (Params1["码表"] == 0xAA)
  150. {
  151. comboBox_NoPBU.SelectedIndex = 0;
  152. }
  153. textBox_WheelSize.Text = Params1["轮胎周长"].ToString();
  154. textBox_Serial.Text = Params1["系列号"].ToString();
  155. textBox_ECO_Gain.Text = ((float)(Params1["ECO增益"]) / 100.0f).ToString("#0.00");
  156. textBox_ECO_Acc.Text = ((float)(Params1["ECO加速"]) / 100.0f).ToString("#0.00");
  157. textBox_NORM_Gain.Text = ((float)(Params1["NORM增益"]) / 100.0f).ToString("#0.00");
  158. textBox_NORM_Acc.Text = ((float)(Params1["NORM加速"]) / 100.0f).ToString("#0.00");
  159. textBox_SPORT_Gain.Text = ((float)(Params1["SPORT增益"]) / 100.0f).ToString("#0.00");
  160. textBox_SPORT_Acc.Text = ((float)(Params1["SPORT加速"]) / 100.0f).ToString("#0.00");
  161. textBox_TURBO_Gain.Text = ((float)(Params1["TURBO增益"]) / 100.0f).ToString("#0.00");
  162. textBox_TURBO_Acc.Text = ((float)(Params1["TURBO加速"]) / 100.0f).ToString("#0.00");
  163. textBox_SMART_Gain.Text = ((float)(Params1["SMART增益"]) / 100.0f).ToString("#0.00");
  164. textBox_SMART_Acc.Text = ((float)(Params1["SMART加速"]) / 100.0f).ToString("#0.00");
  165. textBox_SpeedSensor.Text = Params1["车速级数"].ToString();
  166. textBox_CadenceStart.Text = Params1["踏频启动"].ToString();
  167. if (Params1["指拨模式"] == 0x55) //不支持
  168. {
  169. comboBox_GasMode.SelectedIndex = 0;
  170. comboBox_GasPowerLimit.SelectedIndex = 0;
  171. comboBox_GasModeStart.SelectedIndex = 0;
  172. textBox_GasSpeedLimit.Text = "无效";
  173. }
  174. else
  175. {
  176. //控制模式
  177. if ((Params1["指拨模式"] & 0x01) == 0x00) //速度模式
  178. {
  179. comboBox_GasMode.SelectedIndex = 1;
  180. }
  181. else //力矩模式
  182. {
  183. comboBox_GasMode.SelectedIndex = 2;
  184. }
  185. //功率限制方式
  186. if ((Params1["指拨模式"] & 0x02) == 0x02) //挡位限制功率
  187. {
  188. comboBox_GasPowerLimit.SelectedIndex = 1;
  189. }
  190. else //挡位不限制功率
  191. {
  192. comboBox_GasPowerLimit.SelectedIndex = 2;
  193. }
  194. //启动方式
  195. if ((Params1["指拨启动方式"] & 0x04) == 0x00) //零速
  196. {
  197. comboBox_GasPowerLimit.SelectedIndex = 1;
  198. }
  199. else //带速
  200. {
  201. comboBox_GasPowerLimit.SelectedIndex = 2;
  202. }
  203. //指拨限速
  204. if ((Params1["指拨模式"] >> 3) <= 5)
  205. textBox_GasSpeedLimit.Text = ((Params1["限速值"] + (Params1["指拨模式"] >> 3) + 31 - 0x15) & 0x1F).ToString();
  206. else
  207. textBox_GasSpeedLimit.Text = ((Params1["限速值"] + (Params1["指拨模式"] >> 3) - 0x15) & 0x1F).ToString();
  208. }
  209. if (Params1["速度信号来源"] == 0x55)
  210. {
  211. comboBox_SpeedSensor.SelectedIndex = 0;
  212. }
  213. else if (Params1["速度信号来源"] == 0xAA)
  214. {
  215. comboBox_SpeedSensor.SelectedIndex = 1;
  216. }
  217. else if (Params1["速度信号来源"] == 0xEE)
  218. {
  219. comboBox_SpeedSensor.SelectedIndex = 2;
  220. }
  221. textBox_WheelSizeAdj.Text = Params1["周长微调"].ToString();
  222. textBox_UV_Protect.Text = Params1["低压保护"].ToString();
  223. textBox_Walk_SpeedLimit.Text = ((float)(Params1["推行限速"]) / 10.0f).ToString("#0.0");
  224. textBox_WalkSpeed.Text = Params1["推行转速"].ToString();
  225. //参数2
  226. if (Params2["姿态传感器"] == 0x55)
  227. {
  228. comboBox_AstSensor.SelectedIndex = 0;
  229. }
  230. else if (Params1["姿态传感器"] == 0xAA)
  231. {
  232. comboBox_AstSensor.SelectedIndex = 1;
  233. }
  234. textBox_Angle_P.Text = ((float)(Params2["俯仰角零偏"]) / 10.0f).ToString("#0.0");
  235. textBox_Angle_R.Text = ((float)(Params2["横滚角零偏"]) / 10.0f).ToString("#0.0");
  236. comboBox_LightMode.SelectedIndex = Params2["尾灯模式"] - 1;
  237. if (Params2["前灯电压"] == 6)
  238. {
  239. comboBox_HeadLightVol.SelectedIndex = 0;
  240. }
  241. else if (Params2["前灯电压"] == 12)
  242. {
  243. comboBox_HeadLightVol.SelectedIndex = 1;
  244. }
  245. else if (Params2["前灯电压"] == 0xFF)
  246. {
  247. comboBox_HeadLightVol.SelectedIndex = 2;
  248. }
  249. else if (Params2["前灯电压"] == 0)
  250. {
  251. comboBox_HeadLightVol.SelectedIndex = 3;
  252. }
  253. if (Params2["尾灯电压"] == 6)
  254. {
  255. comboBox_TailLightVol.SelectedIndex = 0;
  256. }
  257. else if (Params2["尾灯电压"] == 12)
  258. {
  259. comboBox_TailLightVol.SelectedIndex = 1;
  260. }
  261. else if (Params2["尾灯电压"] == 0xFF)
  262. {
  263. comboBox_TailLightVol.SelectedIndex = 2;
  264. }
  265. else if (Params2["尾灯电压"] == 0)
  266. {
  267. comboBox_TailLightVol.SelectedIndex = 3;
  268. }
  269. textBox_AlarmSpeed.Text = ((float)(Params2["报警阈值"]) / 10.0f).ToString("#0.0");
  270. textBox_LightPluse.Text = Params2["尾灯脉宽"].ToString();
  271. textBox_LightPeriod.Text = Params2["尾灯周期"].ToString();
  272. textBox_LimitSpeedStart.Text = ((float)(Params2["起始限速"]) / 10.0f).ToString("#0.0");
  273. textBox_LimitSpeedStop.Text = ((float)(Params2["结束限速"]) / 10.0f).ToString("#0.0");
  274. //马达参数
  275. textBox_RatePower.Text = MotorParam["额定功率"].ToString();
  276. textBox_RateSpeed.Text = MotorParam["空载转速"].ToString();
  277. textBox_RotorR.Text = MotorParam["定子电阻"].ToString();
  278. textBox_Rotor_Lq.Text = MotorParam["定子Lq"].ToString();
  279. textBox_Rotor_Ld.Text = MotorParam["定子Ld"].ToString();
  280. textBox_E.Text = MotorParam["反电动势"].ToString();
  281. textBox_Rate_Vol.Text = MotorParam["额定电压"].ToString();
  282. //其它信息
  283. textBox_Mac.Text = Otherinfo["生产商"].ToString();
  284. textBox_Mac_Addr.Text = Otherinfo["生产地"].ToString();
  285. textBox_Mac_Date.Text = Otherinfo["生产日期"].ToString();
  286. textBox_Secrect.Text = Otherinfo["校验密钥"].ToString();
  287. textBox_Info1.Text = Otherinfo["信息1"].ToString();
  288. textBox_Info2.Text = Otherinfo["信息2"].ToString();
  289. textBox_Info3.Text = Otherinfo["信息3"].ToString();
  290. //测试阈值
  291. textBox_NC_Current.Text = TestThData["空载电流"].ToString();
  292. textBox_SpeedTh.Text = TestThData["车速"].ToString();
  293. textBox_CadenceTh.Text = TestThData["踏频"].ToString();
  294. textBox_GasSpeedTh.Text = TestThData["指拨转速"].ToString();
  295. textBox_Zero_Min.Text = TestThData["零偏最小值"].ToString();
  296. textBox_Zero_Max.Text = TestThData["零偏最大值"].ToString();
  297. textBox_K_Min.Text = ((float)(TestThData["标定系数最小值"]) / 100.0f).ToString("#0.00");
  298. textBox_K_Max.Text = ((float)(TestThData["标定系数最大值"]) / 100.0f).ToString("#0.00");
  299. textBox_Start_Min.Text = TestThData["启动值最小值"].ToString();
  300. textBox_Start_Max.Text = TestThData["启动值最大值"].ToString();
  301. textBox_K_Sqrd.Text= ((float)(TestThData["标定系数标准差"]) / 1000.0f).ToString("#0.000");
  302. //其它测试备注信息
  303. textBox_HW_Version.Text = MarkInfo["PCBA版号"];
  304. //TE版本信息
  305. textBox_TE_FW_Version.Text = "N_A";
  306. }
  307. private bool DisplaySetToParams()
  308. {
  309. try
  310. {
  311. //参数1
  312. Params1.Clear();
  313. if (comboBox_StartMode.Text == "柔和")
  314. {
  315. Params1.Add("启动模式", 1);
  316. }
  317. else if (comboBox_StartMode.Text == "正常")
  318. {
  319. Params1.Add("启动模式", 2);
  320. }
  321. else if (comboBox_StartMode.Text == "强劲")
  322. {
  323. Params1.Add("启动模式", 3);
  324. }
  325. else
  326. {
  327. MessageBox.Show("请检查启动模式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  328. return false;
  329. }
  330. Params1.Add("停机时间", Convert.ToUInt16(textBox_StopTime.Text));
  331. if (Params1["停机时间"] < 50 || Params1["停机时间"] > 500)
  332. {
  333. MessageBox.Show("停机时间有效值:50~500 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  334. return false;
  335. }
  336. Params1.Add("限速值", Convert.ToUInt16(textBox_SpeedLimit.Text));
  337. if (Params1["限速值"] < 5 || Params1["限速值"] > 120)
  338. {
  339. MessageBox.Show("限速值有效值:5~120 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  340. return false;
  341. }
  342. Params1.Add("下降速度", Convert.ToUInt16(textBox_Dec.Text));
  343. if (Params1["下降速度"] < 1 || Params1["下降速度"] > 5)
  344. {
  345. MessageBox.Show("下降速度有效值:1~5 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  346. return false;
  347. }
  348. Params1.Add("前飞", Convert.ToUInt16(textBox_T_Front.Text));
  349. if (Params1["前飞"] < 5 || Params1["前飞"] > 100)
  350. {
  351. MessageBox.Show("前飞有效值:5~100 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  352. return false;
  353. }
  354. Params1.Add("后飞", Convert.ToUInt16(textBox_T_Tail.Text));
  355. if (Params1["后飞"] < 5 || Params1["后飞"] > 100)
  356. {
  357. MessageBox.Show("后飞有效值:5~100 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  358. return false;
  359. }
  360. Params1.Add("限流", Convert.ToUInt16(textBox_MaxCurrent.Text));
  361. if (Params1["限流"] < 5 || Params1["限流"] > 25)
  362. {
  363. MessageBox.Show("限流有效值:5~25 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  364. return false;
  365. }
  366. Params1.Add("温度预警", Convert.ToUInt16(textBox_NTC_Alarm.Text));
  367. Params1.Add("温度保护", Convert.ToUInt16(textBox_NTC_Ptotect.Text));
  368. if (comboBox_NoPBU.Text == "有")
  369. {
  370. Params1.Add("码表", 0x55);
  371. }
  372. else if (comboBox_NoPBU.Text == "无")
  373. {
  374. Params1.Add("码表", 0xAA);
  375. }
  376. else
  377. {
  378. MessageBox.Show("请检查无码表设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  379. return false;
  380. }
  381. Params1.Add("轮胎周长", Convert.ToUInt16(textBox_WheelSize.Text));
  382. if (Params1["轮胎周长"] < 80 || Params1["轮胎周长"] > 250)
  383. {
  384. MessageBox.Show("轮胎周长有效值:80~250 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  385. return false;
  386. }
  387. Params1.Add("系列号", Convert.ToUInt16(textBox_Serial.Text));
  388. if (Params1["系列号"] < 1 || Params1["系列号"] > 16)
  389. {
  390. MessageBox.Show("系列号有效值:1~16 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  391. return false;
  392. }
  393. Params1.Add("ECO增益", Convert.ToUInt16(float.Parse(textBox_ECO_Gain.Text) * 100));//放大100倍
  394. Params1.Add("ECO加速", Convert.ToUInt16(float.Parse(textBox_ECO_Acc.Text) * 100));
  395. Params1.Add("NORM增益", Convert.ToUInt16(float.Parse(textBox_NORM_Gain.Text) * 100));
  396. Params1.Add("NORM加速", Convert.ToUInt16(float.Parse(textBox_NORM_Acc.Text) * 100));
  397. Params1.Add("SPORT增益", Convert.ToUInt16(float.Parse(textBox_SPORT_Gain.Text) * 100));
  398. Params1.Add("SPORT加速", Convert.ToUInt16(float.Parse(textBox_SPORT_Acc.Text) * 100));
  399. Params1.Add("TURBO增益", Convert.ToUInt16(float.Parse(textBox_TURBO_Gain.Text) * 100));
  400. Params1.Add("TURBO加速", Convert.ToUInt16(float.Parse(textBox_TURBO_Acc.Text) * 100));
  401. Params1.Add("SMART增益", Convert.ToUInt16(float.Parse(textBox_SMART_Gain.Text) * 100));
  402. Params1.Add("SMART加速", Convert.ToUInt16(float.Parse(textBox_SMART_Acc.Text) * 100));
  403. Params1.Add("车速级数", Convert.ToUInt16(textBox_SpeedSensor.Text));
  404. Params1.Add("踏频启动", Convert.ToUInt16(textBox_CadenceStart.Text));
  405. if (comboBox_GasMode.SelectedIndex == 0) //不支持
  406. {
  407. Params1.Add("指拨模式", 0x55);
  408. }
  409. else if(comboBox_GasMode.SelectedIndex == 3) //推行
  410. {
  411. Params1.Add("指拨模式", 0xF8);
  412. }
  413. else //支持
  414. {
  415. Byte GasModeTemp = 0;
  416. //控制模式
  417. if (comboBox_GasMode.SelectedIndex == 1) //支持,速度模式
  418. GasModeTemp &= 0xFE;
  419. else if (comboBox_GasMode.SelectedIndex == 2) //支持,力矩模式
  420. GasModeTemp |= 0x01;
  421. //挡位功率限制
  422. if (comboBox_GasPowerLimit.SelectedIndex == 1) //支持,限制
  423. GasModeTemp |= 0x02;
  424. else if (comboBox_GasPowerLimit.SelectedIndex == 2) //支持,不限制
  425. GasModeTemp &= 0xFD;
  426. else
  427. {
  428. MessageBox.Show("请检查指拨功率限制设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  429. return false;
  430. }
  431. //启动方式
  432. if (comboBox_GasModeStart.SelectedIndex == 1) //支持,零速启动
  433. GasModeTemp &= 0xFB;
  434. else if (comboBox_GasModeStart.SelectedIndex == 2) //支持,带速启动
  435. GasModeTemp |= 0x04;
  436. else
  437. {
  438. MessageBox.Show("请检查指拨启动方式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  439. return false;
  440. }
  441. //限速
  442. if (Convert.ToByte(textBox_GasSpeedLimit.Text) - Convert.ToByte(textBox_SpeedLimit.Text) > 15) //不支持
  443. {
  444. MessageBox.Show("请检查指拨限速设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  445. return false;
  446. }
  447. else if (Convert.ToByte(textBox_SpeedLimit.Text) - Convert.ToByte(textBox_GasSpeedLimit.Text) > 15) //不支持
  448. {
  449. MessageBox.Show("请检查指拨限速设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  450. return false;
  451. }
  452. if (Convert.ToByte(textBox_GasSpeedLimit.Text) - Convert.ToByte(textBox_SpeedLimit.Text) >= 10)
  453. GasModeTemp |= (byte)((0x15 + Convert.ToByte(textBox_GasSpeedLimit.Text) - Convert.ToByte(textBox_SpeedLimit.Text) - 0x1F) << 3);
  454. else
  455. GasModeTemp |= (byte)((0x15 + Convert.ToByte(textBox_GasSpeedLimit.Text) - Convert.ToByte(textBox_SpeedLimit.Text)) << 3);
  456. Params1.Add("指拨模式", GasModeTemp);
  457. }
  458. if (comboBox_SpeedSensor.Text == "传感器")
  459. {
  460. Params1.Add("速度信号来源", 0x55);
  461. }
  462. else if (comboBox_SpeedSensor.Text == "踏频")
  463. {
  464. Params1.Add("速度信号来源", 0xAA);
  465. }
  466. else if (comboBox_SpeedSensor.Text == "通信")
  467. {
  468. Params1.Add("速度信号来源", 0xEE);
  469. }
  470. else
  471. {
  472. MessageBox.Show("请检查速度信号来源设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  473. return false;
  474. }
  475. Params1.Add("周长微调", Convert.ToUInt16((byte)(Convert.ToSByte(textBox_WheelSizeAdj.Text))));
  476. Params1.Add("低压保护", Convert.ToUInt16(textBox_UV_Protect.Text));//mV
  477. Params1.Add("推行限速", Convert.ToUInt16(float.Parse(textBox_Walk_SpeedLimit.Text) * 10));//放大10倍
  478. Params1.Add("推行转速", Convert.ToUInt16(textBox_WalkSpeed.Text));
  479. //参数2
  480. Params2.Clear();
  481. if (comboBox_AstSensor.Text == "不支持")
  482. {
  483. Params2.Add("姿态传感器", 0x55);
  484. }
  485. else if (comboBox_AstSensor.Text == "支持")
  486. {
  487. Params2.Add("姿态传感器", 0xAA);
  488. }
  489. else
  490. {
  491. MessageBox.Show("请检查姿态传感器设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  492. return false;
  493. }
  494. Params2.Add("俯仰角零偏", Convert.ToUInt16((UInt16)(float.Parse(textBox_Angle_P.Text) * 10)));
  495. Params2.Add("横滚角零偏", Convert.ToUInt16((UInt16)(float.Parse(textBox_Angle_R.Text) * 10)));
  496. if (comboBox_LightMode.Text == "模式 1")
  497. {
  498. Params2.Add("尾灯模式", 1);
  499. }
  500. else if(comboBox_LightMode.Text == "模式 2")
  501. {
  502. Params2.Add("尾灯模式", 2);
  503. }
  504. else if (comboBox_LightMode.Text == "模式 3")
  505. {
  506. Params2.Add("尾灯模式", 3);
  507. }
  508. else if (comboBox_LightMode.Text == "模式 4")
  509. {
  510. Params2.Add("尾灯模式", 4);
  511. }
  512. else if (comboBox_LightMode.Text == "模式 5")
  513. {
  514. Params2.Add("尾灯模式", 5);
  515. }
  516. else if (comboBox_LightMode.Text == "模式 6")
  517. {
  518. Params2.Add("尾灯模式", 6);
  519. }
  520. if (comboBox_HeadLightVol.Text == "6V")
  521. {
  522. Params2.Add("前灯电压", 6);
  523. }
  524. else if (comboBox_HeadLightVol.Text == "12V")
  525. {
  526. Params2.Add("前灯电压", 12);
  527. }
  528. else if (comboBox_HeadLightVol.Text == "随电池")
  529. {
  530. Params2.Add("前灯电压", 0xFF);
  531. }
  532. else if (comboBox_HeadLightVol.Text == "硬件配置")
  533. {
  534. Params2.Add("前灯电压", 0);
  535. }
  536. if (comboBox_TailLightVol.Text == "6V")
  537. {
  538. Params2.Add("尾灯电压", 6);
  539. }
  540. else if (comboBox_TailLightVol.Text == "12V")
  541. {
  542. Params2.Add("尾灯电压", 12);
  543. }
  544. else if (comboBox_TailLightVol.Text == "随电池")
  545. {
  546. Params2.Add("尾灯电压", 0xFF);
  547. }
  548. else if (comboBox_TailLightVol.Text == "硬件配置")
  549. {
  550. Params2.Add("尾灯电压", 0);
  551. }
  552. Params2.Add("报警阈值", Convert.ToUInt16(float.Parse(textBox_AlarmSpeed.Text) * 10));//放大10倍
  553. Params2.Add("尾灯脉宽", Convert.ToUInt16(textBox_LightPluse.Text));
  554. Params2.Add("尾灯周期", Convert.ToUInt16(textBox_LightPeriod.Text));
  555. Params2.Add("起始限速", Convert.ToUInt16((byte)(float.Parse(textBox_LimitSpeedStart.Text) * 10)));
  556. Params2.Add("结束限速", Convert.ToUInt16((byte)(float.Parse(textBox_LimitSpeedStop.Text) * 10)));
  557. Params2.Add("限速微调", 0);
  558. Params2.Add("ECO最大电流增益", 100);
  559. Params2.Add("ECO最大力矩增益", 100);
  560. Params2.Add("NORM最大电流增益", 100);
  561. Params2.Add("NORM最大力矩增益", 100);
  562. Params2.Add("SPORT最大电流增益", 100);
  563. Params2.Add("SPORT最大力矩增益", 100);
  564. Params2.Add("TURBO最大电流增益", 100);
  565. Params2.Add("TURBO最大力矩增益", 100);
  566. Params2.Add("SMART最大电流增益", 100);
  567. Params2.Add("SMART最大力矩增益", 100);
  568. //马达参数
  569. MotorParam.Clear();
  570. MotorParam.Add("额定功率", Convert.ToUInt16(textBox_RatePower.Text));
  571. MotorParam.Add("空载转速", Convert.ToUInt16(textBox_RateSpeed.Text));
  572. MotorParam.Add("定子电阻", Convert.ToUInt16(textBox_RotorR.Text));
  573. MotorParam.Add("定子Lq", Convert.ToUInt16(textBox_Rotor_Lq.Text));
  574. MotorParam.Add("定子Ld", Convert.ToUInt16(textBox_Rotor_Ld.Text));
  575. MotorParam.Add("反电动势", Convert.ToUInt16(textBox_E.Text));
  576. MotorParam.Add("额定电压", Convert.ToUInt16(textBox_Rate_Vol.Text));
  577. //其它信息
  578. Otherinfo.Clear();
  579. Otherinfo.Add("生产商", textBox_Mac.Text);
  580. Otherinfo.Add("生产地", textBox_Mac_Addr.Text);
  581. Otherinfo.Add("生产日期", textBox_Mac_Date.Text);
  582. Otherinfo.Add("校验密钥", textBox_Secrect.Text);
  583. Otherinfo.Add("信息1", textBox_Info1.Text);
  584. Otherinfo.Add("信息2", textBox_Info2.Text);
  585. Otherinfo.Add("信息3", textBox_Info3.Text);
  586. //测试阈值
  587. TestThData.Clear();
  588. TestThData.Add("空载电流", Convert.ToUInt16(textBox_NC_Current.Text));
  589. TestThData.Add("车速", Convert.ToUInt16(textBox_SpeedTh.Text));
  590. TestThData.Add("踏频", Convert.ToUInt16(textBox_CadenceTh.Text));
  591. TestThData.Add("指拨转速", Convert.ToUInt16(textBox_GasSpeedTh.Text));
  592. TestThData.Add("零偏最小值", Convert.ToUInt16(textBox_Zero_Min.Text));
  593. TestThData.Add("零偏最大值", Convert.ToUInt16(textBox_Zero_Max.Text));
  594. TestThData.Add("标定系数最小值", Convert.ToUInt16(float.Parse(textBox_K_Min.Text) * 100));
  595. TestThData.Add("标定系数最大值", Convert.ToUInt16(float.Parse(textBox_K_Max.Text) * 100));
  596. TestThData.Add("启动值最小值", Convert.ToUInt16(textBox_Start_Min.Text));
  597. TestThData.Add("启动值最大值", Convert.ToUInt16(textBox_Start_Max.Text));
  598. TestThData.Add("标定系数标准差", Convert.ToUInt16(float.Parse(textBox_K_Sqrd.Text) * 1000));
  599. //其它测试备注信息
  600. MarkInfo.Clear();
  601. if (textBox_HW_Version.Text == string.Empty)
  602. {
  603. MessageBox.Show("请输入PCBA版号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  604. return false;
  605. }
  606. else
  607. {
  608. MarkInfo.Add("PCBA版号", textBox_HW_Version.Text);
  609. }
  610. return true;
  611. }
  612. catch(Exception ex)
  613. {
  614. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  615. return false;
  616. }
  617. }
  618. private void button_Default_Click(object sender, EventArgs e)
  619. {
  620. if (MessageBox.Show("确认恢复默认值?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  621. {
  622. return;
  623. }
  624. SetDefault();
  625. ParamsDisplayUpdate();
  626. }
  627. private void button_Generate_Click(object sender, EventArgs e)
  628. {
  629. if (MessageBox.Show("确认提交?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
  630. {
  631. return;
  632. }
  633. //空间内容更新到字典
  634. if (DisplaySetToParams() == false)
  635. {
  636. MessageBox.Show("参数生成失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  637. return;
  638. }
  639. //保存为配置文件
  640. if (textBox_Model.Text == string.Empty) //判断型号是否填写
  641. {
  642. MessageBox.Show("请输入电机型号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  643. return;
  644. }
  645. if (textBox_Client.Text == string.Empty) //判断订单编号是否填写
  646. {
  647. MessageBox.Show("请输入订单号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  648. return;
  649. }
  650. if (textBox_HW_Version.Text == String.Empty) //判断PCBA板号是否填写
  651. {
  652. MessageBox.Show("请输入PCBA板号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  653. return;
  654. }
  655. if (comboBox_Baudrate.SelectedIndex == -1)
  656. {
  657. MessageBox.Show("请设定波特率!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  658. return;
  659. }
  660. 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}");
  661. if (Reg.IsMatch(textBox_FW_Version.Text) == false) //判断主控软件版本是否填写
  662. {
  663. MessageBox.Show("主控软件版本格式不正确,例如V1.0.0.0.0_20210101 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  664. return;
  665. }
  666. if (textBox_TE_FW_Version.Text != "N_A")//兼容单MCU主控板,无TE时填写N_A
  667. {
  668. Reg = new Regex(@"[V][0-9].[0-9].[0-9]_20\d{6}"); //判断TE软件版本是否填写
  669. if (Reg.IsMatch(textBox_TE_FW_Version.Text) == false) //判断TE软件版本是否填写
  670. {
  671. MessageBox.Show("TE软件版本格式不正确,例如N_A或V1.0.0_20210101 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  672. return;
  673. }
  674. }
  675. button_Generate.BackColor = Color.Red;
  676. button_Generate.Text = "生成中";
  677. button_Generate.Enabled = false;
  678. if (System.IO.Directory.Exists(FilePath) == false)
  679. System.IO.Directory.CreateDirectory(FilePath);
  680. string Datenow = DateTime.Now.ToString("yyyy-MM-dd") + "\\";
  681. if (System.IO.Directory.Exists(FilePath + Datenow) == false)
  682. System.IO.Directory.CreateDirectory(FilePath + Datenow);
  683. 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";
  684. using (StreamWriter file = new StreamWriter(fileName))
  685. {
  686. //用户参数1
  687. file.WriteLine("[{0}]", "用户参数1");
  688. foreach (var entry in Params1)
  689. if (entry.Key == "码表")
  690. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "有" : entry.Value == 0xAA ? "无" : "无效");
  691. else if (entry.Key == "指拨模式")
  692. {
  693. string strTemp = "";
  694. if (entry.Value == 0x55)
  695. strTemp += "不支持";
  696. else if(entry.Value == 0xF8)
  697. strTemp += "支持 推行模式";
  698. else
  699. {
  700. strTemp += "支持";
  701. //控制模式
  702. if((entry.Value & 0x01) == 0x00) //速度模式
  703. strTemp += " 速度模式";
  704. else
  705. strTemp += " 力矩模式";
  706. //功率限制方式
  707. if ((entry.Value & 0x02) == 0x00) //按挡位不限制
  708. strTemp += " 挡位不限制功率";
  709. else
  710. strTemp += " 挡位限制功率";
  711. //启动方式
  712. if ((entry.Value & 0x04) == 0x00) //零速启动
  713. strTemp += " 零速启动";
  714. else
  715. strTemp += " 带速启动";
  716. //限速
  717. strTemp += " 限速:" + textBox_GasSpeedLimit.Text + "km/h";
  718. }
  719. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, strTemp);
  720. }
  721. else if (entry.Key == "速度信号来源")
  722. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "传感器" : entry.Value == 0xAA ? "踏频" : entry.Value == 0xEE ? "通信" : "无效");
  723. else
  724. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  725. //用户参数2
  726. file.WriteLine("");
  727. file.WriteLine("[{0}]", "用户参数2");
  728. foreach (var entry in Params2)
  729. if (entry.Key == "姿态传感器")
  730. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "不支持" : entry.Value == 0xAA ? "支持" : "无效");
  731. else if (entry.Key == "前灯电压")
  732. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0xFF ? "随电池" : entry.Value == 0 ? "硬件配置" : entry.Value + "V");
  733. else if (entry.Key == "尾灯电压")
  734. file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0xFF ? "随电池" : entry.Value == 0 ? "硬件配置" : entry.Value + "V");
  735. else
  736. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  737. //马达参数
  738. file.WriteLine("");
  739. file.WriteLine("[{0}]", "马达参数");
  740. foreach (var entry in MotorParam)
  741. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  742. //其它信息
  743. file.WriteLine("");
  744. file.WriteLine("[{0}]", "其它信息");
  745. foreach (var entry in Otherinfo)
  746. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  747. //测试阈值
  748. file.WriteLine("");
  749. file.WriteLine("[{0}]", "测试阈值");
  750. foreach (var entry in TestThData)
  751. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  752. //其它测试备注信息
  753. file.WriteLine("");
  754. file.WriteLine("[{0}]", "其它测试备注信息");
  755. foreach (var entry in MarkInfo)
  756. file.WriteLine("{0},{1}", entry.Key, entry.Value);
  757. }
  758. button_Generate.Text = "转换中";
  759. //保存为Excel文件
  760. string importExcelName = "FOQC成机参数检验标准_Temple4.xls";
  761. string exportExcelName = FilePath + Datenow + textBox_Model.Text + "_" + textBox_Client.Text + "_" + ((textBox_Remark.Text == string.Empty) ? "" : textBox_Remark.Text + "_") + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".xls";
  762. try
  763. {
  764. //导入文件
  765. IWorkbook workbook = WorkbookFactory.Create(importExcelName);
  766. //获取第一个工作薄
  767. ISheet sheet = workbook.GetSheetAt(0);
  768. #region 开始按行写入单元格
  769. //第3行,文件信息
  770. IRow row = sheet.GetRow(2);
  771. row.GetCell(0).SetCellValue("文件信息 File Info:" + textBox_Model.Text + "_" + textBox_Client.Text + "_" + ((textBox_Remark.Text == string.Empty) ? "" : textBox_Remark.Text + "_") + DateTime.Now.ToString("yyyy-MM-dd-HHmmss"));
  772. //第5行,第2列型号,第10列SPORT加速
  773. row = sheet.GetRow(4);
  774. row.GetCell(1).SetCellValue(textBox_Model.Text);
  775. row.GetCell(9).SetCellValue(textBox_SPORT_Acc.Text);
  776. //第6行,第2列SN,第10列TURBO增益
  777. row = sheet.GetRow(5);
  778. row.GetCell(1).SetCellValue("Same as marking");
  779. row.GetCell(9).SetCellValue(textBox_TURBO_Gain.Text);
  780. //第7行,第2列硬件板号,第10列TURBO加速
  781. row = sheet.GetRow(6);
  782. row.GetCell(1).SetCellValue(textBox_HW_Version.Text);
  783. row.GetCell(9).SetCellValue(textBox_TURBO_Acc.Text);
  784. //第8行,第2列主控软件版本,第10列SMART增益
  785. row = sheet.GetRow(7);
  786. row.GetCell(1).SetCellValue(textBox_FW_Version.Text);
  787. row.GetCell(9).SetCellValue(textBox_SMART_Gain.Text);
  788. //第9行,第2列TE软件版本,第10列SMART加速
  789. row = sheet.GetRow(8);
  790. row.GetCell(1).SetCellValue(textBox_TE_FW_Version.Text);
  791. row.GetCell(9).SetCellValue(textBox_SMART_Acc.Text);
  792. //第10行,第2列BOOT版本,第10列额定功率
  793. row = sheet.GetRow(9);
  794. row.GetCell(1).SetCellValue(comboBox_Baudrate.SelectedIndex == 0 ? "V1.2.2 125K" : "V2.0.0 250K");
  795. row.GetCell(9).SetCellValue(textBox_RatePower.Text + " W");
  796. //第11行,第2列静态电压,第10列空载转速
  797. row = sheet.GetRow(10);
  798. row.GetCell(1).SetCellValue(textBox_Rate_Vol.Text + " ± 1 V");
  799. row.GetCell(9).SetCellValue(textBox_RateSpeed.Text + " rpm");
  800. //第12行,第2列静态电流,第10列额定电压
  801. row = sheet.GetRow(11);
  802. row.GetCell(1).SetCellValue("≤ 0.050 A");
  803. row.GetCell(9).SetCellValue(textBox_Rate_Vol.Text + " V");
  804. //第13行,第2列指拨模式,第10列速度信号个数
  805. row = sheet.GetRow(12);
  806. row.GetCell(1).SetCellValue(comboBox_GasMode.Text == "不支持" ? "不支持 No" : "支持 Yes " + comboBox_GasMode.Text + " " + comboBox_GasPowerLimit.Text + " " + comboBox_GasModeStart.Text + " " + textBox_GasSpeedLimit.Text + "km/h");
  807. row.GetCell(9).SetCellValue(textBox_SpeedSensor.Text);
  808. //第14行,第2列启动模式,第10列踏频启动信号个数
  809. row = sheet.GetRow(13);
  810. row.GetCell(1).SetCellValue(comboBox_StartMode.Text == "柔和" ? "柔和 Comfort" : comboBox_StartMode.Text == "正常" ? "正常 Normal" : "强劲 Dynamic");
  811. row.GetCell(9).SetCellValue(textBox_CadenceStart.Text);
  812. //第15行,第2列停机时间,第10列车速信号来源
  813. row = sheet.GetRow(14);
  814. row.GetCell(1).SetCellValue(textBox_StopTime.Text + " ms");
  815. row.GetCell(9).SetCellValue(comboBox_SpeedSensor.Text == "传感器" ? "传感器 Sensor" : comboBox_SpeedSensor.Text == "踏频" ? "踏频 Cadence" : "通信 CAN");
  816. //第16行,第2列限速,第10列轮胎周长微调
  817. row = sheet.GetRow(15);
  818. row.GetCell(1).SetCellValue(textBox_SpeedLimit.Text + " km/h");
  819. row.GetCell(9).SetCellValue(textBox_WheelSizeAdj.Text + " cm");
  820. //第17行,第2列下降速度,第10列推行转速
  821. row = sheet.GetRow(16);
  822. row.GetCell(1).SetCellValue("Level " + textBox_Dec.Text);
  823. row.GetCell(9).SetCellValue(textBox_WalkSpeed.Text + " rpm");
  824. //第18行,第2列前齿,第10列俯仰角零偏
  825. row = sheet.GetRow(17);
  826. row.GetCell(1).SetCellValue(textBox_T_Front.Text + " T");
  827. row.GetCell(9).SetCellValue(textBox_Angle_P.Text + " °");
  828. //第19行,第2列后齿,第10列横滚角零偏
  829. row = sheet.GetRow(18);
  830. row.GetCell(1).SetCellValue(textBox_T_Tail.Text + " T");
  831. row.GetCell(9).SetCellValue(textBox_Angle_R.Text + " °");
  832. //第20行,第2列限流,第10列姿态传感器
  833. row = sheet.GetRow(19);
  834. row.GetCell(1).SetCellValue(textBox_MaxCurrent.Text + " A");
  835. row.GetCell(9).SetCellValue(comboBox_AstSensor.Text == "不支持" ? "不支持 No" : "支持 Yes");
  836. //第21行,第2列温度预警,第10列尾灯模式
  837. row = sheet.GetRow(20);
  838. row.GetCell(1).SetCellValue(textBox_NTC_Alarm.Text + " ℃");
  839. row.GetCell(9).SetCellValue(comboBox_LightMode.Text.Replace("模式", "Mode"));
  840. //第22行,第2列温度保护,第10列前灯电压
  841. row = sheet.GetRow(21);
  842. row.GetCell(1).SetCellValue(textBox_NTC_Ptotect.Text + " ℃");
  843. row.GetCell(9).SetCellValue(comboBox_HeadLightVol.Text.Contains("随电池") ? comboBox_HeadLightVol.Text + " " + textBox_Rate_Vol.Text + " V" : comboBox_HeadLightVol.Text.Contains("硬件") ? "硬件配置 By HW" : comboBox_HeadLightVol.Text);
  844. //第23行,第2列码表,第10列后灯电压
  845. row = sheet.GetRow(22);
  846. row.GetCell(1).SetCellValue(comboBox_NoPBU.Text == "有" ? "有 Yes" : "无 No");
  847. row.GetCell(9).SetCellValue(comboBox_TailLightVol.Text.Contains("随电池") ? comboBox_TailLightVol.Text + " " + textBox_Rate_Vol.Text + " V" : comboBox_TailLightVol.Text.Contains("硬件") ? "硬件配置 By HW" : comboBox_TailLightVol.Text);
  848. //第24行,第2列轮胎周长,第10列启动值
  849. row = sheet.GetRow(23);
  850. row.GetCell(1).SetCellValue(textBox_WheelSize.Text + " cm");
  851. row.GetCell(9).SetCellValue(textBox_Start_Min.Text + " - " + textBox_Start_Max.Text);
  852. //第25行,第2列电机系列,第10列校正系数1
  853. row = sheet.GetRow(24);
  854. row.GetCell(1).SetCellValue(textBox_Serial.Text);
  855. row.GetCell(9).SetCellValue(textBox_K_Min.Text + " - " + textBox_K_Max.Text);
  856. //第26行,第2列低压保护,第10列校正系数2
  857. row = sheet.GetRow(25);
  858. row.GetCell(1).SetCellValue(textBox_UV_Protect.Text + " mV");
  859. if ((textBox_Model.Text.Contains("PG")) || (textBox_Model.Text.Contains("PS")) || (textBox_Model.Text.Contains("J01")))
  860. row.GetCell(9).SetCellValue(textBox_K_Min.Text + " - " + textBox_K_Max.Text);
  861. else
  862. row.GetCell(9).SetCellValue("无此项目 None");
  863. //第27行,第2列推行限速,第10列校正系数3
  864. row = sheet.GetRow(26);
  865. row.GetCell(1).SetCellValue(textBox_Walk_SpeedLimit.Text + " km/h");
  866. if ((textBox_Model.Text.Contains("PG")) || (textBox_Model.Text.Contains("PS")) || (textBox_Model.Text.Contains("J01")))
  867. row.GetCell(9).SetCellValue(textBox_K_Min.Text + " - " + textBox_K_Max.Text);
  868. else
  869. row.GetCell(9).SetCellValue("无此项目 None");
  870. //第28行,第2列ECO增益,第10列零点值1
  871. row = sheet.GetRow(27);
  872. row.GetCell(1).SetCellValue(textBox_ECO_Gain.Text);
  873. row.GetCell(9).SetCellValue(textBox_Zero_Min.Text + " - " + textBox_Zero_Max.Text);
  874. //第29行,第2列ECO加速,第10列零点值2
  875. row = sheet.GetRow(28);
  876. row.GetCell(1).SetCellValue(textBox_ECO_Acc.Text);
  877. if ((textBox_Model.Text.Contains("PG")) || (textBox_Model.Text.Contains("PS")) || (textBox_Model.Text.Contains("J01")))
  878. row.GetCell(9).SetCellValue(textBox_Zero_Min.Text + " - " + textBox_Zero_Max.Text);
  879. else
  880. row.GetCell(9).SetCellValue("无此项目 None");
  881. //第30行,第2列NORM增益,第10列零点值3
  882. row = sheet.GetRow(29);
  883. row.GetCell(1).SetCellValue(textBox_NORM_Gain.Text);
  884. if ((textBox_Model.Text.Contains("PG")) || (textBox_Model.Text.Contains("PS")) || (textBox_Model.Text.Contains("J01")))
  885. row.GetCell(9).SetCellValue(textBox_Zero_Min.Text + " - " + textBox_Zero_Max.Text);
  886. else
  887. row.GetCell(9).SetCellValue("无此项目 None");
  888. //第31行,第2列NORM加速,第10列骑行历史
  889. row = sheet.GetRow(30);
  890. row.GetCell(1).SetCellValue(textBox_NORM_Acc.Text);
  891. row.GetCell(9).SetCellValue("0 km / 0 min");
  892. //第32行,第2列SPORT增益,第10列故障码
  893. row = sheet.GetRow(31);
  894. row.GetCell(1).SetCellValue(textBox_SPORT_Gain.Text);
  895. row.GetCell(9).SetCellValue("无故障记录 None");
  896. //第33行,第2列尾灯脉宽,第10列尾灯周期
  897. row = sheet.GetRow(32);
  898. row.GetCell(1).SetCellValue(textBox_LightPluse.Text + "\n" + ((float)Convert.ToDouble(textBox_LightPluse.Text) / 15000f).ToString("0.000") + " s");
  899. row.GetCell(9).SetCellValue(textBox_LightPeriod.Text + "\n" + ((float)Convert.ToDouble(textBox_LightPeriod.Text) / 15000f).ToString("0.000") + " s");
  900. //第34行,第2列超速报警阈值,第11列限速起始偏移
  901. row = sheet.GetRow(33);
  902. row.GetCell(1).SetCellValue(textBox_AlarmSpeed.Text + " km/h");
  903. row.GetCell(9).SetCellValue(textBox_LimitSpeedStart.Text + " km/h");
  904. //第35行,第2列限速结束偏移
  905. row = sheet.GetRow(34);
  906. row.GetCell(1).SetCellValue(textBox_LimitSpeedStop.Text + " km/h");
  907. #endregion
  908. using (FileStream file = File.OpenWrite(exportExcelName))
  909. {
  910. workbook.Write(file);
  911. workbook.Close();
  912. }
  913. }
  914. catch (Exception ex)
  915. {
  916. throw (ex);
  917. }
  918. //文件转换为pdf格式保存
  919. string exportPdfName = FilePath + Datenow + textBox_Model.Text + "_" + textBox_Client.Text + "_" + ((textBox_Remark.Text == string.Empty) ? "" : textBox_Remark.Text + "_") + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".pdf";
  920. Workbook workbook_1 = new Workbook();//创建Workbook类的实例
  921. workbook_1.LoadFromFile(exportExcelName);//加载Excel工作簿
  922. workbook_1.SaveToFile(exportPdfName, FileFormat.PDF);//将整个工作薄保存为PDF
  923. MessageBox.Show("参数已生成,进入文件管理页面查看!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  924. button_Generate.Text = "上传中";
  925. //发送文件到服务器
  926. if (StartForm.myFtp.IsNetConnected == true)
  927. {
  928. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  929. int okCnt = 0;
  930. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/cfg/", DateNow) == false)
  931. {
  932. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
  933. }
  934. //上传配置文件
  935. bool result = StartForm.myFtp.UploadFile(fileName, StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
  936. if (result == true)
  937. {
  938. okCnt++;
  939. //MessageBox.Show("配置文件上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  940. }
  941. //上传配置清单excel
  942. result = StartForm.myFtp.UploadFile(exportExcelName, StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
  943. if (result == true)
  944. {
  945. okCnt++;
  946. //MessageBox.Show("配置检验清单上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  947. }
  948. //上传配置清单pdf
  949. result = StartForm.myFtp.UploadFile(exportPdfName, StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
  950. if (result == true)
  951. {
  952. okCnt++;
  953. //MessageBox.Show("配置检验清单上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  954. }
  955. if (okCnt >= 3)
  956. {
  957. MessageBox.Show("配置检验文件上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  958. }
  959. else
  960. {
  961. MessageBox.Show("配置检验文件上传服务器失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  962. }
  963. }
  964. button_Generate.Text = "生成";
  965. button_Generate.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
  966. button_Generate.Enabled = true;
  967. }
  968. private void button_keyboard_Click(object sender, EventArgs e)
  969. {
  970. System.Diagnostics.Process.Start("osk.exe");
  971. }
  972. //输入型号时自动更新关键参数
  973. private void textBox_Model_TextChanged(object sender, EventArgs e)
  974. {
  975. if (textBox_Model.Text.Contains("J01"))
  976. {
  977. textBox_Serial.Text = "1";//系列号
  978. textBox_MaxCurrent.Text = "13";//限流
  979. textBox_RatePower.Text = "250";//额定功率
  980. textBox_RateSpeed.Text = "1200";//额定转速
  981. textBox_Rate_Vol.Text = "36";//额定电压
  982. textBox_NC_Current.Text = "800";//空载电流
  983. textBox_Zero_Min.Text = "100";//零偏下限
  984. textBox_Zero_Max.Text = "2000";//零偏上限
  985. textBox_K_Min.Text = "0.40";//传感器标定值下限
  986. textBox_K_Max.Text = "1.20";//传感器标定值下限
  987. textBox_Start_Min.Text = "280";//启动值下限
  988. textBox_Start_Max.Text = "500";//启动值上限
  989. textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
  990. }
  991. else if (textBox_Model.Text.Contains("VL"))
  992. {
  993. textBox_Serial.Text = "1";//系列号
  994. textBox_MaxCurrent.Text = "13";//限流
  995. textBox_RatePower.Text = "250";//额定功率
  996. textBox_RateSpeed.Text = "1200";//额定转速
  997. textBox_Rate_Vol.Text = "36";//额定电压
  998. textBox_NC_Current.Text = "800";//空载电流
  999. textBox_Zero_Min.Text = "200";//零偏下限
  1000. textBox_Zero_Max.Text = "1800";//零偏上限
  1001. textBox_K_Min.Text = "0.25";//传感器标定值下限
  1002. textBox_K_Max.Text = "0.75";//传感器标定值下限
  1003. textBox_Start_Min.Text = "350";//启动值下限
  1004. textBox_Start_Max.Text = "750";//启动值上限
  1005. if (textBox_Model.Text.Contains("03") || textBox_Model.Text.Contains("13"))
  1006. {
  1007. textBox_GasSpeedTh.Text = "200";
  1008. }
  1009. else
  1010. {
  1011. textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
  1012. }
  1013. }
  1014. else if (textBox_Model.Text.Contains("VS"))
  1015. {
  1016. textBox_Serial.Text = "2";//系列号
  1017. textBox_MaxCurrent.Text = "15";//限流
  1018. textBox_RatePower.Text = "250";//额定功率
  1019. textBox_RateSpeed.Text = "1200";//额定转速
  1020. textBox_Rate_Vol.Text = "36";//额定电压
  1021. textBox_NC_Current.Text = "800";//空载电流
  1022. textBox_Zero_Min.Text = "200";//零偏下限
  1023. textBox_Zero_Max.Text = "1800";//零偏上限
  1024. textBox_K_Min.Text = "0.25";//传感器标定值下限
  1025. textBox_K_Max.Text = "0.75";//传感器标定值下限
  1026. textBox_Start_Min.Text = "350";//启动值下限
  1027. textBox_Start_Max.Text = "750";//启动值上限
  1028. if (textBox_Model.Text.Contains("03") || textBox_Model.Text.Contains("13"))
  1029. {
  1030. textBox_GasSpeedTh.Text = "200";
  1031. }
  1032. else
  1033. {
  1034. textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
  1035. }
  1036. }
  1037. else if (textBox_Model.Text.Contains("VR"))
  1038. {
  1039. textBox_Serial.Text = "2";//系列号
  1040. textBox_MaxCurrent.Text = "15";//限流
  1041. textBox_RatePower.Text = "250";//额定功率
  1042. textBox_RateSpeed.Text = "1200";//额定转速
  1043. textBox_Rate_Vol.Text = "36";//额定电压
  1044. textBox_NC_Current.Text = "800";//空载电流
  1045. textBox_Zero_Min.Text = "200";//零偏下限
  1046. textBox_Zero_Max.Text = "1800";//零偏上限
  1047. textBox_K_Min.Text = "0.25";//传感器标定值下限
  1048. textBox_K_Max.Text = "0.75";//传感器标定值下限
  1049. textBox_Start_Min.Text = "350";//启动值下限
  1050. textBox_Start_Max.Text = "750";//启动值上限
  1051. textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
  1052. }
  1053. else if (textBox_Model.Text.Contains("PG"))
  1054. {
  1055. textBox_Serial.Text = "3";//系列号
  1056. textBox_MaxCurrent.Text = "17";//限流
  1057. textBox_RatePower.Text = "250";//额定功率
  1058. textBox_RateSpeed.Text = "1550";//额定转速
  1059. textBox_Rate_Vol.Text = "36";//额定电压
  1060. textBox_NC_Current.Text = "1000";//空载电流
  1061. textBox_Zero_Min.Text = "100";//零偏下限
  1062. textBox_Zero_Max.Text = "2000";//零偏上限
  1063. textBox_K_Min.Text = "0.25";//传感器标定值下限
  1064. textBox_K_Max.Text = "1.20";//传感器标定值下限
  1065. textBox_Start_Min.Text = "280";//启动值下限
  1066. textBox_Start_Max.Text = "500";//启动值上限
  1067. textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
  1068. }
  1069. else if (textBox_Model.Text.Contains("PS"))
  1070. {
  1071. textBox_Serial.Text = "4";//系列号
  1072. textBox_MaxCurrent.Text = "17";//限流
  1073. textBox_RatePower.Text = "500";//额定功率
  1074. textBox_RateSpeed.Text = "1650";//额定转速
  1075. textBox_Rate_Vol.Text = "48";//额定电压
  1076. textBox_NC_Current.Text = "1000";//空载电流
  1077. textBox_Zero_Min.Text = "100";//零偏下限
  1078. textBox_Zero_Max.Text = "2000";//零偏上限
  1079. textBox_K_Min.Text = "0.25";//传感器标定值下限
  1080. textBox_K_Max.Text = "1.20";//传感器标定值下限
  1081. textBox_Start_Min.Text = "280";//启动值下限
  1082. textBox_Start_Max.Text = "500";//启动值上限
  1083. textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
  1084. }
  1085. else
  1086. {
  1087. textBox_Serial.Text = "";//系列号
  1088. textBox_MaxCurrent.Text = "";//限流
  1089. textBox_RatePower.Text = "";//额定功率
  1090. textBox_RateSpeed.Text = "";//额定转速
  1091. textBox_Rate_Vol.Text = "";//额定电压
  1092. textBox_NC_Current.Text = "";//空载电流
  1093. textBox_Zero_Min.Text = "";//零偏下限
  1094. textBox_Zero_Max.Text = "";//零偏上限
  1095. textBox_K_Min.Text = "";//传感器标定值下限
  1096. textBox_K_Max.Text = "";//传感器标定值下限
  1097. textBox_Start_Min.Text = "";//启动值下限
  1098. textBox_Start_Max.Text = "";//启动值上限
  1099. textBox_GasSpeedTh.Text = "";
  1100. }
  1101. }
  1102. //输入限速时更改指拨转速阈值
  1103. private void textBox_SpeedLimit_TextChanged(object sender, EventArgs e)
  1104. {
  1105. if (textBox_SpeedLimit.Text == "")
  1106. return;
  1107. if ((!textBox_Model.Text.Contains("6503")) && (!textBox_Model.Text.Contains("6513")) && (!textBox_Model.Text.Contains("7503")) && (!textBox_Model.Text.Contains("7513")))
  1108. {
  1109. textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
  1110. }
  1111. }
  1112. //更改尾灯模式时更改尾灯脉宽和周期
  1113. private void comboBox_LightMode_SelectedIndexChanged(object sender, EventArgs e)
  1114. {
  1115. if (comboBox_LightMode.SelectedIndex == 0) // 模式1,开灯低亮,刹车高亮
  1116. {
  1117. textBox_AlarmSpeed.Text = "15.0";
  1118. textBox_LightPluse.Text = "75";
  1119. textBox_LightPeriod.Text = "150";
  1120. }
  1121. else if (comboBox_LightMode.SelectedIndex == 5) // 模式6,超速报警
  1122. {
  1123. textBox_AlarmSpeed.Text = "15.0";
  1124. textBox_LightPluse.Text = "7500";
  1125. textBox_LightPeriod.Text = "45000";
  1126. }
  1127. }
  1128. //指拨转速阈值修改
  1129. private void textBox_GasSpeedTh_TextChanged(object sender, EventArgs e)
  1130. {
  1131. UInt32 DataTemp = 0;
  1132. if (textBox_GasSpeedTh.Text == "")
  1133. {
  1134. return;
  1135. }
  1136. DataTemp = Convert.ToUInt32(textBox_GasSpeedTh.Text);
  1137. if (textBox_Model.Text.Contains("VL"))
  1138. {
  1139. if (DataTemp >= 1200)
  1140. {
  1141. textBox_GasSpeedTh.Text = "1200";
  1142. }
  1143. }
  1144. else if (textBox_Model.Text.Contains("VS"))
  1145. {
  1146. if (DataTemp >= 1200)
  1147. {
  1148. textBox_GasSpeedTh.Text = "1200";
  1149. }
  1150. }
  1151. else if (textBox_Model.Text.Contains("PG"))
  1152. {
  1153. if (DataTemp >= 1400)
  1154. {
  1155. textBox_GasSpeedTh.Text = "1400";
  1156. }
  1157. }
  1158. else if (textBox_Model.Text.Contains("PS"))
  1159. {
  1160. if (DataTemp >= 1600)
  1161. {
  1162. textBox_GasSpeedTh.Text = "1600";
  1163. }
  1164. }
  1165. }
  1166. /// <summary>
  1167. /// 指拨模式修改时,自动调整限功率方式和限速值
  1168. /// </summary>
  1169. /// <param name="sender"></param>
  1170. /// <param name="e"></param>
  1171. private void comboBox_GasMode_SelectedIndexChanged(object sender, EventArgs e)
  1172. {
  1173. if (comboBox_GasMode.SelectedIndex == 0)//不支持
  1174. {
  1175. comboBox_GasPowerLimit.SelectedIndex = 0;
  1176. textBox_GasSpeedLimit.Text = "无效";
  1177. comboBox_GasModeStart.SelectedIndex = 0;
  1178. }
  1179. else if (comboBox_GasMode.SelectedIndex == 3)//推行模式
  1180. {
  1181. comboBox_GasPowerLimit.SelectedIndex = 0;
  1182. comboBox_GasModeStart.SelectedIndex = 0;
  1183. textBox_GasSpeedLimit.Text = "6";
  1184. }
  1185. else//速度模式或力矩模式
  1186. {
  1187. comboBox_GasPowerLimit.SelectedIndex = 1;
  1188. comboBox_GasModeStart.SelectedIndex = 1;
  1189. textBox_GasSpeedLimit.Text = textBox_SpeedLimit.Text;
  1190. }
  1191. }
  1192. }
  1193. }