123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml.Serialization;
- using System.Text.RegularExpressions;
- using System.Net;
- using System.Reflection;
- using NPOI;
- using NPOI.SS.UserModel;
- using NPOI.HSSF.UserModel;
- using Spire.Xls;
- using Workbook = Spire.Xls.Workbook;
- using NPOI.POIFS.FileSystem;
- namespace MOTINOVA_Motor_Factory_Set
- {
- public partial class ExportForm : Form
- {
- //参数按照字典类型存储
- Dictionary<string, UInt16> Params1 = new Dictionary<string, UInt16>();
- Dictionary<string, UInt16> Params2 = new Dictionary<string, UInt16>();
- Dictionary<string, UInt16> MotorParam = new Dictionary<string, UInt16>();
- Dictionary<string, string> Otherinfo = new Dictionary<string, string>();
- Dictionary<string, UInt16> TestThData = new Dictionary<string, ushort>();
- Dictionary<string, string> MarkInfo = new Dictionary<string, string>();
- //文件路径
- public string FilePath = "";
- public ExportForm()
- {
- InitializeComponent();
- }
- private void ExportForm_Load(object sender, EventArgs e)
- {
-
- }
- private void SetDefault()
- {
- //参数1
- Params1.Clear();
- Params1.Add("启动模式", 2);
- Params1.Add("停机时间", 100);
- Params1.Add("限速值", 25);
- Params1.Add("下降速度", 3);
- Params1.Add("前飞", 14);
- Params1.Add("后飞", 9);
- Params1.Add("限流", 15);
- Params1.Add("温度预警", 95);
- Params1.Add("温度保护", 125);
- Params1.Add("码表", 0x55);//有,不支持无码表
- Params1.Add("轮胎周长", 219);//cm
- Params1.Add("系列号", 0);
- Params1.Add("ECO增益", 100);//放大100倍
- Params1.Add("ECO加速", 100);
- Params1.Add("NORM增益", 100);
- Params1.Add("NORM加速", 100);
- Params1.Add("SPORT增益", 100);
- Params1.Add("SPORT加速", 100);
- Params1.Add("TURBO增益", 100);
- Params1.Add("TURBO加速", 100);
- Params1.Add("SMART增益", 100);
- Params1.Add("SMART加速", 100);
- Params1.Add("车速级数", 1);
- Params1.Add("踏频启动", 2);
- Params1.Add("指拨模式", 0x55);//不支持
- Params1.Add("速度信号来源", 0x55);//传感器
- Params1.Add("周长微调", 0);
- Params1.Add("低压保护", 3000);//mV
- Params1.Add("推行限速", 60);//放大10倍
- Params1.Add("推行转速", 135);
- //参数2
- Params2.Clear();
- Params2.Add("姿态传感器", 0x55);//不支持
- Params2.Add("俯仰角零偏", 0);
- Params2.Add("横滚角零偏", 0);
- Params2.Add("尾灯模式", 2);
- Params2.Add("前灯电压", 12);
- Params2.Add("尾灯电压", 12);
- Params2.Add("报警阈值", 150);//放大10倍
- Params2.Add("尾灯脉宽", 70);
- Params2.Add("尾灯周期", 150);
- Params2.Add("起始限速", 0);
- Params2.Add("结束限速", 0);
- Params2.Add("限速微调", 0);
- Params2.Add("ECO最大电流增益", 100);
- Params2.Add("ECO最大力矩增益", 100);
- Params2.Add("NORM最大电流增益", 100);
- Params2.Add("NORM最大力矩增益", 100);
- Params2.Add("SPORT最大电流增益", 100);
- Params2.Add("SPORT最大力矩增益", 100);
- Params2.Add("TURBO最大电流增益", 100);
- Params2.Add("TURBO最大力矩增益", 100);
- Params2.Add("SMART最大电流增益", 100);
- Params2.Add("SMART最大力矩增益", 100);
- //马达参数
- MotorParam.Clear();
- MotorParam.Add("额定功率", 250);
- MotorParam.Add("空载转速", 1200);
- MotorParam.Add("定子电阻", 10);
- MotorParam.Add("定子Lq", 10);
- MotorParam.Add("定子Ld", 10);
- MotorParam.Add("反电动势", 36000);
- MotorParam.Add("额定电压", 36);
- //其它信息
- Otherinfo.Clear();
- Otherinfo.Add("生产商", "TTIUM");
- Otherinfo.Add("生产地", "Wuhan");
- Otherinfo.Add("生产日期", DateTime.Now.ToString("yyyyMMdd"));
- Otherinfo.Add("校验密钥", "AVONITOM");
- Otherinfo.Add("信息1", "");
- Otherinfo.Add("信息2", "");
- Otherinfo.Add("信息3", "");
- //测试阈值
- TestThData.Clear();
- TestThData.Add("空载电流", 1000);
- TestThData.Add("踏频", 120);
- TestThData.Add("车速", 150);
- TestThData.Add("指拨转速", 1225);
- TestThData.Add("零偏最小值", 100);
- TestThData.Add("零偏最大值", 1800);
- TestThData.Add("标定系数最小值", 25);
- TestThData.Add("标定系数最大值", 75);
- TestThData.Add("启动值最小值", 350);
- TestThData.Add("启动值最大值", 750);
- TestThData.Add("标定系数标准差", 250);
- //其它测试备注信息
- MarkInfo.Clear();
- MarkInfo.Add("PCBA版号", "");
- }
- private void ParamsDisplayUpdate()
- {
- //参数1
- comboBox_StartMode.SelectedIndex = Params1["启动模式"] - 1;
- textBox_StopTime.Text = Params1["停机时间"].ToString();
- textBox_SpeedLimit.Text = Params1["限速值"].ToString();
- textBox_Dec.Text = Params1["下降速度"].ToString();
- textBox_T_Front.Text = Params1["前飞"].ToString();
- textBox_T_Tail.Text = Params1["后飞"].ToString();
- textBox_MaxCurrent.Text = Params1["限流"].ToString();
- textBox_NTC_Alarm.Text = Params1["温度预警"].ToString();
- textBox_NTC_Ptotect.Text = Params1["温度保护"].ToString();
- if (Params1["码表"] == 0x55)
- {
- comboBox_NoPBU.SelectedIndex = 1;
- }
- else if (Params1["码表"] == 0xAA)
- {
- comboBox_NoPBU.SelectedIndex = 0;
- }
- textBox_WheelSize.Text = Params1["轮胎周长"].ToString();
- textBox_Serial.Text = Params1["系列号"].ToString();
- textBox_ECO_Gain.Text = ((float)(Params1["ECO增益"]) / 100.0f).ToString("#0.00");
- textBox_ECO_Acc.Text = ((float)(Params1["ECO加速"]) / 100.0f).ToString("#0.00");
- textBox_NORM_Gain.Text = ((float)(Params1["NORM增益"]) / 100.0f).ToString("#0.00");
- textBox_NORM_Acc.Text = ((float)(Params1["NORM加速"]) / 100.0f).ToString("#0.00");
- textBox_SPORT_Gain.Text = ((float)(Params1["SPORT增益"]) / 100.0f).ToString("#0.00");
- textBox_SPORT_Acc.Text = ((float)(Params1["SPORT加速"]) / 100.0f).ToString("#0.00");
- textBox_TURBO_Gain.Text = ((float)(Params1["TURBO增益"]) / 100.0f).ToString("#0.00");
- textBox_TURBO_Acc.Text = ((float)(Params1["TURBO加速"]) / 100.0f).ToString("#0.00");
- textBox_SMART_Gain.Text = ((float)(Params1["SMART增益"]) / 100.0f).ToString("#0.00");
- textBox_SMART_Acc.Text = ((float)(Params1["SMART加速"]) / 100.0f).ToString("#0.00");
- textBox_SpeedSensor.Text = Params1["车速级数"].ToString();
- textBox_CadenceStart.Text = Params1["踏频启动"].ToString();
- if (Params1["指拨模式"] == 0x55) //不支持
- {
- comboBox_GasMode.SelectedIndex = 0;
- comboBox_GasPowerLimit.SelectedIndex = 0;
- comboBox_GasModeStart.SelectedIndex = 0;
- textBox_GasSpeedLimit.Text = "无效";
- }
- else
- {
- //控制模式
- if ((Params1["指拨模式"] & 0x01) == 0x00) //速度模式
- {
- comboBox_GasMode.SelectedIndex = 1;
- }
- else //力矩模式
- {
- comboBox_GasMode.SelectedIndex = 2;
- }
- //功率限制方式
- if ((Params1["指拨模式"] & 0x02) == 0x02) //挡位限制功率
- {
- comboBox_GasPowerLimit.SelectedIndex = 1;
- }
- else //挡位不限制功率
- {
- comboBox_GasPowerLimit.SelectedIndex = 2;
- }
- //启动方式
- if ((Params1["指拨启动方式"] & 0x04) == 0x00) //零速
- {
- comboBox_GasPowerLimit.SelectedIndex = 1;
- }
- else //带速
- {
- comboBox_GasPowerLimit.SelectedIndex = 2;
- }
- //指拨限速
- if ((Params1["指拨模式"] >> 3) <= 5)
- textBox_GasSpeedLimit.Text = ((Params1["限速值"] + (Params1["指拨模式"] >> 3) + 31 - 0x15) & 0x1F).ToString();
- else
- textBox_GasSpeedLimit.Text = ((Params1["限速值"] + (Params1["指拨模式"] >> 3) - 0x15) & 0x1F).ToString();
- }
- if (Params1["速度信号来源"] == 0x55)
- {
- comboBox_SpeedSensor.SelectedIndex = 0;
- }
- else if (Params1["速度信号来源"] == 0xAA)
- {
- comboBox_SpeedSensor.SelectedIndex = 1;
- }
- else if (Params1["速度信号来源"] == 0xEE)
- {
- comboBox_SpeedSensor.SelectedIndex = 2;
- }
- textBox_WheelSizeAdj.Text = Params1["周长微调"].ToString();
- textBox_UV_Protect.Text = Params1["低压保护"].ToString();
- textBox_Walk_SpeedLimit.Text = ((float)(Params1["推行限速"]) / 10.0f).ToString("#0.0");
- textBox_WalkSpeed.Text = Params1["推行转速"].ToString();
- //参数2
- if (Params2["姿态传感器"] == 0x55)
- {
- comboBox_AstSensor.SelectedIndex = 0;
- }
- else if (Params1["姿态传感器"] == 0xAA)
- {
- comboBox_AstSensor.SelectedIndex = 1;
- }
- textBox_Angle_P.Text = ((float)(Params2["俯仰角零偏"]) / 10.0f).ToString("#0.0");
- textBox_Angle_R.Text = ((float)(Params2["横滚角零偏"]) / 10.0f).ToString("#0.0");
- comboBox_LightMode.SelectedIndex = Params2["尾灯模式"] - 1;
- if (Params2["前灯电压"] == 6)
- {
- comboBox_HeadLightVol.SelectedIndex = 0;
- }
- else if (Params2["前灯电压"] == 12)
- {
- comboBox_HeadLightVol.SelectedIndex = 1;
- }
- else if (Params2["前灯电压"] == 0xFF)
- {
- comboBox_HeadLightVol.SelectedIndex = 2;
- }
- else if (Params2["前灯电压"] == 0)
- {
- comboBox_HeadLightVol.SelectedIndex = 3;
- }
- if (Params2["尾灯电压"] == 6)
- {
- comboBox_TailLightVol.SelectedIndex = 0;
- }
- else if (Params2["尾灯电压"] == 12)
- {
- comboBox_TailLightVol.SelectedIndex = 1;
- }
- else if (Params2["尾灯电压"] == 0xFF)
- {
- comboBox_TailLightVol.SelectedIndex = 2;
- }
- else if (Params2["尾灯电压"] == 0)
- {
- comboBox_TailLightVol.SelectedIndex = 3;
- }
- textBox_AlarmSpeed.Text = ((float)(Params2["报警阈值"]) / 10.0f).ToString("#0.0");
- textBox_LightPluse.Text = Params2["尾灯脉宽"].ToString();
- textBox_LightPeriod.Text = Params2["尾灯周期"].ToString();
- textBox_LimitSpeedStart.Text = ((float)(Params2["起始限速"]) / 10.0f).ToString("#0.0");
- textBox_LimitSpeedStop.Text = ((float)(Params2["结束限速"]) / 10.0f).ToString("#0.0");
- //马达参数
- textBox_RatePower.Text = MotorParam["额定功率"].ToString();
- textBox_RateSpeed.Text = MotorParam["空载转速"].ToString();
- textBox_RotorR.Text = MotorParam["定子电阻"].ToString();
- textBox_Rotor_Lq.Text = MotorParam["定子Lq"].ToString();
- textBox_Rotor_Ld.Text = MotorParam["定子Ld"].ToString();
- textBox_E.Text = MotorParam["反电动势"].ToString();
- textBox_Rate_Vol.Text = MotorParam["额定电压"].ToString();
- //其它信息
- textBox_Mac.Text = Otherinfo["生产商"].ToString();
- textBox_Mac_Addr.Text = Otherinfo["生产地"].ToString();
- textBox_Mac_Date.Text = Otherinfo["生产日期"].ToString();
- textBox_Secrect.Text = Otherinfo["校验密钥"].ToString();
- textBox_Info1.Text = Otherinfo["信息1"].ToString();
- textBox_Info2.Text = Otherinfo["信息2"].ToString();
- textBox_Info3.Text = Otherinfo["信息3"].ToString();
-
- //测试阈值
- textBox_NC_Current.Text = TestThData["空载电流"].ToString();
- textBox_SpeedTh.Text = TestThData["车速"].ToString();
- textBox_CadenceTh.Text = TestThData["踏频"].ToString();
- textBox_GasSpeedTh.Text = TestThData["指拨转速"].ToString();
- textBox_Zero_Min.Text = TestThData["零偏最小值"].ToString();
- textBox_Zero_Max.Text = TestThData["零偏最大值"].ToString();
- textBox_K_Min.Text = ((float)(TestThData["标定系数最小值"]) / 100.0f).ToString("#0.00");
- textBox_K_Max.Text = ((float)(TestThData["标定系数最大值"]) / 100.0f).ToString("#0.00");
- textBox_Start_Min.Text = TestThData["启动值最小值"].ToString();
- textBox_Start_Max.Text = TestThData["启动值最大值"].ToString();
- textBox_K_Sqrd.Text= ((float)(TestThData["标定系数标准差"]) / 1000.0f).ToString("#0.000");
- //其它测试备注信息
- textBox_HW_Version.Text = MarkInfo["PCBA版号"];
- //TE版本信息
- textBox_TE_FW_Version.Text = "N_A";
- }
- private bool DisplaySetToParams()
- {
- try
- {
- //参数1
- Params1.Clear();
- if (comboBox_StartMode.Text == "柔和")
- {
- Params1.Add("启动模式", 1);
- }
- else if (comboBox_StartMode.Text == "正常")
- {
- Params1.Add("启动模式", 2);
- }
- else if (comboBox_StartMode.Text == "强劲")
- {
- Params1.Add("启动模式", 3);
- }
- else
- {
- MessageBox.Show("请检查启动模式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("停机时间", Convert.ToUInt16(textBox_StopTime.Text));
- if (Params1["停机时间"] < 50 || Params1["停机时间"] > 500)
- {
- MessageBox.Show("停机时间有效值:50~500 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("限速值", Convert.ToUInt16(textBox_SpeedLimit.Text));
- if (Params1["限速值"] < 5 || Params1["限速值"] > 120)
- {
- MessageBox.Show("限速值有效值:5~120 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("下降速度", Convert.ToUInt16(textBox_Dec.Text));
- if (Params1["下降速度"] < 1 || Params1["下降速度"] > 5)
- {
- MessageBox.Show("下降速度有效值:1~5 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("前飞", Convert.ToUInt16(textBox_T_Front.Text));
- if (Params1["前飞"] < 5 || Params1["前飞"] > 100)
- {
- MessageBox.Show("前飞有效值:5~100 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("后飞", Convert.ToUInt16(textBox_T_Tail.Text));
- if (Params1["后飞"] < 5 || Params1["后飞"] > 100)
- {
- MessageBox.Show("后飞有效值:5~100 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("限流", Convert.ToUInt16(textBox_MaxCurrent.Text));
- if (Params1["限流"] < 5 || Params1["限流"] > 25)
- {
- MessageBox.Show("限流有效值:5~25 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("温度预警", Convert.ToUInt16(textBox_NTC_Alarm.Text));
- Params1.Add("温度保护", Convert.ToUInt16(textBox_NTC_Ptotect.Text));
- if (comboBox_NoPBU.Text == "有")
- {
- Params1.Add("码表", 0x55);
- }
- else if (comboBox_NoPBU.Text == "无")
- {
- Params1.Add("码表", 0xAA);
- }
- else
- {
- MessageBox.Show("请检查无码表设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("轮胎周长", Convert.ToUInt16(textBox_WheelSize.Text));
- if (Params1["轮胎周长"] < 80 || Params1["轮胎周长"] > 250)
- {
- MessageBox.Show("轮胎周长有效值:80~250 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("系列号", Convert.ToUInt16(textBox_Serial.Text));
- if (Params1["系列号"] < 1 || Params1["系列号"] > 16)
- {
- MessageBox.Show("系列号有效值:1~16 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("ECO增益", Convert.ToUInt16(float.Parse(textBox_ECO_Gain.Text) * 100));//放大100倍
- Params1.Add("ECO加速", Convert.ToUInt16(float.Parse(textBox_ECO_Acc.Text) * 100));
- Params1.Add("NORM增益", Convert.ToUInt16(float.Parse(textBox_NORM_Gain.Text) * 100));
- Params1.Add("NORM加速", Convert.ToUInt16(float.Parse(textBox_NORM_Acc.Text) * 100));
- Params1.Add("SPORT增益", Convert.ToUInt16(float.Parse(textBox_SPORT_Gain.Text) * 100));
- Params1.Add("SPORT加速", Convert.ToUInt16(float.Parse(textBox_SPORT_Acc.Text) * 100));
- Params1.Add("TURBO增益", Convert.ToUInt16(float.Parse(textBox_TURBO_Gain.Text) * 100));
- Params1.Add("TURBO加速", Convert.ToUInt16(float.Parse(textBox_TURBO_Acc.Text) * 100));
- Params1.Add("SMART增益", Convert.ToUInt16(float.Parse(textBox_SMART_Gain.Text) * 100));
- Params1.Add("SMART加速", Convert.ToUInt16(float.Parse(textBox_SMART_Acc.Text) * 100));
- Params1.Add("车速级数", Convert.ToUInt16(textBox_SpeedSensor.Text));
- Params1.Add("踏频启动", Convert.ToUInt16(textBox_CadenceStart.Text));
- if (comboBox_GasMode.SelectedIndex == 0) //不支持
- {
- Params1.Add("指拨模式", 0x55);
- }
- else if(comboBox_GasMode.SelectedIndex == 3) //推行
- {
- Params1.Add("指拨模式", 0xF8);
- }
- else //支持
- {
- Byte GasModeTemp = 0;
- //控制模式
- if (comboBox_GasMode.SelectedIndex == 1) //支持,速度模式
- GasModeTemp &= 0xFE;
- else if (comboBox_GasMode.SelectedIndex == 2) //支持,力矩模式
- GasModeTemp |= 0x01;
- //挡位功率限制
- if (comboBox_GasPowerLimit.SelectedIndex == 1) //支持,限制
- GasModeTemp |= 0x02;
- else if (comboBox_GasPowerLimit.SelectedIndex == 2) //支持,不限制
- GasModeTemp &= 0xFD;
- else
- {
- MessageBox.Show("请检查指拨功率限制设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- //启动方式
- if (comboBox_GasModeStart.SelectedIndex == 1) //支持,零速启动
- GasModeTemp &= 0xFB;
- else if (comboBox_GasModeStart.SelectedIndex == 2) //支持,带速启动
- GasModeTemp |= 0x04;
- else
- {
- MessageBox.Show("请检查指拨启动方式设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- //限速
- if (Convert.ToByte(textBox_GasSpeedLimit.Text) - Convert.ToByte(textBox_SpeedLimit.Text) > 15) //不支持
- {
- MessageBox.Show("请检查指拨限速设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- else if (Convert.ToByte(textBox_SpeedLimit.Text) - Convert.ToByte(textBox_GasSpeedLimit.Text) > 15) //不支持
- {
- MessageBox.Show("请检查指拨限速设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- if (Convert.ToByte(textBox_GasSpeedLimit.Text) - Convert.ToByte(textBox_SpeedLimit.Text) >= 10)
- GasModeTemp |= (byte)((0x15 + Convert.ToByte(textBox_GasSpeedLimit.Text) - Convert.ToByte(textBox_SpeedLimit.Text) - 0x1F) << 3);
- else
- GasModeTemp |= (byte)((0x15 + Convert.ToByte(textBox_GasSpeedLimit.Text) - Convert.ToByte(textBox_SpeedLimit.Text)) << 3);
- Params1.Add("指拨模式", GasModeTemp);
- }
- if (comboBox_SpeedSensor.Text == "传感器")
- {
- Params1.Add("速度信号来源", 0x55);
- }
- else if (comboBox_SpeedSensor.Text == "踏频")
- {
- Params1.Add("速度信号来源", 0xAA);
- }
- else if (comboBox_SpeedSensor.Text == "通信")
- {
- Params1.Add("速度信号来源", 0xEE);
- }
- else
- {
- MessageBox.Show("请检查速度信号来源设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params1.Add("周长微调", Convert.ToUInt16((byte)(Convert.ToSByte(textBox_WheelSizeAdj.Text))));
- Params1.Add("低压保护", Convert.ToUInt16(textBox_UV_Protect.Text));//mV
- Params1.Add("推行限速", Convert.ToUInt16(float.Parse(textBox_Walk_SpeedLimit.Text) * 10));//放大10倍
- Params1.Add("推行转速", Convert.ToUInt16(textBox_WalkSpeed.Text));
- //参数2
- Params2.Clear();
- if (comboBox_AstSensor.Text == "不支持")
- {
- Params2.Add("姿态传感器", 0x55);
- }
- else if (comboBox_AstSensor.Text == "支持")
- {
- Params2.Add("姿态传感器", 0xAA);
- }
- else
- {
- MessageBox.Show("请检查姿态传感器设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- Params2.Add("俯仰角零偏", Convert.ToUInt16((UInt16)(float.Parse(textBox_Angle_P.Text) * 10)));
- Params2.Add("横滚角零偏", Convert.ToUInt16((UInt16)(float.Parse(textBox_Angle_R.Text) * 10)));
- if (comboBox_LightMode.Text == "模式 1")
- {
- Params2.Add("尾灯模式", 1);
- }
- else if(comboBox_LightMode.Text == "模式 2")
- {
- Params2.Add("尾灯模式", 2);
- }
- else if (comboBox_LightMode.Text == "模式 3")
- {
- Params2.Add("尾灯模式", 3);
- }
- else if (comboBox_LightMode.Text == "模式 4")
- {
- Params2.Add("尾灯模式", 4);
- }
- else if (comboBox_LightMode.Text == "模式 5")
- {
- Params2.Add("尾灯模式", 5);
- }
- else if (comboBox_LightMode.Text == "模式 6")
- {
- Params2.Add("尾灯模式", 6);
- }
- if (comboBox_HeadLightVol.Text == "6V")
- {
- Params2.Add("前灯电压", 6);
- }
- else if (comboBox_HeadLightVol.Text == "12V")
- {
- Params2.Add("前灯电压", 12);
- }
- else if (comboBox_HeadLightVol.Text == "随电池")
- {
- Params2.Add("前灯电压", 0xFF);
- }
- else if (comboBox_HeadLightVol.Text == "硬件配置")
- {
- Params2.Add("前灯电压", 0);
- }
- if (comboBox_TailLightVol.Text == "6V")
- {
- Params2.Add("尾灯电压", 6);
- }
- else if (comboBox_TailLightVol.Text == "12V")
- {
- Params2.Add("尾灯电压", 12);
- }
- else if (comboBox_TailLightVol.Text == "随电池")
- {
- Params2.Add("尾灯电压", 0xFF);
- }
- else if (comboBox_TailLightVol.Text == "硬件配置")
- {
- Params2.Add("尾灯电压", 0);
- }
- Params2.Add("报警阈值", Convert.ToUInt16(float.Parse(textBox_AlarmSpeed.Text) * 10));//放大10倍
- Params2.Add("尾灯脉宽", Convert.ToUInt16(textBox_LightPluse.Text));
- Params2.Add("尾灯周期", Convert.ToUInt16(textBox_LightPeriod.Text));
- Params2.Add("起始限速", Convert.ToUInt16((byte)(float.Parse(textBox_LimitSpeedStart.Text) * 10)));
- Params2.Add("结束限速", Convert.ToUInt16((byte)(float.Parse(textBox_LimitSpeedStop.Text) * 10)));
- Params2.Add("限速微调", 0);
- Params2.Add("ECO最大电流增益", 100);
- Params2.Add("ECO最大力矩增益", 100);
- Params2.Add("NORM最大电流增益", 100);
- Params2.Add("NORM最大力矩增益", 100);
- Params2.Add("SPORT最大电流增益", 100);
- Params2.Add("SPORT最大力矩增益", 100);
- Params2.Add("TURBO最大电流增益", 100);
- Params2.Add("TURBO最大力矩增益", 100);
- Params2.Add("SMART最大电流增益", 100);
- Params2.Add("SMART最大力矩增益", 100);
- //马达参数
- MotorParam.Clear();
- MotorParam.Add("额定功率", Convert.ToUInt16(textBox_RatePower.Text));
- MotorParam.Add("空载转速", Convert.ToUInt16(textBox_RateSpeed.Text));
- MotorParam.Add("定子电阻", Convert.ToUInt16(textBox_RotorR.Text));
- MotorParam.Add("定子Lq", Convert.ToUInt16(textBox_Rotor_Lq.Text));
- MotorParam.Add("定子Ld", Convert.ToUInt16(textBox_Rotor_Ld.Text));
- MotorParam.Add("反电动势", Convert.ToUInt16(textBox_E.Text));
- MotorParam.Add("额定电压", Convert.ToUInt16(textBox_Rate_Vol.Text));
- //其它信息
- Otherinfo.Clear();
- Otherinfo.Add("生产商", textBox_Mac.Text);
- Otherinfo.Add("生产地", textBox_Mac_Addr.Text);
- Otherinfo.Add("生产日期", textBox_Mac_Date.Text);
- Otherinfo.Add("校验密钥", textBox_Secrect.Text);
- Otherinfo.Add("信息1", textBox_Info1.Text);
- Otherinfo.Add("信息2", textBox_Info2.Text);
- Otherinfo.Add("信息3", textBox_Info3.Text);
- //测试阈值
- TestThData.Clear();
- TestThData.Add("空载电流", Convert.ToUInt16(textBox_NC_Current.Text));
- TestThData.Add("车速", Convert.ToUInt16(textBox_SpeedTh.Text));
- TestThData.Add("踏频", Convert.ToUInt16(textBox_CadenceTh.Text));
- TestThData.Add("指拨转速", Convert.ToUInt16(textBox_GasSpeedTh.Text));
- TestThData.Add("零偏最小值", Convert.ToUInt16(textBox_Zero_Min.Text));
- TestThData.Add("零偏最大值", Convert.ToUInt16(textBox_Zero_Max.Text));
- TestThData.Add("标定系数最小值", Convert.ToUInt16(float.Parse(textBox_K_Min.Text) * 100));
- TestThData.Add("标定系数最大值", Convert.ToUInt16(float.Parse(textBox_K_Max.Text) * 100));
- TestThData.Add("启动值最小值", Convert.ToUInt16(textBox_Start_Min.Text));
- TestThData.Add("启动值最大值", Convert.ToUInt16(textBox_Start_Max.Text));
- TestThData.Add("标定系数标准差", Convert.ToUInt16(float.Parse(textBox_K_Sqrd.Text) * 1000));
- //其它测试备注信息
- MarkInfo.Clear();
- if (textBox_HW_Version.Text == string.Empty)
- {
- MessageBox.Show("请输入PCBA版号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- else
- {
- MarkInfo.Add("PCBA版号", textBox_HW_Version.Text);
- }
- return true;
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- private void button_Default_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("确认恢复默认值?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
- {
- return;
- }
- SetDefault();
- ParamsDisplayUpdate();
- }
- private void button_Generate_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("确认提交?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
- {
- return;
- }
- //空间内容更新到字典
- if (DisplaySetToParams() == false)
- {
- MessageBox.Show("参数生成失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //保存为配置文件
- if (textBox_Model.Text == string.Empty) //判断型号是否填写
- {
- MessageBox.Show("请输入电机型号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (textBox_Client.Text == string.Empty) //判断订单编号是否填写
- {
- MessageBox.Show("请输入订单号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (textBox_HW_Version.Text == String.Empty) //判断PCBA板号是否填写
- {
- MessageBox.Show("请输入PCBA板号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (comboBox_Baudrate.SelectedIndex == -1)
- {
- MessageBox.Show("请设定波特率!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- 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}");
- if (Reg.IsMatch(textBox_FW_Version.Text) == false) //判断主控软件版本是否填写
- {
- MessageBox.Show("主控软件版本格式不正确,例如V1.0.0.0.0_20210101 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (textBox_TE_FW_Version.Text != "N_A")//兼容单MCU主控板,无TE时填写N_A
- {
- Reg = new Regex(@"[V][0-9].[0-9].[0-9]_20\d{6}"); //判断TE软件版本是否填写
- if (Reg.IsMatch(textBox_TE_FW_Version.Text) == false) //判断TE软件版本是否填写
- {
- MessageBox.Show("TE软件版本格式不正确,例如N_A或V1.0.0_20210101 !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- button_Generate.BackColor = Color.Red;
- button_Generate.Text = "生成中";
- button_Generate.Enabled = false;
- if (System.IO.Directory.Exists(FilePath) == false)
- System.IO.Directory.CreateDirectory(FilePath);
- string Datenow = DateTime.Now.ToString("yyyy-MM-dd") + "\\";
- if (System.IO.Directory.Exists(FilePath + Datenow) == false)
- System.IO.Directory.CreateDirectory(FilePath + Datenow);
- 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";
- using (StreamWriter file = new StreamWriter(fileName))
- {
- //用户参数1
- file.WriteLine("[{0}]", "用户参数1");
- foreach (var entry in Params1)
- if (entry.Key == "码表")
- file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "有" : entry.Value == 0xAA ? "无" : "无效");
- else if (entry.Key == "指拨模式")
- {
- string strTemp = "";
- if (entry.Value == 0x55)
- strTemp += "不支持";
- else if(entry.Value == 0xF8)
- strTemp += "支持 推行模式";
- else
- {
- strTemp += "支持";
- //控制模式
- if((entry.Value & 0x01) == 0x00) //速度模式
- strTemp += " 速度模式";
- else
- strTemp += " 力矩模式";
- //功率限制方式
- if ((entry.Value & 0x02) == 0x00) //按挡位不限制
- strTemp += " 挡位不限制功率";
- else
- strTemp += " 挡位限制功率";
- //启动方式
- if ((entry.Value & 0x04) == 0x00) //零速启动
- strTemp += " 零速启动";
- else
- strTemp += " 带速启动";
- //限速
- strTemp += " 限速:" + textBox_GasSpeedLimit.Text + "km/h";
- }
- file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, strTemp);
- }
- else if (entry.Key == "速度信号来源")
- file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "传感器" : entry.Value == 0xAA ? "踏频" : entry.Value == 0xEE ? "通信" : "无效");
- else
- file.WriteLine("{0},{1}", entry.Key, entry.Value);
- //用户参数2
- file.WriteLine("");
- file.WriteLine("[{0}]", "用户参数2");
- foreach (var entry in Params2)
- if (entry.Key == "姿态传感器")
- file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0x55 ? "不支持" : entry.Value == 0xAA ? "支持" : "无效");
- else if (entry.Key == "前灯电压")
- file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0xFF ? "随电池" : entry.Value == 0 ? "硬件配置" : entry.Value + "V");
- else if (entry.Key == "尾灯电压")
- file.WriteLine("{0},{1},{2}", entry.Key, entry.Value, entry.Value == 0xFF ? "随电池" : entry.Value == 0 ? "硬件配置" : entry.Value + "V");
- else
- file.WriteLine("{0},{1}", entry.Key, entry.Value);
- //马达参数
- file.WriteLine("");
- file.WriteLine("[{0}]", "马达参数");
- foreach (var entry in MotorParam)
- file.WriteLine("{0},{1}", entry.Key, entry.Value);
- //其它信息
- file.WriteLine("");
- file.WriteLine("[{0}]", "其它信息");
- foreach (var entry in Otherinfo)
- file.WriteLine("{0},{1}", entry.Key, entry.Value);
- //测试阈值
- file.WriteLine("");
- file.WriteLine("[{0}]", "测试阈值");
- foreach (var entry in TestThData)
- file.WriteLine("{0},{1}", entry.Key, entry.Value);
- //其它测试备注信息
- file.WriteLine("");
- file.WriteLine("[{0}]", "其它测试备注信息");
- foreach (var entry in MarkInfo)
- file.WriteLine("{0},{1}", entry.Key, entry.Value);
- }
- button_Generate.Text = "转换中";
- //保存为Excel文件
- string importExcelName = "FOQC成机参数检验标准_Temple4.xls";
- 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";
- try
- {
-
- //导入文件
- IWorkbook workbook = WorkbookFactory.Create(importExcelName);
- //获取第一个工作薄
- ISheet sheet = workbook.GetSheetAt(0);
- #region 开始按行写入单元格
- //第3行,文件信息
- IRow row = sheet.GetRow(2);
- 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"));
- //第5行,第2列型号,第10列SPORT加速
- row = sheet.GetRow(4);
- row.GetCell(1).SetCellValue(textBox_Model.Text);
- row.GetCell(9).SetCellValue(textBox_SPORT_Acc.Text);
- //第6行,第2列SN,第10列TURBO增益
- row = sheet.GetRow(5);
- row.GetCell(1).SetCellValue("Same as marking");
- row.GetCell(9).SetCellValue(textBox_TURBO_Gain.Text);
- //第7行,第2列硬件板号,第10列TURBO加速
- row = sheet.GetRow(6);
- row.GetCell(1).SetCellValue(textBox_HW_Version.Text);
- row.GetCell(9).SetCellValue(textBox_TURBO_Acc.Text);
- //第8行,第2列主控软件版本,第10列SMART增益
- row = sheet.GetRow(7);
- row.GetCell(1).SetCellValue(textBox_FW_Version.Text);
- row.GetCell(9).SetCellValue(textBox_SMART_Gain.Text);
- //第9行,第2列TE软件版本,第10列SMART加速
- row = sheet.GetRow(8);
- row.GetCell(1).SetCellValue(textBox_TE_FW_Version.Text);
- row.GetCell(9).SetCellValue(textBox_SMART_Acc.Text);
- //第10行,第2列BOOT版本,第10列额定功率
- row = sheet.GetRow(9);
- row.GetCell(1).SetCellValue(comboBox_Baudrate.SelectedIndex == 0 ? "V1.2.2 125K" : "V2.0.0 250K");
- row.GetCell(9).SetCellValue(textBox_RatePower.Text + " W");
- //第11行,第2列静态电压,第10列空载转速
- row = sheet.GetRow(10);
- row.GetCell(1).SetCellValue(textBox_Rate_Vol.Text + " ± 1 V");
- row.GetCell(9).SetCellValue(textBox_RateSpeed.Text + " rpm");
- //第12行,第2列静态电流,第10列额定电压
- row = sheet.GetRow(11);
- row.GetCell(1).SetCellValue("≤ 0.050 A");
- row.GetCell(9).SetCellValue(textBox_Rate_Vol.Text + " V");
- //第13行,第2列指拨模式,第10列速度信号个数
- row = sheet.GetRow(12);
- row.GetCell(1).SetCellValue(comboBox_GasMode.Text == "不支持" ? "不支持 No" : "支持 Yes " + comboBox_GasMode.Text + " " + comboBox_GasPowerLimit.Text + " " + comboBox_GasModeStart.Text + " " + textBox_GasSpeedLimit.Text + "km/h");
- row.GetCell(9).SetCellValue(textBox_SpeedSensor.Text);
- //第14行,第2列启动模式,第10列踏频启动信号个数
- row = sheet.GetRow(13);
- row.GetCell(1).SetCellValue(comboBox_StartMode.Text == "柔和" ? "柔和 Comfort" : comboBox_StartMode.Text == "正常" ? "正常 Normal" : "强劲 Dynamic");
- row.GetCell(9).SetCellValue(textBox_CadenceStart.Text);
- //第15行,第2列停机时间,第10列车速信号来源
- row = sheet.GetRow(14);
- row.GetCell(1).SetCellValue(textBox_StopTime.Text + " ms");
- row.GetCell(9).SetCellValue(comboBox_SpeedSensor.Text == "传感器" ? "传感器 Sensor" : comboBox_SpeedSensor.Text == "踏频" ? "踏频 Cadence" : "通信 CAN");
- //第16行,第2列限速,第10列轮胎周长微调
- row = sheet.GetRow(15);
- row.GetCell(1).SetCellValue(textBox_SpeedLimit.Text + " km/h");
- row.GetCell(9).SetCellValue(textBox_WheelSizeAdj.Text + " cm");
- //第17行,第2列下降速度,第10列推行转速
- row = sheet.GetRow(16);
- row.GetCell(1).SetCellValue("Level " + textBox_Dec.Text);
- row.GetCell(9).SetCellValue(textBox_WalkSpeed.Text + " rpm");
- //第18行,第2列前齿,第10列俯仰角零偏
- row = sheet.GetRow(17);
- row.GetCell(1).SetCellValue(textBox_T_Front.Text + " T");
- row.GetCell(9).SetCellValue(textBox_Angle_P.Text + " °");
- //第19行,第2列后齿,第10列横滚角零偏
- row = sheet.GetRow(18);
- row.GetCell(1).SetCellValue(textBox_T_Tail.Text + " T");
- row.GetCell(9).SetCellValue(textBox_Angle_R.Text + " °");
- //第20行,第2列限流,第10列姿态传感器
- row = sheet.GetRow(19);
- row.GetCell(1).SetCellValue(textBox_MaxCurrent.Text + " A");
- row.GetCell(9).SetCellValue(comboBox_AstSensor.Text == "不支持" ? "不支持 No" : "支持 Yes");
- //第21行,第2列温度预警,第10列尾灯模式
- row = sheet.GetRow(20);
- row.GetCell(1).SetCellValue(textBox_NTC_Alarm.Text + " ℃");
- row.GetCell(9).SetCellValue(comboBox_LightMode.Text.Replace("模式", "Mode"));
- //第22行,第2列温度保护,第10列前灯电压
- row = sheet.GetRow(21);
- row.GetCell(1).SetCellValue(textBox_NTC_Ptotect.Text + " ℃");
- 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);
- //第23行,第2列码表,第10列后灯电压
- row = sheet.GetRow(22);
- row.GetCell(1).SetCellValue(comboBox_NoPBU.Text == "有" ? "有 Yes" : "无 No");
- 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);
- //第24行,第2列轮胎周长,第10列启动值
- row = sheet.GetRow(23);
- row.GetCell(1).SetCellValue(textBox_WheelSize.Text + " cm");
- row.GetCell(9).SetCellValue(textBox_Start_Min.Text + " - " + textBox_Start_Max.Text);
- //第25行,第2列电机系列,第10列校正系数1
- row = sheet.GetRow(24);
- row.GetCell(1).SetCellValue(textBox_Serial.Text);
- row.GetCell(9).SetCellValue(textBox_K_Min.Text + " - " + textBox_K_Max.Text);
- //第26行,第2列低压保护,第10列校正系数2
- row = sheet.GetRow(25);
- row.GetCell(1).SetCellValue(textBox_UV_Protect.Text + " mV");
- if ((textBox_Model.Text.Contains("PG")) || (textBox_Model.Text.Contains("PS")) || (textBox_Model.Text.Contains("J01")))
- row.GetCell(9).SetCellValue(textBox_K_Min.Text + " - " + textBox_K_Max.Text);
- else
- row.GetCell(9).SetCellValue("无此项目 None");
- //第27行,第2列推行限速,第10列校正系数3
- row = sheet.GetRow(26);
- row.GetCell(1).SetCellValue(textBox_Walk_SpeedLimit.Text + " km/h");
- if ((textBox_Model.Text.Contains("PG")) || (textBox_Model.Text.Contains("PS")) || (textBox_Model.Text.Contains("J01")))
- row.GetCell(9).SetCellValue(textBox_K_Min.Text + " - " + textBox_K_Max.Text);
- else
- row.GetCell(9).SetCellValue("无此项目 None");
- //第28行,第2列ECO增益,第10列零点值1
- row = sheet.GetRow(27);
- row.GetCell(1).SetCellValue(textBox_ECO_Gain.Text);
- row.GetCell(9).SetCellValue(textBox_Zero_Min.Text + " - " + textBox_Zero_Max.Text);
- //第29行,第2列ECO加速,第10列零点值2
- row = sheet.GetRow(28);
- row.GetCell(1).SetCellValue(textBox_ECO_Acc.Text);
- if ((textBox_Model.Text.Contains("PG")) || (textBox_Model.Text.Contains("PS")) || (textBox_Model.Text.Contains("J01")))
- row.GetCell(9).SetCellValue(textBox_Zero_Min.Text + " - " + textBox_Zero_Max.Text);
- else
- row.GetCell(9).SetCellValue("无此项目 None");
- //第30行,第2列NORM增益,第10列零点值3
- row = sheet.GetRow(29);
- row.GetCell(1).SetCellValue(textBox_NORM_Gain.Text);
- if ((textBox_Model.Text.Contains("PG")) || (textBox_Model.Text.Contains("PS")) || (textBox_Model.Text.Contains("J01")))
- row.GetCell(9).SetCellValue(textBox_Zero_Min.Text + " - " + textBox_Zero_Max.Text);
- else
- row.GetCell(9).SetCellValue("无此项目 None");
- //第31行,第2列NORM加速,第10列骑行历史
- row = sheet.GetRow(30);
- row.GetCell(1).SetCellValue(textBox_NORM_Acc.Text);
- row.GetCell(9).SetCellValue("0 km / 0 min");
- //第32行,第2列SPORT增益,第10列故障码
- row = sheet.GetRow(31);
- row.GetCell(1).SetCellValue(textBox_SPORT_Gain.Text);
- row.GetCell(9).SetCellValue("无故障记录 None");
- //第33行,第2列尾灯脉宽,第10列尾灯周期
- row = sheet.GetRow(32);
- row.GetCell(1).SetCellValue(textBox_LightPluse.Text + "\n" + ((float)Convert.ToDouble(textBox_LightPluse.Text) / 15000f).ToString("0.000") + " s");
- row.GetCell(9).SetCellValue(textBox_LightPeriod.Text + "\n" + ((float)Convert.ToDouble(textBox_LightPeriod.Text) / 15000f).ToString("0.000") + " s");
- //第34行,第2列超速报警阈值,第11列限速起始偏移
- row = sheet.GetRow(33);
- row.GetCell(1).SetCellValue(textBox_AlarmSpeed.Text + " km/h");
- row.GetCell(9).SetCellValue(textBox_LimitSpeedStart.Text + " km/h");
- //第35行,第2列限速结束偏移
- row = sheet.GetRow(34);
- row.GetCell(1).SetCellValue(textBox_LimitSpeedStop.Text + " km/h");
- #endregion
- using (FileStream file = File.OpenWrite(exportExcelName))
- {
- workbook.Write(file);
- workbook.Close();
- }
- }
- catch (Exception ex)
- {
- throw (ex);
- }
- //文件转换为pdf格式保存
- 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";
- Workbook workbook_1 = new Workbook();//创建Workbook类的实例
- workbook_1.LoadFromFile(exportExcelName);//加载Excel工作簿
- workbook_1.SaveToFile(exportPdfName, FileFormat.PDF);//将整个工作薄保存为PDF
- MessageBox.Show("参数已生成,进入文件管理页面查看!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- button_Generate.Text = "上传中";
- //发送文件到服务器
- if (StartForm.myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- int okCnt = 0;
- if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/cfg/", DateNow) == false)
- {
- StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
- }
- //上传配置文件
- bool result = StartForm.myFtp.UploadFile(fileName, StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
- if (result == true)
- {
- okCnt++;
- //MessageBox.Show("配置文件上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //上传配置清单excel
- result = StartForm.myFtp.UploadFile(exportExcelName, StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
- if (result == true)
- {
- okCnt++;
- //MessageBox.Show("配置检验清单上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //上传配置清单pdf
- result = StartForm.myFtp.UploadFile(exportPdfName, StartForm.myServerCfg.RootPath + "/cfg/" + DateNow);
- if (result == true)
- {
- okCnt++;
- //MessageBox.Show("配置检验清单上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- if (okCnt >= 3)
- {
- MessageBox.Show("配置检验文件上传服务器成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- MessageBox.Show("配置检验文件上传服务器失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- button_Generate.Text = "生成";
- button_Generate.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
- button_Generate.Enabled = true;
- }
- private void button_keyboard_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("osk.exe");
- }
- //输入型号时自动更新关键参数
- private void textBox_Model_TextChanged(object sender, EventArgs e)
- {
- if (textBox_Model.Text.Contains("J01"))
- {
- textBox_Serial.Text = "1";//系列号
- textBox_MaxCurrent.Text = "13";//限流
- textBox_RatePower.Text = "250";//额定功率
- textBox_RateSpeed.Text = "1200";//额定转速
- textBox_Rate_Vol.Text = "36";//额定电压
- textBox_NC_Current.Text = "800";//空载电流
- textBox_Zero_Min.Text = "100";//零偏下限
- textBox_Zero_Max.Text = "2000";//零偏上限
- textBox_K_Min.Text = "0.40";//传感器标定值下限
- textBox_K_Max.Text = "1.20";//传感器标定值下限
- textBox_Start_Min.Text = "280";//启动值下限
- textBox_Start_Max.Text = "500";//启动值上限
- textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
- }
- else if (textBox_Model.Text.Contains("VL"))
- {
- textBox_Serial.Text = "1";//系列号
- textBox_MaxCurrent.Text = "13";//限流
- textBox_RatePower.Text = "250";//额定功率
- textBox_RateSpeed.Text = "1200";//额定转速
- textBox_Rate_Vol.Text = "36";//额定电压
- textBox_NC_Current.Text = "800";//空载电流
- textBox_Zero_Min.Text = "200";//零偏下限
- textBox_Zero_Max.Text = "1800";//零偏上限
- textBox_K_Min.Text = "0.25";//传感器标定值下限
- textBox_K_Max.Text = "0.75";//传感器标定值下限
- textBox_Start_Min.Text = "350";//启动值下限
- textBox_Start_Max.Text = "750";//启动值上限
- if (textBox_Model.Text.Contains("03") || textBox_Model.Text.Contains("13"))
- {
- textBox_GasSpeedTh.Text = "200";
- }
- else
- {
- textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
- }
- }
- else if (textBox_Model.Text.Contains("VS"))
- {
- textBox_Serial.Text = "2";//系列号
- textBox_MaxCurrent.Text = "15";//限流
- textBox_RatePower.Text = "250";//额定功率
- textBox_RateSpeed.Text = "1200";//额定转速
- textBox_Rate_Vol.Text = "36";//额定电压
- textBox_NC_Current.Text = "800";//空载电流
- textBox_Zero_Min.Text = "200";//零偏下限
- textBox_Zero_Max.Text = "1800";//零偏上限
- textBox_K_Min.Text = "0.25";//传感器标定值下限
- textBox_K_Max.Text = "0.75";//传感器标定值下限
- textBox_Start_Min.Text = "350";//启动值下限
- textBox_Start_Max.Text = "750";//启动值上限
- if (textBox_Model.Text.Contains("03") || textBox_Model.Text.Contains("13"))
- {
- textBox_GasSpeedTh.Text = "200";
- }
- else
- {
- textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
- }
- }
- else if (textBox_Model.Text.Contains("VR"))
- {
- textBox_Serial.Text = "2";//系列号
- textBox_MaxCurrent.Text = "15";//限流
- textBox_RatePower.Text = "250";//额定功率
- textBox_RateSpeed.Text = "1200";//额定转速
- textBox_Rate_Vol.Text = "36";//额定电压
- textBox_NC_Current.Text = "800";//空载电流
- textBox_Zero_Min.Text = "200";//零偏下限
- textBox_Zero_Max.Text = "1800";//零偏上限
- textBox_K_Min.Text = "0.25";//传感器标定值下限
- textBox_K_Max.Text = "0.75";//传感器标定值下限
- textBox_Start_Min.Text = "350";//启动值下限
- textBox_Start_Max.Text = "750";//启动值上限
- textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
- }
- else if (textBox_Model.Text.Contains("PG"))
- {
- textBox_Serial.Text = "3";//系列号
- textBox_MaxCurrent.Text = "17";//限流
- textBox_RatePower.Text = "250";//额定功率
- textBox_RateSpeed.Text = "1550";//额定转速
- textBox_Rate_Vol.Text = "36";//额定电压
- textBox_NC_Current.Text = "1000";//空载电流
- textBox_Zero_Min.Text = "100";//零偏下限
- textBox_Zero_Max.Text = "2000";//零偏上限
- textBox_K_Min.Text = "0.25";//传感器标定值下限
- textBox_K_Max.Text = "1.20";//传感器标定值下限
- textBox_Start_Min.Text = "280";//启动值下限
- textBox_Start_Max.Text = "500";//启动值上限
- textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
- }
- else if (textBox_Model.Text.Contains("PS"))
- {
- textBox_Serial.Text = "4";//系列号
- textBox_MaxCurrent.Text = "17";//限流
- textBox_RatePower.Text = "500";//额定功率
- textBox_RateSpeed.Text = "1650";//额定转速
- textBox_Rate_Vol.Text = "48";//额定电压
- textBox_NC_Current.Text = "1000";//空载电流
- textBox_Zero_Min.Text = "100";//零偏下限
- textBox_Zero_Max.Text = "2000";//零偏上限
- textBox_K_Min.Text = "0.25";//传感器标定值下限
- textBox_K_Max.Text = "1.20";//传感器标定值下限
- textBox_Start_Min.Text = "280";//启动值下限
- textBox_Start_Max.Text = "500";//启动值上限
- textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
- }
- else
- {
- textBox_Serial.Text = "";//系列号
- textBox_MaxCurrent.Text = "";//限流
- textBox_RatePower.Text = "";//额定功率
- textBox_RateSpeed.Text = "";//额定转速
- textBox_Rate_Vol.Text = "";//额定电压
- textBox_NC_Current.Text = "";//空载电流
- textBox_Zero_Min.Text = "";//零偏下限
- textBox_Zero_Max.Text = "";//零偏上限
- textBox_K_Min.Text = "";//传感器标定值下限
- textBox_K_Max.Text = "";//传感器标定值下限
- textBox_Start_Min.Text = "";//启动值下限
- textBox_Start_Max.Text = "";//启动值上限
- textBox_GasSpeedTh.Text = "";
- }
- }
- //输入限速时更改指拨转速阈值
- private void textBox_SpeedLimit_TextChanged(object sender, EventArgs e)
- {
- if (textBox_SpeedLimit.Text == "")
- return;
- if ((!textBox_Model.Text.Contains("6503")) && (!textBox_Model.Text.Contains("6513")) && (!textBox_Model.Text.Contains("7503")) && (!textBox_Model.Text.Contains("7513")))
- {
- textBox_GasSpeedTh.Text = (Convert.ToInt16(textBox_SpeedLimit.Text) * 49).ToString();
- }
- }
- //更改尾灯模式时更改尾灯脉宽和周期
- private void comboBox_LightMode_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_LightMode.SelectedIndex == 0) // 模式1,开灯低亮,刹车高亮
- {
- textBox_AlarmSpeed.Text = "15.0";
- textBox_LightPluse.Text = "75";
- textBox_LightPeriod.Text = "150";
- }
- else if (comboBox_LightMode.SelectedIndex == 5) // 模式6,超速报警
- {
- textBox_AlarmSpeed.Text = "15.0";
- textBox_LightPluse.Text = "7500";
- textBox_LightPeriod.Text = "45000";
- }
- }
- //指拨转速阈值修改
- private void textBox_GasSpeedTh_TextChanged(object sender, EventArgs e)
- {
- UInt32 DataTemp = 0;
- if (textBox_GasSpeedTh.Text == "")
- {
- return;
- }
- DataTemp = Convert.ToUInt32(textBox_GasSpeedTh.Text);
- if (textBox_Model.Text.Contains("VL"))
- {
- if (DataTemp >= 1200)
- {
- textBox_GasSpeedTh.Text = "1200";
- }
- }
- else if (textBox_Model.Text.Contains("VS"))
- {
- if (DataTemp >= 1200)
- {
- textBox_GasSpeedTh.Text = "1200";
- }
- }
- else if (textBox_Model.Text.Contains("PG"))
- {
- if (DataTemp >= 1400)
- {
- textBox_GasSpeedTh.Text = "1400";
- }
- }
- else if (textBox_Model.Text.Contains("PS"))
- {
- if (DataTemp >= 1600)
- {
- textBox_GasSpeedTh.Text = "1600";
- }
- }
- }
- /// <summary>
- /// 指拨模式修改时,自动调整限功率方式和限速值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_GasMode_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_GasMode.SelectedIndex == 0)//不支持
- {
- comboBox_GasPowerLimit.SelectedIndex = 0;
- textBox_GasSpeedLimit.Text = "无效";
- comboBox_GasModeStart.SelectedIndex = 0;
- }
- else if (comboBox_GasMode.SelectedIndex == 3)//推行模式
- {
- comboBox_GasPowerLimit.SelectedIndex = 0;
- comboBox_GasModeStart.SelectedIndex = 0;
- textBox_GasSpeedLimit.Text = "6";
- }
- else//速度模式或力矩模式
- {
- comboBox_GasPowerLimit.SelectedIndex = 1;
- comboBox_GasModeStart.SelectedIndex = 1;
- textBox_GasSpeedLimit.Text = textBox_SpeedLimit.Text;
- }
- }
- }
- }
|