123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Threading;
- using System.Windows.Forms;
- namespace Welling_Motor_Debug_Tool
- {
- public partial class Form1 : Form
- {
- #region 变量定义
- //串口实例
- Serial_Process mySerialProcess = new Serial_Process();
- //MC运行信息超时计数
- bool MC_RunInfo_Refresh = false;
- ushort MC_RunInfo_Refresh_Cnt = 0;
- //MC故障码超时计数
- bool MC_ErrorCode_Refresh = false;
- ushort MC_ErrorCode_Refresh_Cnt = 0;
- //配置参数实例
- Params myParams = new Params();
- //记录文件名称
- string SaveFilename = "";
- //BMS运行信息超时计数
- bool BMS_RunInfo_Refresh = false;
- ushort BMS_RunInfo_Refresh_Cnt = 0;
- #endregion
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, System.EventArgs e)
- {
- //页面初始化
- label_BuildTime.Text= "编译时间:"+ System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
- //下拉控件初始值设定
- comboBox_WorkMode.SelectedIndex = 0;
- comboBox_GearSt.SelectedIndex = 0;
- comboBox_LightSwitch.SelectedIndex = 1;
- comboBox_OBC_SetGearST.SelectedIndex = 0;
- comboBox_OBC_LightSw.SelectedIndex = 1;
- //端口设置
- mySerialProcess.Init();
- toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
- toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
- //创建线程,定时解析数据
- Thread th = new Thread(Task_SerialProcess);
- th.IsBackground = true;
- th.Start();
- }
- #region 串口数据解析线程
- /// <summary>
- /// 串口数据解析线程
- /// </summary>
- private void Task_SerialProcess()
- {
- //创建定时器,定时读取串口数据
- System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
- timer_ReadSerial.Enabled = true;
- timer_ReadSerial.Interval = 20;
- timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
- timer_ReadSerial.Start();
- while (true)
- {
- Thread.Sleep(1);
- };
- }
- /// <summary>
- /// 串口解析定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_ReadSerial_Tick(object sender, EventArgs e)
- {
- //串口解析
- Serial_process(mySerialProcess.buffer);
- }
- #endregion
- #region 数据解析
- public void Serial_process(List<byte> buffer)
- {
- byte DataNum = 0; //记录每条命令数据段的长度
- ushort PackageID, Cmd;
- byte[] Data = new byte[1024];
- while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
- {
- if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
- {
- PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
- if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
- {
- int CmdLen = buffer[5];
- if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
- buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
- while (CmdLen > 0) //读取命令段
- {
- Cmd = (ushort)(buffer[0] * 256 + buffer[1]);
- DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
- if (DataNum <= (CmdLen - 2))
- {
- for (int i = 0; i < DataNum; i++)
- {
- Data[i] = buffer[i + 2];
- }
- DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
- buffer.RemoveRange(0, DataNum);//移除处理过的数据段
- CmdLen -= (DataNum + 2);
- if (CmdLen < 2)
- {
- buffer.RemoveRange(0, CmdLen + 2);
- return;
- }
- }
- else
- {
- buffer.RemoveRange(0, CmdLen + 11);
- }
- }
- }
- else
- {
- buffer.RemoveAt(0);//ID不对
- }
- }
- else
- {
- buffer.RemoveAt(0);//帧头不对,删除帧头高字节
- }
- }
- }
- private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
- {
- int DataTemp;
- ushort uData16;
- unchecked
- {
- this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
- }
- #region 解析发送给CDL的指令
- if (ID == 0x7FF)
- {
- switch (CmdTemp)
- {
- case 0x1100://
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //CDL连接成功
- mySerialProcess.CDL_Online_Flag = true;
- MessageBox.Show("连接成功!", "提示");
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析电机的命令
- else if ((ID == 0x715) || (ID == 0x710))
- {
- switch (CmdTemp)
- {
- case 0x1020://电机运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_RunInfo_Refresh = true;
- //车速
- DataTemp = (int)(Data[1] * 256 + Data[0]);
- textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
- //输出转速
- DataTemp = (ushort)(Data[3] * 256 + Data[2]);
- textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
- Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
- Class_MotorSpeed.Data = DataTemp;
- //电功率
- DataTemp = (ushort)(Data[5] * 256 + Data[4]);
- textBox_RunInfo_Power.Text = Convert.ToString(DataTemp * 2) + " W";
- //母线电压
- DataTemp = (ushort)(Data[7] * 256 + Data[6]);
- textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
- //母线电流
- DataTemp = (ushort)(Data[9] * 256 + Data[8]);
- textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
- Class_CurrentData.String = textBox_RunInfo_Current.Text;
- Class_CurrentData.Data = DataTemp;
- //踏频
- DataTemp = (ushort)(Data[10]);
- textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
- //踩踏力矩
- DataTemp = (ushort)(Data[11]);
- textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
- Class_TorqueData.String = textBox_RunInfo_Torque.Text;
- Class_TorqueData.Data = DataTemp;
- //踩踏方向
- DataTemp = (ushort)(Data[12]);
- if (DataTemp == 0)
- {
- textBox_RunInfo_Dir.Text = "正向";
- }
- else if (DataTemp == 1)
- {
- textBox_RunInfo_Dir.Text = "反向";
- }
- else if (DataTemp == 2)
- {
- textBox_RunInfo_Dir.Text = "停止";
- }
- //助力档位
- DataTemp = (ushort)(Data[13]);
- if (DataTemp == 0x22)
- {
- textBox_RunInfo_GearSt.Text = "Walk";
- comboBox_GearSt.SelectedIndex = 6;
- comboBox_OBC_SetGearST.SelectedIndex = 6;
- }
- else
- {
- textBox_RunInfo_GearSt.Text = Convert.ToString(DataTemp);
- comboBox_GearSt.SelectedIndex = DataTemp;
- comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
- }
- //大灯状态
- DataTemp = (ushort)(Data[14]);
- if (DataTemp == 0xF0)
- {
- textBox_RunInfo_LightSwitch.Text = "OFF";
- comboBox_LightSwitch.SelectedIndex = 1;
- comboBox_OBC_LightSw.SelectedIndex = 1;
- }
- else if (DataTemp == 0xF1)
- {
- textBox_RunInfo_LightSwitch.Text = "ON";
- comboBox_LightSwitch.SelectedIndex = 0;
- comboBox_OBC_LightSw.SelectedIndex = 0;
- }
- //剩余电量
- DataTemp = (ushort)(Data[15]);
- textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
- //剩余续航里程
- DataTemp = (ushort)(Data[17] * 256 + Data[16]);
- if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
- {
- textBox_RunInfo_Range.Text = "---";
- }
- else
- {
- textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
- }
- //预留,空2bytes
- //平均功耗
- DataTemp = (ushort)(Data[20]);
- textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
- //PCB温度
- DataTemp = (ushort)(Data[21]);
- textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40));
- //绕组温度
- DataTemp = (ushort)(Data[22]);
- textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40));
- //MCU温度
- DataTemp = (ushort)(Data[23]);
- textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40));
- //单次里程
- DataTemp = (ushort)(Data[25] * 256 + Data[24]);
- textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
- //单次时间
- DataTemp = (ushort)(Data[27] * 256 + Data[26]);
- textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
- //数据保存
- DataAutoSave();
- }));
- }
- break;
- }
- case 0x1104://故障码
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_ErrorCode_Refresh = true;
- textBox_ErrorCode.Text =
- Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
- "H";
- }));
- }
- break;
- }
- case 0xA903://反馈指令
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- timer_1s.Enabled = false;
- MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }));
- }
- break;
- }
- case 0xB226://马达参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_MotorParam.Clear();
- for (int i = 0; i < myParams.MotorParma.Count; i++)
- {
- richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB318://整车信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_BikeParam.Clear();
- for (int i = 0; i < myParams.BikeParma.Count; i++)
- {
- richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB420://控制器参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_ControlParam.Clear();
- for (int i = 0; i < myParams.ControlParma.Count; i++)
- {
- richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB528://传感器参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_SensorParam.Clear();
- for (int i = 0; i < myParams.SensorParam.Count; i++)
- {
- richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB64C://助力参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_AssistParam.Clear();
- int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
- int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
- for (int i = 0; i < myParams.AssistParam.Count; i++)
- {
- if (i < index_1) //数据占用2bytes
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- else if (i <= index_2) //数据占用4bytes
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((Data[4 * i - 5] << 24) + (Data[4 * i - 6] << 16) + (Data[4 * i - 7] << 8) + Data[4 * i - 8]) + ", ");
- }
- else //数据占用2bytes
- {
- richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString(Data[2 * i + 17] * 256 + Data[2 * i + 16]) + ", ");
- }
- }
- richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB74C://历史记录
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Record.Clear();
- for (int i = 0; i < myParams.Record.Count; i++)
- {
- richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
- }));
- }
- break;
- }
- case 0xB832://调试参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_DebugParam.Clear();
- for (int i = 0; i < myParams.DebugParam.Count; i++)
- {
- richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
- }
- richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
- }));
- }
- break;
- }
- case 0x1240://电机版本信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //电机型号
- textBox_Model.Text = "";
- textBox_OBC_ReadModel.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_Model.Text += ((char)Data[i]).ToString();
- textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
- }
- Class_Motor_Ver.Mode = textBox_Model.Text;
- //电机SN
- textBox_SN.Text = "";
- textBox_OBC_ReadSN.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[16 + i] == 0x2E)
- {
- break;
- }
- textBox_SN.Text += ((char)Data[16 + i]).ToString();
- textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
- }
- Class_Motor_Ver.SN = textBox_SN.Text;
- //电机HW
- textBox_HW.Text = "";
- textBox_OBC_ReadHW.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[32 + i] == 0x2E)
- {
- break;
- }
- textBox_HW.Text += ((char)Data[32 + i]).ToString();
- textBox_OBC_ReadHW.Text += ((char)Data[32 + i]).ToString();
- }
- Class_Motor_Ver.HW = textBox_HW.Text;
- //电机FW
- textBox_FW.Text = "";
- textBox_OBC_ReadFW.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[48 + i] == 0x2E)
- {
- break;
- }
- if (Data[48 + i] == 'r')
- {
- Data[48 + i] = (byte)'.';
- }
- textBox_FW.Text += ((char)Data[48 + i]).ToString();
- textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
- }
- Class_Motor_Ver.FW = textBox_FW.Text;
- }));
- }
- break;
- }
- case 0xA610://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User1.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User1.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA710://自定义2
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User2.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User2.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA810://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_User3.Text = "";
- for (ushort i = 0; i < 16; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_User3.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA520://生产信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //生产商
- textBox_MAC.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[i] == 0x2E)
- {
- break;
- }
- textBox_MAC.Text += ((char)Data[i]).ToString();
- }
- //生产地
- textBox_MACAdd.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[8 + i] == 0x2E)
- {
- break;
- }
- textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
- }
- //生产日期
- textBox_MACDate.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[16 + i] == 0x2E)
- {
- break;
- }
- textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
- }
- //品牌信息
- textBox_PP.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- if (Data[24 + i] == 0x2E)
- {
- break;
- }
- textBox_PP.Text += ((char)Data[24 + i]).ToString();
- }
- }));
- }
- break;
- }
- case 0xA408://密钥
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_Key.Text = "";
- for (ushort i = 0; i < 8; i++)
- {
- textBox_Key.Text += ((char)Data[i]).ToString();
- }
- }));
- }
- break;
- }
- case 0x1401://在线检测结果
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
- }));
- }
- break;
- }
- case 0x1510://骑行历史信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- long DataTemp32;
- //ODO里程
- DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
- textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
- //ODO时间
- DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
- if (DataTemp32 >= 60 * 100000)
- textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
- else
- textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
- //TRIP里程
- DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
- textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
- //TRIP时间
- DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
- if (DataTemp32 >= 60 * 100000)
- textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
- else
- textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析BMS广播的命令
- else if (ID == 0x720)
- {
- switch (CmdTemp)
- {
- case 0x1010://BMS运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- BMS_RunInfo_Refresh = true;
- richTextBox_OBC_BMS_RunInfo.Clear();
- //电压
- uData16 = (ushort)(Data[1] * 256 + Data[0]);
- richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
- //电流
- uData16 = (ushort)(Data[3] * 256 + Data[2]);
- richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
- //剩余容量
- uData16 = (ushort)(Data[5] * 256 + Data[4]);
- richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
- //满充容量
- uData16 = (ushort)(Data[7] * 256 + Data[6]);
- richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mV" + "\r\n");
- //电芯温度
- richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
- //剩余电量
- richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
- //电池状态
- richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
- //SOH
- richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %" + "\r\n");
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 解析电机发送OBC的命令
- else if (ID == 0x713)
- {
- switch (CmdTemp)
- {
- case 0x5408://电机用户参数
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_OBC_ReadUserInfo.Clear();
- //默认周长
- richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
- //启动模式
- richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
- comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
- //限速
- richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
- //周长微调
- numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
- richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
- //助力方案
- richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
- comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
- }));
- }
- break;
- }
- case 0x5303://电机应答反馈
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- timer_1s.Enabled = false;
- MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- }
- #endregion
- /// <summary>
- /// 端口连接事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
- {
- bool result = false;
- if (连接ToolStripMenuItem.Text == "连接")
- {
- result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text);
- if (result)
- {
- toolStripComboBox_ComNum.Enabled = false;
- toolStripComboBox_Baudrate.Enabled = false;
- 刷新ToolStripMenuItem.Enabled = false;
- 连接ToolStripMenuItem.Text = "断开";
- 连接ToolStripMenuItem.Checked = true;
- label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
- }
- }
- else if (连接ToolStripMenuItem.Text == "断开")
- {
- result = mySerialProcess.SerialClose();
- if (result)
- {
- toolStripComboBox_ComNum.Enabled = true;
- toolStripComboBox_Baudrate.Enabled = true;
- 刷新ToolStripMenuItem.Enabled = true;
- 连接ToolStripMenuItem.Text = "连接";
- 连接ToolStripMenuItem.Checked = false;
- label_COM_Sta.Text = "连接状态:未连接";
- }
- }
- }
- /// <summary>
- /// 端口号刷新事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- toolStripComboBox_ComNum.Items.Clear();
- toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
- }
- /// <summary>
- /// 转速调节事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
- {
- var Data = new byte[1];
- Data[0] = (byte)numericUpDown_SpeedAdj.Value;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
- }
- /// <summary>
- /// 存储标志修改事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
- }
- /// <summary>
- /// 1s定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_1s_Tick(object sender, EventArgs e)
- {
- //时间更新
- label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString();
- //MC_Runinfo超时清除
- if (MC_RunInfo_Refresh == false)
- {
- MC_RunInfo_Refresh_Cnt++;
- if (MC_RunInfo_Refresh_Cnt > 5)//5s
- {
- MC_RunInfo_Clear();
- MC_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_RunInfo_Refresh_Cnt = 0;
- }
- MC_RunInfo_Refresh = false;
- //BMS_RunInfo超时清除
- if (BMS_RunInfo_Refresh == false)
- {
- BMS_RunInfo_Refresh_Cnt++;
- if (BMS_RunInfo_Refresh_Cnt > 5)//5s
- {
- richTextBox_OBC_BMS_RunInfo.Clear();
- BMS_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- BMS_RunInfo_Refresh_Cnt = 0;
- }
- BMS_RunInfo_Refresh = false;
- //故障码超时清除
- if (MC_ErrorCode_Refresh == false)
- {
- MC_ErrorCode_Refresh_Cnt++;
- if (MC_ErrorCode_Refresh_Cnt > 5)//5s
- {
- textBox_ErrorCode.Text = "---";
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- MC_ErrorCode_Refresh = false;
- //CDL连接超时
- #if false
- if (mySerialProcess.CDL_Online_Flag == false)
- {
- mySerialProcess.CDL_OnlineCheck_Cnt++;
- if (mySerialProcess.CDL_OnlineCheck_Cnt > 3)//3s
- {
- timer_1s.Enabled = false;
- MessageBox.Show("连接失败!", "提示");
- timer_1s.Enabled = true;
- //关闭串口
- mySerialProcess.SerialClose();
- toolStripComboBox_ComNum.Enabled = true;
- toolStripComboBox_Baudrate.Enabled = true;
- 刷新ToolStripMenuItem.Enabled = true;
- 连接ToolStripMenuItem.Text = "连接";
- 连接ToolStripMenuItem.Checked = false;
- label_COM_Sta.Text = "连接状态:未连接";
- }
- }
- #endif
- //OBC定时发送设置档位
- if (checkBox_OBC_StartSetGearSt.Checked == true)
- {
- var CtrlCode = new byte[2];
- if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
- CtrlCode[0] = 0x22;
- else
- CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
- if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
- CtrlCode[1] = 0xF1;
- else
- CtrlCode[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode);
- }
- //OBC定时发送查询电池
- if (checkBox_OBC_StartReadBMS.Checked == true)
- {
- mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null);
- }
- }
- /// <summary>
- /// 运行信息清除
- /// </summary>
- private void MC_RunInfo_Clear()
- {
- foreach (Control c in groupBox2.Controls)
- {
- if ((c is TextBox))
- {
- if(c.Name != textBox_ErrorCode.ToString())
- c.Text = "---";
- }
- }
- }
- /// <summary>
- /// 读取马达参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Read_MotorParam_Click(object sender, EventArgs e)
- {
- richTextBox_MotorParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
- }
- /// <summary>
- /// 写入马达参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Write_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[40];
- for (int i = 0; i < 40; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取整车信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadBikeParam_Click(object sender, EventArgs e)
- {
- richTextBox_BikeParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
- }
- /// <summary>
- /// 写入整车信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteBikeParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[26];
- for (int i = 0; i < 26; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1A, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取控制器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadControlParam_Click(object sender, EventArgs e)
- {
- richTextBox_ControlParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
- }
- /// <summary>
- /// 写入控制器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteControlParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[34];
- for (int i = 0; i < 34; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadAssistParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- int AssistNum = 0;
- try
- {
- AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
- ConfigParam[0] = (byte)(AssistNum & 0xFF);
- ConfigParam[1] = (byte)(AssistNum >> 8);
- AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
- ConfigParam[2] = (byte)(AssistNum & 0xFF);
- ConfigParam[3] = (byte)(AssistNum >> 8);
- richTextBox_AssistParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
-
- }
- /// <summary>
- /// 写入助力参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteAssistParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[80];
- for (int i = 0; i < 80; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ulong ulDataTemp = 0;
- string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index_1 = 0, index_2 = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
- {
- index_1 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
- {
- index_2 = i;
- break;
- }
- }
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
- if (i < index_1)
- {
- ConfigParam[2 * i + 4] = (byte)ulDataTemp;
- ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
- }
- else if (i <= index_2)
- {
- ConfigParam[4 * i - 4] = (byte)ulDataTemp;
- ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
- ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
- ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
- }
- else
- {
- ConfigParam[2 * i + 20] = (byte)ulDataTemp;
- ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取调试参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadDebugParam_Click(object sender, EventArgs e)
- {
- richTextBox_DebugParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
- }
- /// <summary>
- /// 写入调试参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteDebugParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[52];
- for (int i = 0; i < 52; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4634, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 读取历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadRecord_Click(object sender, EventArgs e)
- {
- richTextBox_Record.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
- }
- /// <summary>
- /// 读取传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadSensorParam_Click(object sender, EventArgs e)
- {
- richTextBox_SensorParam.Clear();
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
- }
- /// <summary>
- /// 写入力矩传感器标定值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Write_Cal_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[4];
- for (int i = 0; i < 4; i++)
- ConfigParam[i] = 0;
- ushort uwDataTemp = 0;
- try
- {
- uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
- ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[1] = (byte)(uwDataTemp >> 8);
- uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
- ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
- ConfigParam[3] = (byte)(uwDataTemp >> 8);
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 写入传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSensorParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[14];
- for (int i = 0; i < 14; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- //力矩传感器参数只写入前面14项与力矩传感器相关的参数
- string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "踏频传感器一圈脉冲数")
- {
- index = i;
- break;
- }
- }
- for (int i = 0; i < (strDataTemp.Length - index); i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 写入型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteModel_Click(object sender, EventArgs e)
- {
- string Mode = textBox_Model.Text;
- var ModeArray = new byte[16];
- for (ushort i = 0; i < Mode.Length; i++)
- {
- ModeArray[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- ModeArray[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- ModeArray[Mode.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
- }
- /// <summary>
- /// 写入SN
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteSN_Click(object sender, EventArgs e)
- {
- string SN = textBox_SN.Text;
- var SNArray = new byte[16];
- for (ushort i = 0; i < SN.Length; i++)
- {
- SNArray[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- SNArray[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- SNArray[SN.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
- }
- /// <summary>
- /// 查询版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadVersion_Click(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
- }
- /// <summary>
- /// 查询自定义1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser1_Click(object sender, EventArgs e)
- {
- textBox_User1.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
- }
- /// <summary>
- /// 查询自定义2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser2_Click(object sender, EventArgs e)
- {
- textBox_User2.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
- }
- /// <summary>
- /// 查询自定义3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadUser3_Click(object sender, EventArgs e)
- {
- textBox_User3.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
- }
- /// <summary>
- /// 写入自定义字符串1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser1_Click(object sender, EventArgs e)
- {
- string User = textBox_User1.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
- }
- /// <summary>
- /// 写入自定义字符串2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser2_Click(object sender, EventArgs e)
- {
- string User = textBox_User2.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
- }
- /// <summary>
- /// 写入自定义字符串3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteUser3_Click(object sender, EventArgs e)
- {
- string User = textBox_User3.Text;
- var UserArray = new byte[16];
- for (ushort i = 0; i < User.Length; i++)
- {
- UserArray[i] = (byte)User[i];
- }
- if (User.Length < 16)
- {
- UserArray[User.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - User.Length - 1; i++)
- {
- UserArray[User.Length + 1 + i] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
- }
- /// <summary>
- /// 查询生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadMAC_Click(object sender, EventArgs e)
- {
- textBox_MAC.Text = "---";
- textBox_MACAdd.Text = "---";
- textBox_MACDate.Text = "---";
- textBox_PP.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
- }
-
- /// <summary>
- /// 写入生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteMac_Click(object sender, EventArgs e)
- {
- var MACArray = new byte[32];
- //填入生产商
- for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
- {
- MACArray[i] = (byte)textBox_MAC.Text[i];
- }
- if (textBox_MAC.Text.Length < 8)
- {
- MACArray[textBox_MAC.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
- {
- MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
- }
- }
- //填入生产地
- for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
- {
- MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
- }
- if (textBox_MACAdd.Text.Length < 8)
- {
- MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
- {
- MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
- }
- }
- //填入生产日期
- for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
- {
- MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
- }
- if (textBox_MACDate.Text.Length < 8)
- {
- MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
- {
- MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
- }
- }
- //填入品牌
- for (ushort i = 0; i < textBox_PP.Text.Length; i++)
- {
- MACArray[24 + i] = (byte)textBox_PP.Text[i];
- }
- if (textBox_PP.Text.Length < 8)
- {
- MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
- {
- MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
- }
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
- }
- /// <summary>
- /// 查询密钥
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadKey_Click(object sender, EventArgs e)
- {
- textBox_Key.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
- }
- /// <summary>
- /// 写入校验密钥
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteKey_Click(object sender, EventArgs e)
- {
- string Key = textBox_Key.Text;
- var KeyArray = new byte[8];
- if (Key.Length != 8)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- for (ushort i = 0; i < Key.Length; i++)
- {
- KeyArray[i] = (byte)Key[i];
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
- }
- /// <summary>
- /// 查询在线检测结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ReadOnLine_Click(object sender, EventArgs e)
- {
- textBox_Online.Text = "---";
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
- }
- /// <summary>
- /// 系统清除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_SystemClear_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 参数还原
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Recovery_Click(object sender, EventArgs e)
- {
- var Code = new byte[8];
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'C';
- Code[3] = (byte)'O';
- Code[4] = (byte)'V';
- Code[5] = (byte)'E';
- Code[6] = (byte)'R';
- Code[7] = (byte)'Y';
- timer_1s.Enabled = false;
- if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 系统复位
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_Reset_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'S';
- Code[3] = (byte)'E';
- Code[4] = (byte)'T';
- timer_1s.Enabled = false;
- if (MessageBox.Show("系统将重启", "确认重启?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 记录清除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ClearLog_Click(object sender, EventArgs e)
- {
- var Code = new byte[9];
- Code[0] = (byte)'L';
- Code[1] = (byte)'O';
- Code[2] = (byte)'G';
- Code[3] = (byte)' ';
- Code[4] = (byte)'C';
- Code[5] = (byte)'L';
- Code[6] = (byte)'E';
- Code[7] = (byte)'A';
- Code[8] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
- }
- }
- }
- timer_1s.Enabled = true;
- }
- /// <summary>
- /// 打开系统计算器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("calc.exe");
- }
- /// <summary>
- ///故障转换和显示
- /// </summary>
- List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
- "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
- "",""};
- private string ErrorInfoDisplay(UInt32 Code)
- {
- string Result = "";
- if (Code == 0)
- {
- Result = "无故障";
- }
- else
- {
- for (int i = 0; i < 32; i++)
- {
- if ((Code & 0x01) == 0x01)
- {
- Result += ErrorInfo[i] + " ";
- }
- Code >>= 1;
- }
- }
- return Result;
- }
- /// <summary>
- /// 鼠标滑过故障码显示具体内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
- {
- // 创建the ToolTip
- ToolTip toolTip1 = new ToolTip();
- // 设置显示样式
- toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
- toolTip1.InitialDelay = 50;//事件触发多久后出现提示
- toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
- toolTip1.ShowAlways = true;//是否显示提示框
- // 设置伴随的对象.
- string ErrorCode = this.textBox_ErrorCode.Text;
- UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
- toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
- }
- /// <summary>
- /// 数据记录
- /// </summary>
- private void DataAutoSave()
- {
- if (记录数据ToolStripMenuItem.Checked == true)
- {
- if (SaveFilename == string.Empty)
- {
- return;
- }
- string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_") + " ";
- foreach (Control c in groupBox3.Controls)
- {
- if (c is TextBox)
- {
- SaveData += c.Text + " , ";
- }
- }
- SaveData += "\r\n";
- System.IO.File.AppendAllText(SaveFilename, SaveData);//sb.ToString());
- }
- }
- /// <summary>
- /// 打开或关闭数据记录
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (记录数据ToolStripMenuItem.Checked == false)
- {
- if (mySerialProcess.mySerial.IsOpen == true)
- {
- SaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
- timer_1s.Enabled = false;
- MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- 记录数据ToolStripMenuItem.Checked = true;
- }
- else
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- }
- else
- {
- 记录数据ToolStripMenuItem.Checked = false;
- timer_1s.Enabled = false;
- MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- timer_1s.Enabled = true;
- }
- }
- /// <summary>
- /// 修改写入的助力力矩曲线编号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_AssistTorque_SelectionChangeCommitted(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 修改写入的助力踏频曲线编号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_AssistCadence_SelectionChangeCommitted(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 工作模式选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_WorkMode_SelectionChangeCommitted(object sender, EventArgs e)
- {
- var RunMode = new byte[1];
- if (comboBox_WorkMode.Text == "配置模式")
- RunMode[0] = 0x01;
- else
- RunMode[0] = 0x00;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
- }
- /// <summary>
- /// 助力档位选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox_GearSt_SelectionChangeCommitted(object sender, EventArgs e)
- {
- var CtrlCode = new byte[2];
- if (comboBox_GearSt.SelectedIndex == 6)//档位
- CtrlCode[0] = 0x22;
- else
- CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
- if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
- CtrlCode[1] = 0xF1;
- else
- CtrlCode[1] = 0xF0;
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
- }
- /// <summary>
- /// 仪表启动控制档位开关事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_OBC_StartSetGearSt.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartSetGearSt.Checked = false;
- return;
- }
- //检查是否选择档位和打开车灯
- if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartSetGearSt.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// OBC查询电机用户参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
- {
- richTextBox_OBC_ReadUserInfo.Clear();
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
- }
- /// <summary>
- /// OBC设置电机用户参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
- {
- var UserInfoCode = new byte[8];
- for (int i = 0; i < UserInfoCode.Length; i++)
- UserInfoCode[i] = 0;
- if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
- {
- timer_1s.Enabled = false;
- MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- return;
- }
- UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
- UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
- UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
- }
-
- /// <summary>
- /// OBC查询电机版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
- {
- textBox_Model.Text = "---";
- textBox_SN.Text = "---";
- textBox_HW.Text = "---";
- textBox_FW.Text = "---";
- textBox_OBC_ReadModel.Text = "---";
- textBox_OBC_ReadSN.Text = "---";
- textBox_OBC_ReadHW.Text = "---";
- textBox_OBC_ReadFW.Text = "---";
- Class_Motor_Ver.Mode = "---";
- Class_Motor_Ver.SN = "---";
- Class_Motor_Ver.HW = "---";
- Class_Motor_Ver.FW = "---";
- Class_Motor_Ver.Special = "---";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
- }
- /// <summary>
- /// OBC读取骑行历史
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
- {
- textBox_OBC_TRIP_KM.Text = "";
- textBox_OBC_TRIP_TIME.Text = "";
- textBox_OBC_ODO_KM.Text = "";
- textBox_OBC_ODO_TIME.Text = "";
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
- }
- /// <summary>
- /// OBC清除TRIP里程
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- timer_1s.Enabled = false;
- if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
- timer_1s.Enabled = true;
- }
- private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_OBC_StartReadBMS.Checked == true)
- {
- //检查串口是否打开
- if (!mySerialProcess.mySerial.IsOpen)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- timer_1s.Enabled = true;
- checkBox_OBC_StartReadBMS.Checked = false;
- return;
- }
- }
- }
- /// <summary>
- /// 写入力矩传感器参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
- {
- var ConfigParam = new byte[46];
- for (int i = 0; i < 14; i++)
- ConfigParam[i] = 0;
- ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
- ushort uwDataTemp = 0;
- //力矩传感器参数只写入前面14项与力矩传感器相关的参数
- string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
- int index = 0;
- try
- {
- for (int i = 0; i < strDataTemp.Length; i++)
- {
- if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
- {
- index = i;
- break;
- }
- }
- for (int i = 0; i < (index + 1); i++)
- {
- uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
- ConfigParam[2 * i + 2] = (byte)uwDataTemp;
- ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
- }
- mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
- }
- catch (Exception)
- {
- timer_1s.Enabled = false;
- MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- timer_1s.Enabled = true;
- }
- }
- }
- }
|