12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO.Ports;
- namespace MOTINOVA_MC_Test
- {
- public partial class Form1 : Form
- {
- #region------------------------本地变量-----------------------------
- #region 串口相关
- private List<byte> buffer = new List<byte>(4096);
- private byte[] binary_data_1 = new byte[128];
- private bool Listening = false;// 侦听串口是否是接收数据标志位
- public static string m_strDataBits = "8";
- public static string m_strStopBits = "1";
- public static string m_strCheckBits = "None";
- public static bool g_blnIsOpen = false;
- #endregion
- #endregion
- public Form1()
- {
- InitializeComponent();
- }
- #region 打开或关闭串口
- private void button_ComOpen_Click(object sender, EventArgs e)
- {
- try
- {
- if (!serialPort1.IsOpen)
- {
- serialPort1.PortName = comboBox_ComIndex.Text;
- serialPort1.BaudRate = int.Parse(comboBox_Baudrate.Text);
- serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), m_strCheckBits);
- serialPort1.DataBits = Int32.Parse(m_strDataBits);
- serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), (m_strStopBits == "1.5") ? "3" : m_strStopBits);
- serialPort1.Open();
- comboBox_ComIndex.Enabled = false;
- comboBox_Baudrate.Enabled = false;
- button_ComOpen.Text = "断开";
- g_blnIsOpen = true;
- timer1.Enabled = true;
- button_RefreshPort.Enabled = false;
- }
- else
- {
- while (Listening) Application.DoEvents();
- //打开时点击,则关闭串口
- serialPort1.Close();
- comboBox_ComIndex.Enabled = true;
- comboBox_Baudrate.Enabled = true;
- button_ComOpen.Text = "连接";
- g_blnIsOpen = false;
- timer1.Enabled = false;
- button_RefreshPort.Enabled = true;
- }
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- return;
- }
- }
- #endregion
- private void Form1_Load(object sender, EventArgs e)
- {
- string[] ports = SerialPort.GetPortNames();
- Array.Sort(ports);
- comboBox_ComIndex.Items.AddRange(ports);
- comboBox_ComIndex.SelectedIndex = comboBox_ComIndex.Items.Count > 0 ? 0 : -1;
- comboBox_Baudrate.SelectedIndex = comboBox_Baudrate.Items.IndexOf("115200");
-
- }
- #region CRC校验
- static UInt32[] crc32_table = new UInt32[256]
- {
- 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,
- 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
- 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7,
- 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75,
- 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3,
- 0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039,
- 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, 0xBAEA46EF,
- 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D,
- 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB,
- 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1,
- 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0,
- 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072,
- 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4,
- 0x0808D07D, 0x0CC9CDCA, 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE,
- 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08,
- 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,
- 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC,
- 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6,
- 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050,
- 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2,
- 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34,
- 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637,
- 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1,
- 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53,
- 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5,
- 0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF,
- 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E, 0xF5EE4BB9,
- 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B,
- 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD,
- 0xCDA1F604, 0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7,
- 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71,
- 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3,
- 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2,
- 0x470CDD2B, 0x43CDC09C, 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8,
- 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E,
- 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,
- 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A,
- 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0,
- 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676,
- 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4,
- 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662,
- 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668,
- 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
- };
- static UInt32 crc32_cal(byte[] pData, UInt16 Length)
- {
- UInt32 nReg;
- UInt32 nTemp = 0;
- UInt16 i, n;
- nReg = 0xFFFFFFFF;
- for (n = 0; n < Length; n++)
- {
- nReg ^= (UInt32)pData[n];
- for (i = 0; i < 4; i++)
- {
- nTemp = crc32_table[((nReg >> 24) & 0xFF)];
- nReg <<= 8;
- nReg ^= nTemp;
- }
- }
- return nReg;
- }
- #endregion
- #region 发送指令函数
- private void SendCmd(ushort ID, byte Mode, ushort Cmd, byte[] Data)
- {
- if (!serialPort1.IsOpen)
- {
- MessageBox.Show("串口未连接");
- return;
- }
- ushort DataLength = (ushort)(Cmd & 0xFF);
- var SendCmdTmp = new byte[DataLength + 13];
- //帧头
- SendCmdTmp[0] = 0x55;
- SendCmdTmp[1] = 0xAA;
- //ID
- SendCmdTmp[2] = (byte)(ID >> 8);
- SendCmdTmp[3] = (byte)(ID & 0xFF);
- //MODE
- SendCmdTmp[4] = Mode;
- //长度
- SendCmdTmp[5] = (byte)((Cmd & 0xFF) + 2);
- //命令字
- SendCmdTmp[6] = (byte)(Cmd >> 8);
- SendCmdTmp[7] = (byte)(Cmd & 0xFF);
- //数据段
- for (UInt16 i = 0; i < (Cmd & 0xFF); i++)
- {
- SendCmdTmp[8 + i] = Data[i];
- }
- //校验
- UInt32 CRC_Result = crc32_cal(SendCmdTmp, (ushort)(DataLength + 8));
- SendCmdTmp[DataLength + 8] = Convert.ToByte(CRC_Result >> 24);
- SendCmdTmp[DataLength + 9] = Convert.ToByte((CRC_Result >> 16) % 256);
- SendCmdTmp[DataLength + 10] = Convert.ToByte((CRC_Result >> 8) % 256);
- SendCmdTmp[DataLength + 11] = Convert.ToByte(CRC_Result % 256);
- //帧尾
- SendCmdTmp[DataLength + 12] = 0xF0;
- //发送数据
- serialPort1.Write(SendCmdTmp, 0, SendCmdTmp.Length);
- }
- #endregion
- //串口数据接收
- private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
- {
- try
- {
- Listening = true;
- int n = serialPort1.BytesToRead;
- byte[] buf = new byte[n];//将一次串口事件中接收到的数据暂存于buf中(注:对于超过8个字节的数据,C#的
- //串口接收事件将按每次处理8个字节的方式多次处理
- serialPort1.Read(buf, 0, n);//将接收到的数据读入buf
- this.Invoke((EventHandler)delegate
- {
- });
- buffer.AddRange(buf);//将读取的数据放入buffer中
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- return;
- }
- finally
- {
- Listening = false;
- }
- }
- //接收计数清零
- private void label58_Click(object sender, EventArgs e)
- {
- textBox_RevCnt.Text = "0";
- }
- //端口刷新
- private void button_RefreshPort_Click(object sender, EventArgs e)
- {
- string[] ports = SerialPort.GetPortNames();
- Array.Sort(ports);
- comboBox_ComIndex.Items.Clear();
- comboBox_ComIndex.Items.AddRange(ports);
- comboBox_ComIndex.SelectedIndex = comboBox_ComIndex.Items.Count > 0 ? 0 : -1;
- }
- //time1定时任务
- private void timer1_Tick(object sender, EventArgs e)
- {
-
- //...
-
- //串口解析
- byte DataNum = 0; //记录每条命令数据段的长度
- while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
- {
- if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
- {
- int CmdLen = buffer[5];
- if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
- buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
- while (CmdLen > 0) //读取命令段
- {
- DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
- if (DataNum <= (CmdLen - 2))
- {
- for (int i = 0; i < DataNum + 2; i++)
- {
- binary_data_1[i] = buffer[i];
- }
- DataCmdProcess();//对于不同的命令段,做不同的处理
- buffer.RemoveRange(0, DataNum + 2);//移除处理过的命令段与数据段
- CmdLen -= (DataNum + 2);
- if (CmdLen < 2)
- {
- buffer.RemoveRange(0, CmdLen + 2);
- return;
- }
- }
- else
- {
- buffer.RemoveRange(0, CmdLen + 11);
- }
- }
- }
- else
- {
- buffer.RemoveAt(0);//帧头不对,删除帧头高字节
- }
- }
- }
- #region 字符串转换为字节流
- public static byte[] HexStringToBytes(string hexStr, bool Flag_Space)
- {
- if (string.IsNullOrEmpty(hexStr))
- {
- return new byte[0];
- }
- if (hexStr.StartsWith("0x"))
- {
- hexStr = hexStr.Remove(0, 2);
- }
- var count = hexStr.Length;
- var byteCount = 0;
- if (Flag_Space == true)//相邻字节含空格
- {
- if ((count % 3) == 0)//最后字节含空格
- {
- byteCount = count / 3;
- }
- else if ((count % 3) == 2)//最后字节不含空格
- {
- byteCount = (count + 1) / 3;
- }
- else//数据无效
- {
- MessageBox.Show("相邻字节请插入空格!", "提示");
- }
- var result = new byte[byteCount];
- for (int ii = 0; ii < byteCount; ++ii)
- {
- var tempBytes = Byte.Parse(hexStr.Substring(3 * ii, 2), System.Globalization.NumberStyles.HexNumber);
- result[ii] = tempBytes;
- }
- return result;
- }
- else if (Flag_Space == false)//相邻字节不含空格
- {
- if (count % 2 == 1)
- {
- MessageBox.Show("请删除相邻字节之间空格!", "提示");
- }
- byteCount = count / 2;
- var result = new byte[byteCount];
- for (int ii = 0; ii < byteCount; ++ii)
- {
- var tempBytes = Byte.Parse(hexStr.Substring(2 * ii, 2), System.Globalization.NumberStyles.HexNumber);
- result[ii] = tempBytes;
- }
- return result;
- }
- else
- {
- return new byte[0];
- }
- }
- #endregion
- #region 命令段处理函数
- private void DataCmdProcess()
- {
- ushort CmdTemp = (ushort)(binary_data_1[0] * 256 + binary_data_1[1]);
- ushort DataTemp;
- short Data_Temp_Int;
- sbyte Data_Int8;
- UInt32 DataTemp32;
- textBox_RevCnt.Text = Convert.ToString(Convert.ToInt16(textBox_RevCnt.Text) + 1);
- richTextBox_Rev.Text = "";
- richTextBox_Data.Text = "";
- //显示接收的数据
- richTextBox_Rev.Text += "CMD: " + Convert.ToString(binary_data_1[0], 16).PadLeft(2, '0').ToUpper() + " " + Convert.ToString(binary_data_1[1], 16).PadLeft(2, '0').ToUpper() + "\r\n";
- richTextBox_Rev.Text += "DATA: ";
- for (int i = 0; i < binary_data_1[1]; i++)
- {
- richTextBox_Rev.Text += Convert.ToString(binary_data_1[2 + i], 16).PadLeft(2, '0').ToUpper() + " ";
- }
- //数据解析
- switch (CmdTemp)
- {
- case 0x1010://BMS运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- DataTemp = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);//电压
- richTextBox_Data.Text = "母线电压: " + DataTemp.ToString() + " mV\r\n";
- Data_Temp_Int = (short)(binary_data_1[5] * 256 + binary_data_1[4]);//电流
- richTextBox_Data.Text += "母线电流: " + Data_Temp_Int.ToString() + " mA\r\n";
- DataTemp = (ushort)(binary_data_1[7] * 256 + binary_data_1[6]);//剩余容量
- richTextBox_Data.Text += "剩余容量: " + DataTemp.ToString() + " mAh\r\n";
- DataTemp = (ushort)(binary_data_1[9] * 256 + binary_data_1[8]);//满充容量
- richTextBox_Data.Text += "满充容量: " + DataTemp.ToString() + " mAh\r\n";
- Data_Temp_Int = (short)binary_data_1[10];//电芯温度
- richTextBox_Data.Text += "电芯温度: " + (Data_Temp_Int - 40).ToString() + " Degree C\r\n";
- DataTemp = (ushort)binary_data_1[11];//剩余电量
- richTextBox_Data.Text += "剩余电量: " + DataTemp.ToString() + " %\r\n";
- DataTemp = (ushort)binary_data_1[12];//运行状态
- richTextBox_Data.Text += "运行状态: " + "0x" + Convert.ToString(DataTemp, 16).PadLeft(2, '0').ToUpper() + "\r\n";
- DataTemp = (ushort)binary_data_1[13];//SOH
- richTextBox_Data.Text += "剩余寿命: " + DataTemp.ToString() + " %\r\n";
- }));
- }
- break;
- }
- case 0x1120://BMS电芯电压
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- for (int i = 0; i < 16; i++)
- {
- DataTemp = (ushort)(binary_data_1[3 + i * 2] * 256 + binary_data_1[2 + i * 2]);//电压
- if (DataTemp == 0)
- break;
- richTextBox_Data.Text += "电芯" + (i + 1).ToString() + ": " + DataTemp.ToString() + " mV\r\n";
- }
- }));
- }
- break;
- }
- case 0x1204://故障码
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
-
- }));
- }
- break;
- }
- case 0x1308://关机指令
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "接收数据:";
- for (int i = 0; i < 8; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[2 + i])).ToString();
- }));
- }
- break;
- }
- case 0x1410://BMS设计信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- DataTemp = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);
- richTextBox_Data.Text = "设计容量: " + DataTemp.ToString() + " mAh\r\n";
- DataTemp = (ushort)binary_data_1[4];
- richTextBox_Data.Text += "设计电压: " + DataTemp.ToString() + " V\r\n";
- richTextBox_Data.Text += "电芯型号: ";
- for (ushort i = 0; i < 8; i++)
- {
- richTextBox_Data.Text += ((char)binary_data_1[5 + i]).ToString();
- }
- richTextBox_Data.Text += "\r\n";
- }));
- }
- break;
- }
- case 0x1540://BMS版本信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //型号
- richTextBox_Data.Text += "型号: ";
- for (ushort i = 0; i < 16; i++)
- {
- richTextBox_Data.Text += ((char)binary_data_1[2 + i]).ToString();
- }
- richTextBox_Data.Text += "\r\n";
- //SN
- richTextBox_Data.Text += "序列号: ";
- for (ushort i = 0; i < 16; i++)
- {
- richTextBox_Data.Text += ((char)binary_data_1[18 + i]).ToString();
- }
- richTextBox_Data.Text += "\r\n";
- //HW
- richTextBox_Data.Text += "硬件版本: ";
- for (ushort i = 0; i < 16; i++)
- {
- richTextBox_Data.Text += ((char)binary_data_1[34 + i]).ToString();
- }
- richTextBox_Data.Text += "\r\n";
- //FW
- richTextBox_Data.Text += "软件版本: ";
- for (ushort i = 0; i < 16; i++)
- {
- richTextBox_Data.Text += ((char)binary_data_1[50 + i]).ToString();
- }
- richTextBox_Data.Text += "\r\n";
- }));
- }
- break;
- }
- case 0x160C://BMS物理ID
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "物理ID: ";
- richTextBox_Data.Text += "0x";
- for (ushort i = 0; i < 12; i++)
- {
- richTextBox_Data.Text += Convert.ToString(binary_data_1[2 + i], 16).PadLeft(2, '0').ToUpper();
- }
- richTextBox_Data.Text += "\r\n";
- }));
- }
- break;
- }
- case 0x170C://BMS校验码
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "校验码: ";
- richTextBox_Data.Text += "0x";
- for (ushort i = 0; i < 12; i++)
- {
- richTextBox_Data.Text += Convert.ToString(binary_data_1[2 + i], 16).PadLeft(2, '0').ToUpper();
- }
- richTextBox_Data.Text += "\r\n";
- }));
- }
- break;
- }
- case 0x3005://MC在线反馈
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "接收数据:";
- for (int i = 0; i < 5; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[2 + i])).ToString();
- }));
- }
- break;
- }
- case 0x5028://电池历史信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- Data_Int8 = (sbyte)(binary_data_1[2]);//电芯最高温
- richTextBox_Data.Text += "电芯最高温: " + (Data_Int8 - 40).ToString() + " ℃\r\n";
- Data_Int8 = (sbyte)(binary_data_1[3]);//电芯最低温
- richTextBox_Data.Text += "电芯最低温: " + (Data_Int8 - 40).ToString() + " ℃\r\n";
- DataTemp = (ushort)(binary_data_1[5] * 256 + binary_data_1[4]);//最大放电电流
- richTextBox_Data.Text += "最大放电电流: " + DataTemp.ToString() + " mA\r\n";
- DataTemp = (ushort)(binary_data_1[7] * 256 + binary_data_1[6]);//最大放电电流
- richTextBox_Data.Text += "最大充电电流: " + DataTemp.ToString() + " mA\r\n";
- DataTemp = (ushort)(binary_data_1[9] * 256 + binary_data_1[8]);//最大放电电流
- richTextBox_Data.Text += "循环次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[11] * 256 + binary_data_1[10]);//最近充电间隔
- richTextBox_Data.Text += "最近充电间隔时间: " + DataTemp.ToString() + " h\r\n";
- DataTemp = (ushort)(binary_data_1[13] * 256 + binary_data_1[12]);//最大充电间隔
- richTextBox_Data.Text += "最大充电间隔时间: " + DataTemp.ToString() + " h\r\n";
- DataTemp = (ushort)(binary_data_1[15] * 256 + binary_data_1[14]);//充电过流保护次数
- richTextBox_Data.Text += "充电过流保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[17] * 256 + binary_data_1[16]);//放电过流保护次数
- richTextBox_Data.Text += "放电过流保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[19] * 256 + binary_data_1[18]);//过充保护次数
- richTextBox_Data.Text += "过充保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[21] * 256 + binary_data_1[20]);//过放保护次数
- richTextBox_Data.Text += "过放保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[23] * 256 + binary_data_1[22]);//短路保护次数
- richTextBox_Data.Text += "短路保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[25] * 256 + binary_data_1[24]);//充电低温保护次数
- richTextBox_Data.Text += "充电低温保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[27] * 256 + binary_data_1[26]);//充电高温保护次数
- richTextBox_Data.Text += "充电高温保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[29] * 256 + binary_data_1[28]);//放电低温保护次数
- richTextBox_Data.Text += "放电低温保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp = (ushort)(binary_data_1[31] * 256 + binary_data_1[30]);//放电高温保护次数
- richTextBox_Data.Text += "放电高温保护次数: " + DataTemp.ToString() + " 次\r\n";
- DataTemp32 = (UInt32)((binary_data_1[35] << 24) + (binary_data_1[34]) << 16 + binary_data_1[33] * 256 + binary_data_1[32]);//运行时间
- richTextBox_Data.Text += "运行时间: " + DataTemp32.ToString() + " min\r\n";
- DataTemp = (ushort)(binary_data_1[36]);//SOH
- richTextBox_Data.Text += "剩余寿命: " + DataTemp.ToString() + " %\r\n";
- }));
- }
- break;
- }
- case 0x5120://电池生产信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "生产商:";
- for (int i = 0; i < 8; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[2 + i])).ToString();
- richTextBox_Data.Text += "\r\n";
- richTextBox_Data.Text += "生产地:";
- for (int i = 0; i < 8; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[10 + i])).ToString();
- richTextBox_Data.Text += "\r\n";
- richTextBox_Data.Text += "生产日期:";
- for (int i = 0; i < 8; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[18 + i])).ToString();
- }));
- }
- break;
- }
- case 0x5210://自定义1
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "接收数据:";
- for (int i = 0; i < 16; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[2 + i])).ToString();
- }));
- }
- break;
- }
- case 0x5310://自定义2
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "接收数据:";
- for (int i = 0; i < 16; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[2 + i])).ToString();
- }));
- }
- break;
- }
- case 0x5410://自定义3
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "接收数据:";
- for (int i = 0; i < 16; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[2 + i])).ToString();
- }));
- }
- break;
- }
- case 0x5503://反馈
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Data.Text += "接收数据:";
- for (int i = 0; i < 3; i++)
- richTextBox_Data.Text += ((char)(binary_data_1[2 + i])).ToString();
- }));
- }
- break;
- }
- case 0x5688://日志
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region 模拟指令发送
- #region MC模拟指令
- /// <summary>
- /// MC关机就绪
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_MC_Ready_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'A';
- Code[3] = (byte)'D';
- Code[4] = (byte)'Y';
- SendCmd((ushort)0x710, (byte)0x0C, (ushort)0x1305, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// MC在线检测
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_MC_Check_Click(object sender, EventArgs e)
- {
- var Code = new byte[9];
- Code[0] = (byte)'H';
- Code[1] = (byte)'A';
- Code[2] = (byte)'N';
- Code[3] = (byte)'D';
- Code[4] = (byte)'S';
- Code[5] = (byte)'H';
- Code[6] = (byte)'K';
- Code[7] = (byte)'A';
- Code[8] = (byte)'E';
- SendCmd((ushort)0x712, (byte)0x11, (ushort)0x3009, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// 查询物理ID
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_MC_ReadID_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x712, (byte)0x11, (ushort)0x3100, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// 查询校验码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_MC_ReadCheckNum_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x712, (byte)0x11, (ushort)0x3200, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// 查询设计信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_MC_ReadDesignInfo_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x712, (byte)0x11, (ushort)0x3300, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- #endregion
- #region PBU/OBC模拟指令
- /// <summary>
- /// OBC关机就绪
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_Ready_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'A';
- Code[3] = (byte)'D';
- Code[4] = (byte)'Y';
- SendCmd((ushort)0x730, (byte)0x0C, (ushort)0x1405, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// OBC查询BMS运行信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadRunInfo_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// OBC查询BMS版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadVer_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5100, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// OBC查询BMS设计信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadDesign_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5200, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// OBC读取BMS电芯电压
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_OBC_ReadCell_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5300, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- #endregion
- #region HMI模拟指令
- /// <summary>
- /// HMI关机就绪
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_HMI_Ready_Click(object sender, EventArgs e)
- {
- var Code = new byte[5];
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'A';
- Code[3] = (byte)'D';
- Code[4] = (byte)'Y';
- SendCmd((ushort)0x740, (byte)0x0C, (ushort)0x1305, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// HMI读取版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_HMI_ReadVerInfo_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x742, (byte)0x11, (ushort)0x5000, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// HMI读取设计信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_HMI_ReadDesignInfo_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x742, (byte)0x11, (ushort)0x5100, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// HMI读取电芯电压
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_HMI_ReadCell_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x742, (byte)0x11, (ushort)0x5200, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- #endregion
- #region 模拟CDL发送指令
- /// <summary>
- /// CDL查询物理ID
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadID_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3000, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL查询校验码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadCheckNum_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3100, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL写入校验码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_WriteCheckNum_Click(object sender, EventArgs e)
- {
- var Code = new byte[12];
- if (HexStringToBytes(textBox_SendData.Text, true).Length !=12)
- {
- MessageBox.Show("Invalid length of bytes!", "Notice", MessageBoxButtons.OK);
- return;
- }
- Code = HexStringToBytes(textBox_SendData.Text, true);
- SendCmd((ushort)0x752, (byte)0x16, (ushort)0x320C, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL读取版本信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadVer_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3300, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL读取运行信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadRunInfo_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3400, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL读取电芯电压
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadCell_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3500, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL读取设计信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadDesign_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3600, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL读取生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadFac_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3700, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL读取历史信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadHistory_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3800, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL读取自定义信息1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadUser1_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3900, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL写入自定义信息1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_Write_User1_Click(object sender, EventArgs e)
- {
- var Code = new byte[16];
- if (textBox_SendData.Text.Length > 16)
- {
- MessageBox.Show("Length should be less 16 bytes!", "Notice", MessageBoxButtons.OK);
- return;
- }
- for (ushort i = 0; i < textBox_SendData.Text.Length; i++)
- {
- Code[i] = (byte)textBox_SendData.Text[i];
- }
- if (textBox_SendData.Text.Length < 16)
- {
- Code[textBox_SendData.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - textBox_SendData.Text.Length - 1; i++)
- {
- Code[textBox_SendData.Text.Length + 1 + i] = 0x20;
- }
- }
- SendCmd((ushort)0x752, (byte)0x16, (ushort)0x3A10, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL读取自定义信息2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadUser2_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3B00, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL写入自定义信息2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_Write_User2_Click(object sender, EventArgs e)
- {
- var Code = new byte[16];
- if (textBox_SendData.Text.Length > 16)
- {
- MessageBox.Show("Length should be less 16 bytes!", "Notice", MessageBoxButtons.OK);
- return;
- }
- for (ushort i = 0; i < textBox_SendData.Text.Length; i++)
- {
- Code[i] = (byte)textBox_SendData.Text[i];
- }
- if (textBox_SendData.Text.Length < 16)
- {
- Code[textBox_SendData.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - textBox_SendData.Text.Length - 1; i++)
- {
- Code[textBox_SendData.Text.Length + 1 + i] = 0x20;
- }
- }
- SendCmd((ushort)0x752, (byte)0x16, (ushort)0x3C10, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL查询自定义信息3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadUser3_Click(object sender, EventArgs e)
- {
- SendCmd((ushort)0x752, (byte)0x11, (ushort)0x3D00, null);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL写入自定义信息3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_Write_User3_Click(object sender, EventArgs e)
- {
- var Code = new byte[16];
- if (textBox_SendData.Text.Length > 16)
- {
- MessageBox.Show("Length should be less 16 bytes!", "Notice", MessageBoxButtons.OK);
- return;
- }
- for (ushort i = 0; i < textBox_SendData.Text.Length; i++)
- {
- Code[i] = (byte)textBox_SendData.Text[i];
- }
- if (textBox_SendData.Text.Length < 16)
- {
- Code[textBox_SendData.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - textBox_SendData.Text.Length - 1; i++)
- {
- Code[textBox_SendData.Text.Length + 1 + i] = 0x20;
- }
- }
- SendCmd((ushort)0x752, (byte)0x16, (ushort)0x3E10, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL写入生产信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_WriteFac_Click(object sender, EventArgs e)
- {
- var Code = new byte[32];
- if (textBox_SendData.Text.Length == 0)
- {
- MessageBox.Show("Invalid length of bytes!", "Notice", MessageBoxButtons.OK);
- return;
- }
- //填入生产商
- for (ushort i = 0; i < 8; i++)
- {
- Code[i] = (byte)textBox_SendData.Text[i];
- }
- if (textBox_SendData.Text.Length < 8)
- {
- Code[textBox_SendData.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_SendData.Text.Length - 1; i++)
- {
- Code[textBox_SendData.Text.Length + 1 + i] = 0x20;
- }
- }
- //填入生产地
- for (ushort i = 0; i < 8; i++)
- {
- Code[8 + i] = (byte)textBox_SendData.Text[i];
- }
- if (textBox_SendData.Text.Length < 8)
- {
- Code[textBox_SendData.Text.Length + 8] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_SendData.Text.Length - 1; i++)
- {
- Code[textBox_SendData.Text.Length + 1 + i + 8] = 0x20;
- }
- }
- //填入生产日期
- for (ushort i = 0; i < 8; i++)
- {
- Code[16 + i] = (byte)textBox_SendData.Text[i];
- }
- if (textBox_SendData.Text.Length < 8)
- {
- Code[textBox_SendData.Text.Length + 16] = (byte)'.';
- for (ushort i = 0; i < 8 - textBox_SendData.Text.Length - 1; i++)
- {
- Code[textBox_SendData.Text.Length + 1 + i + 16] = 0x20;
- }
- }
- SendCmd((ushort)0x752, (byte)0x16, (ushort)0x3F20, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL写入型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_WriteModel_Click(object sender, EventArgs e)
- {
- var Code = new byte[16];
- if (textBox_SendData.Text.Length > 16)
- {
- MessageBox.Show("Length should be less 16 bytes!", "Notice", MessageBoxButtons.OK);
- return;
- }
- for (ushort i = 0; i < textBox_SendData.Text.Length; i++)
- {
- Code[i] = (byte)textBox_SendData.Text[i];
- }
- if (textBox_SendData.Text.Length < 16)
- {
- Code[textBox_SendData.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - textBox_SendData.Text.Length - 1; i++)
- {
- Code[textBox_SendData.Text.Length + 1 + i] = 0x20;
- }
- }
- SendCmd((ushort)0x752, (byte)0x16, (ushort)0x4010, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL写入SN
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_WriteSN_Click(object sender, EventArgs e)
- {
- var Code = new byte[16];
- if (textBox_SendData.Text.Length > 16)
- {
- MessageBox.Show("Length should be less 16 bytes!", "Notice", MessageBoxButtons.OK);
- return;
- }
- for (ushort i = 0; i < textBox_SendData.Text.Length; i++)
- {
- Code[i] = (byte)textBox_SendData.Text[i];
- }
- if (textBox_SendData.Text.Length < 16)
- {
- Code[textBox_SendData.Text.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - textBox_SendData.Text.Length - 1; i++)
- {
- Code[textBox_SendData.Text.Length + 1 + i] = 0x20;
- }
- }
- SendCmd((ushort)0x752, (byte)0x16, (ushort)0x4110, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// CDL发送复位
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_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';
- SendCmd((ushort)0x752, (byte)0x16, (ushort)0x4205, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- /// <summary>
- /// 读取日志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_CDL_ReadLog_Click(object sender, EventArgs e)
- {
- var Code = new byte[8];
- string AddBegin, AddEnd;
- var CodeTemp = new byte[4];
- if (textBox_SendData.Text.Length != 17)
- {
- MessageBox.Show("Length should be 17 bytes!", "Notice", MessageBoxButtons.OK);
- return;
- }
- AddBegin = textBox_SendData.Text.Split(' ')[0];
- AddEnd = textBox_SendData.Text.Split(' ')[1];
- CodeTemp = HexStringToBytes(AddBegin, false);
- for (int i = 0; i < 4; i++)
- Code[i] = CodeTemp[3 - i];
- CodeTemp = HexStringToBytes(AddEnd, false);
- for (int i = 0; i < 4; i++)
- Code[4 + i] = CodeTemp[3 - i];
- SendCmd((ushort)0x712, (byte)0x11, (ushort)0x4308, Code);
- richTextBox_Data.Text = "";
- richTextBox_Rev.Text = "";
- }
- }
- #endregion
- #endregion
- }
|