ExportForm.cs 56 KB

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