ExportForm.cs 58 KB

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