ExportForm.cs 66 KB

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